|
-
Oct 6th, 2004, 12:07 PM
#1
Thread Starter
Frenzied Member
divs laid out like a table!?
I have a table currently that I use to display somewhat of a menu. I was wondering how you get divs to display in the same format. And this is more of a question of how to do it for this one page. I want to know this in general.
So how do I get, for example,
Code:
<div align="center">
<div align="center"><?php include("specRep3.php"); ?></div>
<div align="center"><?php include("specRep4.php"); ?></div>
<div align="center"><?php include("specRep5.php"); ?></div>
</div>
to appear in a row as if I was using a table row, with what I would call "cellpadding"?
-
Oct 6th, 2004, 01:09 PM
#2
Thread Starter
Frenzied Member
Ok, I've made some progress. I'm using this:
Code:
<div class="specmenu" onclick="gotosect(1);">Header Info</div>
<div class="specmenu" onclick="gotosect(2);">Restrictions/Fuel Temp Setpoints</div>
<div class="specmenu" onclick="gotosect(3);">Heat Rejection Coefficients</div>
with the following CSS:
Code:
.specmenu {
color: Navy;
background-color: #E7E7E7;
border: 8px solid white;
font-weight: bold;
cursor: pointer;
width: 32%;
float: left;
vertical-align: middle;
height: 50px;
}
I have 2 problems.
1) In Firefox (1.0PR) and Netscape (7.1), it only puts 2 per line. In Opera 7.54 and IE 6, it puts 3 per line.
2) It won't vertically align the text in the div in any of the browsers.
Help?
-
Oct 6th, 2004, 02:01 PM
#3
Thread Starter
Frenzied Member
I've changed the CSS to this, and now it is centered and spaced ok in Opera and IE, but FF and Netscape make the divs twice as tall and it is still bumping the 3rd div down to the next line.
I'm gettin desperate here people... 
Code:
.specmenu {
color: Navy;
background-color: #E7E7E7;
border: 8px solid white;
font-weight: bold;
cursor: pointer;
width: 33%;
text-align: center;
float: left;
vertical-align: middle;
height: 46px;
padding-top: 8px;
padding-bottom: 8px;
}
-
Oct 7th, 2004, 06:32 AM
#4
Frenzied Member
Mozilla adds padding and borders to the width of a div.
In other words if you set the width of a div to 100px and then add 10px padding, the true width is 120px (100 + 10(left padding) + 10(right padding). Hence your 3 divs width totals over 100% and therefore wraps over the page.
The same applies for height.
I tend to use a different style sheet for IE cos it doesn't match web standards well.
HTH
DJ
-
Oct 7th, 2004, 07:29 AM
#5
Thread Starter
Frenzied Member
What the hell? Why would they do that?
-
Oct 7th, 2004, 07:46 AM
#6
Frenzied Member
Because that's how it's specified in the specs, padding is applied inside the box, margins are applied outside of it. The width you specify is the space you have for the content, not how much space it takes up on screen.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 7th, 2004, 08:04 AM
#7
Fanatic Member
Take a look at the specs:
w3c box model
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Oct 7th, 2004, 08:17 AM
#8
Thread Starter
Frenzied Member
Ok... well if I understand you correctly, I have to specify everything about the box for it to work correctly? Or am I missing something. I understand the padding and margins and all that and I understand where they are, but I don't get what I'm doing wrong and why Netscape and Firefox are making my divs twice as tall and why they are wrapping.
Is it because I'm not specifying the padding on the left and right? Is it because I'm not specifying the margins? Throw me a bone here.
-
Oct 7th, 2004, 08:37 AM
#9
Frenzied Member
Simple as this IE and Mozilla interpret the same CSS code in different ways. IE is reckonised to be crap in this respect.
IE:
Padding is included within the width.
Mozilla:
Padding is not included in the width, the width is the width for the content only!
As you have 3 divs that should fit to 100% of the page with when you add padding in Mozilla it pushes the total width over 100% and therefore it wraps.
Make sense?
DJ
-
Oct 7th, 2004, 08:39 AM
#10
Thread Starter
Frenzied Member
Yeah... I'm reading the link McCain gave and I'm trying out the Tan Hack... hopefully this will solve my problems.
Thanks for the help. I knew IE was screwed up... but I didn't know Opera was off on this one too.
-
Oct 7th, 2004, 08:47 AM
#11
Thread Starter
Frenzied Member
AHHHHHH... this sucks. I can't even do that. I have other divs on the page and using the Tan Hack will screw up those divs. I guess I could use another block element, but what a freakin pain in the arse. I might as well go back to tables for this page .
-
Oct 7th, 2004, 08:50 AM
#12
Frenzied Member
Are you writing a static HTML page or a dynamic ASP, PHP page?
DJ
-
Oct 7th, 2004, 08:58 AM
#13
Thread Starter
Frenzied Member
It's static.... I'm just setting up a menu of sorts.
4 rows, first two with 3 elements, last two with only 2 elements.
It feeds a bunch of other dynamic PHP pages, and this is just an include page that I drop in as a menu.
-
Oct 7th, 2004, 09:03 AM
#14
Thread Starter
Frenzied Member
This is how I want it to look. That is in Opera. This would be all fine and dandy if I could specify a width for the div in absolute values, but I want to use percentages. I want it to scale. Is that too much to ask!?
Last edited by ober0330; Oct 7th, 2004 at 09:07 AM.
-
Oct 7th, 2004, 09:16 AM
#15
Frenzied Member
If it to be used with PHP pages you could add a browser "sniffer" that uses a different style sheet according to the browser. That way it would work for everything and there would need to be very few differences between the 2 style sheets.
DJ
-
Oct 7th, 2004, 09:19 AM
#16
Thread Starter
Frenzied Member
Yeah, but that would mean that I'd have to keep 2 CSS files up to date. No thanks. My CSS file is quite complex as I use it for about 8 database interfaces (all with the same look and feel, but all with different needs).
-
Oct 7th, 2004, 09:53 AM
#17
Frenzied Member
Like I said the only differences would be the widths so you could have a general CSS and then layout_ie.css and layout_moz.css that only contain the div styles. Once setup you wouldn't have to tinker unless the divs changed. I do it all the time and it ain't difficult to keep up with.
DJ
-
Oct 7th, 2004, 09:57 AM
#18
Frenzied Member
I suggest not using the tantek hack, use conditional statements to specify special widths for IE 5 (IE 6 renders boxes correct, as long as it's not in quirksmode - so a correct doctype as the first line of the document):
Code:
<!--[if ie 5]>
<link rel="stylesheet" type="text/css" href="css/ie5.css">
<![endif]-->
The only thing you specify in that css is the new width for IE5.
so if you have in your general css:
Code:
.box{
width: 100px;
padding: 10px;
/* so many more lines */
}
You specify
Code:
.box{width: 120px;}
in your ie5.css
And that for each box that uses a width and padding.
That's it, the boxmodel works well in IE 5.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 7th, 2004, 10:02 AM
#19
This was hammered up in ten mins - is by no means finished... but may give you an idea?
I'l look again tomorrow 
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Oct 7th, 2004, 10:38 AM
#20
Thread Starter
Frenzied Member
Ok, let me throw another monkey at the wrench. The website is in a controlled environment. It is on our intranet. Everyone is using either Netscape 7.1+ or IE 6+.
Is there something I need to specify in the heading of the document to make the model work correctly without a hack in those 2 browsers?
I'm currently using this header:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
Oct 7th, 2004, 10:45 AM
#21
Frenzied Member
No because that is a document type declaration which states you are using HTML 4.0 Transitional for the webpage which isn't related to CSS at all.
DJ
-
Oct 7th, 2004, 10:48 AM
#22
Actually, dj4uk, it is, because browsers use the doctype to decide whether they should be in Standards-compliant or Quirks mode - and that VERY MUCH influences CSS.
Try changing the DOCTYPE to a HTML 4.01 Strict and see if that solves your problem. Of course, you may only do this if you actually conform to that doctype.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 7th, 2004, 10:51 AM
#23
Frenzied Member
I stand corrected CornedBee - you learn a new thing every day!
-
Oct 7th, 2004, 10:53 AM
#24
Thread Starter
Frenzied Member
Originally posted by CornedBee
Try changing the DOCTYPE to a HTML 4.01 Strict and see if that solves your problem. Of course, you may only do this if you actually conform to that doctype.
Ok... and by "conforming to that doctype", you mean? Making the document complient with the strict standards?
-
Oct 7th, 2004, 11:00 AM
#25
Frenzied Member
Yes, follow the rules as specified by the w3c specs, and validate your documents to see if it compies.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|