Cross Browser Compatibiliy - Aligns in IE but not FF

Discussion in 'CSS' started by jams44, Dec 12, 2007.

  1. #1
    Can anyone help me out as to why this layout (http://radiantstatic.com/champs) is perfectly aligned and text is correctly positioned while as in FF it isn't. Its all valid as I have run it through both CSS and XHTML validators. Any help would be great, I've been stuck on this issue for ages!
     
    jams44, Dec 12, 2007 IP
  2. Katy

    Katy Moderator Staff

    Messages:
    3,490
    Likes Received:
    513
    Best Answers:
    7
    Trophy Points:
    355
    #2
    Simply change:

    .navi{
    margin-top: 173px;
    }

    to

    .navi{
    padding-top: 173px;
    }

    and

    .footer-text{
    margin-top: 11px;

    }

    to

    .footer-text{
    padding-top: 11px;

    }

    Always use padding, never margin, if you want to move a text (no images).
     
    Katy, Dec 12, 2007 IP
  3. jams44

    jams44 Peon

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    great everything text related is fixed now. any reason there is a gap between the header div and the content div as well as the content div with the footer div?
     
    jams44, Dec 12, 2007 IP
  4. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Default margins and padding, which vary from browser to browser. What I do is reset the margins and padding on every non-form control element by placing the following at the top of my stylesheet.

    
    html, body, address, blockquote, div, dl, form, h1, h2, h3, h4, h5, h6, ol, p, pre, table, ul,
    dd, dt, li, tbody, td, tfoot, th, thead, tr, button, del, ins, map, object,
    a, abbr, acronym, b, bdo, big, br, cite, code, dfn, em, i, img, kbd, q, samp, small, span,
    strong, sub, sup, tt, var {
    	margin: 0;
    	padding: 0;
    }
    
    Code (markup):
    Then I set the default styles for the body (which then cascade to the rest of the page elements).

    
    body {
    	background: #FFF; /* change to suit your site of course */
    	color: #000; /* change to suit your site of course */
    	font: normal 85%/140% "lucida console", tahoma, verdana, arial, helvetica, sans-serif;
    	letter-spacing: 1px;
    }
    
    Code (markup):
    Note that I use EM for the widths of my containers and font sizes from here on out, using the Lucida Console font to ensrue that just about any font the user has on his or her system will fit inside their containers without breaking the layout. If I'm dealing with a fixed dimension (like text on images) I'll either go for pixels for the text on the image or use some advanced CSS trickery to make the image appear to be dynamic so the text can resize along with it (using EM for the font size of course). When I'm done with the site, I remove the Lucida Console font from my declaration but leave the container and font size values alone.

    Headings of course are another matter entirely, and thus they normally get styled (by me anyway) like so:

    
    h1, h2, h3, h4, h5, h6 {
    	font-family: georgia, garamond, "times new roman", times, serif;
    	font-weight: bold;
    }
    
    h1 {
    	font-size: 1.75em;
    	line-height: 1.8em;
    }
    
    h2 {
    	font-size: 1.5em;
    	line-height: 1.55em;
    }
    
    h3 {
    	font-size: 1.05em;
    	line-height: 1.1em;
    }
    
    h4 {
    	font-size: 0.95em;
    	line-height: 1em;
    }
    
    h5 {
    	font-size: 0.85em;
    	line-height: 0.9em;
    }
    
    h6 {
    	font-size: 0.75em;
    	line-height: 0.8em;
    }
    
    Code (markup):
    And then followed up with some browser-specific patches before I start working on the actual layout:

    
    img {
    	border: 0;																/* this squashes a Firefox bug */
    	display: block;
    }
    
    table {																		/* I'd like to have all the browsers on the same page with regard to tables - this does it */
    	border-collapse: collapse;
    	empty-cells: show;
    	table-layout: fixed;
    }
    
    .skip {
    	position: absolute;
    	left: -999em;
    }
    
    Code (markup):
    Notice the class of "skip" - this is used to hide "skip links" from the browser. You can use some different CSS to hide the element from the browser by default and then make it appear when hovered over or given an active state. Molly Holzschlag's blog www.molly.com has an article on how to do this, IIRC.

    Oh, and if yo don't mind me being a nit-pick, this looks like a list of links to me:

    
    <div id="navi">Link :: Link :: Link :: Link :: Link :: Link :: Link :: Link</div>
    
    Code (markup):
    So I'd use an unordered list with an ID of "menu" instead (oh, and structurally speaking, menus should never appear in headers, since they can be over-laid with CSS using margins, and you never know when the design may have to change or what it will look like so having the major sections of a Web page - header, menu(s), content, sidebar(s), footer - separated from one another will help immensely; note that footer menus can be placed inside the footer, especially given that styling their locations and appearance will be much easier this way due to the limits of the current CSS specification and cross-browser support).

    
    <ul id="menu">
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    </ul>
    
    Code (markup):
     
    Dan Schulz, Dec 14, 2007 IP
  5. buckmajor

    buckmajor Active Member

    Messages:
    574
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Hey Im having the same problem with the different browsers too.(http://css-example.digitalprodusa.net) is perfectly aligned and text is correctly positioned while as in FF, NS and Opera, it isn't.

    Any help would be great and many thanks in advance

    CHEERS :)
     
    buckmajor, Dec 15, 2007 IP
  6. yangyang

    yangyang Banned

    Messages:
    757
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #6

    Very informative and helpful, Dan. But never used this before:

    table {																		/* I'd like to have all the browsers on the same page with regard to tables - this does it */
    	border-collapse: collapse;
    	empty-cells: show;
    	table-layout: fixed;
    }
    Code (markup):
    will try it next time dealing with table data. And one question, though, is there any difference among them:

    * {margin:0;padding:0;}
    Code (markup):
    html * {margin:0;padding:0;}
    Code (markup):
    html, body, address, blockquote, div, dl, form, h1, h2, h3, h4, h5, h6, ol, p, pre, table, ul,
    dd, dt, li, tbody, td, tfoot, th, thead, tr, button, del, ins, map, object,
    a, abbr, acronym, b, bdo, big, br, cite, code, dfn, em, i, img, kbd, q, samp, small, span,
    strong, sub, sup, tt, var {
    	margin: 0;
    	padding: 0;
    }
    Code (markup):
     
    yangyang, Dec 15, 2007 IP
  7. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, there is a difference. The first targets ALL elements, the third targets all the elements listed (the ones that are not form elements, form controls or CDATA), and I don't recall what the second one targets since I never use it (nor have had a need to).
     
    Dan Schulz, Dec 15, 2007 IP
  8. yangyang

    yangyang Banned

    Messages:
    757
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks Dan. I use YUI CSS reset most of the cases, works out good.
     
    yangyang, Dec 18, 2007 IP