+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13
Like Tree2Likes

Thread: CSS question

  1. #1
    danielcopelandnz56 is offline x10Hosting Member danielcopelandnz56 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    CSS question

    On one of my pages, I have a background image with an empty <div> over the top of it; the empty <div> is a partly-transparent white background for the text <div>. I can't put the text inside the empty <div>, because then the text is partly transparent as well.
    The problem I'm having is that, although the text and background <div>s have exactly the same positioning and size CSS, the text sticks out of the white background on the right-hand side. Here is the code:
    Code:
    #whitebox {
        position : absolute;
        width : 83.333%;
        left : 8.333%;
        height : 100%;
        background-color : #ffffff;
        opacity : 0.66667;
        filter : Alpha(opacity=66.667);
    }
    
    #content {
        position : absolute;
        width : 83.333%;
        left : 8.333%;
        height : 100%;
        padding : 1em;
    }
    And, to be clear, the <div id='content'> is outside the <div id='whitebox'> and comes after it on the webpage.
    The problem occurs in Firefox. It did not occur in IE until I put a doctype declaration on the HTML page -- but now it does.
    I've had this problem a few times. In the past I've quietly changed the design so as not to have to worry about it, but this is no longer an option.

  2. #2
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: CSS question

    When you use width and height properties in "standards mode", you are sizing the content-box. The content-box is just the content -- the padding, border and margin are all outside of the content-box. Since "whitebox" and "content" have the same size, but "whitebox" has no padding, "content" is actually larger by the amount of the padding (2em in either direction).

    That's fixable using the CSS3 box-sizing: border-box; declaration, which makes the browser work in the sensible way that "quirks mode" Internet Explorer works -- but box-sizing isn't supported in all browsers. (Ironically, Internet Explorer -- at least versions before 9 -- is the problem; it can't be forced to act like its old self while there's a valid doctype in place.)

    You can always use a tiled semitransparent white PNG for the content background image as a work-around, or use an RGBa background-color (which includes an opacity value) for modern browsers and a filter for Internet Explorer. That will let you dispense with "whitebox" altogether. See this post at DaltonLP.com for details. You will still have to deal with the padding width on the box, but you won't have to absolutely position anything, so you can use "auto" for the margins.
    fomalhaut likes this.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  3. #3
    danielcopelandnz56 is offline x10Hosting Member danielcopelandnz56 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    Re: CSS question

    Thanks for the reply; it was very helpful. I'm afraid I didn't do what you suggested, because I'm not in a position to assume that users will be using CSS3-compliant browsers; but I was able to solve the problem in a different way with the information you gave me.
    Now I have another problem. My design specifications require that I put some pages in double columns. Because I can't assume CSS3 capability, and also have to make it work in IE, the columns: property and its variants and derivatives are no use. I've tried several other fixes I've found, and none of them are working; the top of the right-hand column sits level with the bottom of the left-hand one. Here's the CSS I'm currently using:
    Code:
    .doublecol {
        width : 821px;
        margin : 0 auto;
    }
    
    .leftcol {
        position : relative;
        margin-left : 0;
        float : left;
        width : 402px;
    }
    
    .rightcol {
        position : relative;
        margin-left : 419px;
        float : right;
        width : 402px;
    }
    And here's the HTML to go with that:
    Code:
    <div class='doublecol'>
                    <div class='leftcol'>
                                    <p>
                                                    Integer nisi mi, congue ultricies porta auctor, lacinia eu neque...<br />
                                                    Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
                                    </p>
                    </div>
                    <div class='rightcol'>
                                    <p>
                                                    Aenean tortor diam, lacinia ut condimentum vitae, iaculis sit amet urna...<br />
                                                    Sed semper, orci eu pulvinar sagittis, metus arcu congue lorem, vitae feugiat velit leo at est.
                                    </p>
                    </div>
    </div>

  4. #4
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: CSS question

    The margin is considered part of the block for floating purposes, so the right-hand column is floating as high as it's allowed to. You don't need the margin-left if you're floating right -- the block will position itself according to the right-hand side position (the right-hand edge of the block will be moved as far to the right as it can go within the container, and the left-hand edge will be determined by the width you've declared).

    That may still leave you with a staggered arrangement in some browsers, so adding a clear: right; to your right-floated elements should prevent them from clearing anything that is floated left.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  5. #5
    danielcopelandnz56 is offline x10Hosting Member danielcopelandnz56 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    Re: CSS question

    Problem solved! Many thanks.

  6. #6
    danielcopelandnz56 is offline x10Hosting Member danielcopelandnz56 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    Re: CSS question

    Yet another CSS problem. I can't get my content centred horizontally. The solution people give to this, in web forum after web forum, is:
    Code:
    #container {
    	width : 1024px;
    	margin-left : auto;
    	margin-right : auto;
    }
    ...which is what I have, but isn't working. I have tried several changes to my DOCTYPE declaration, and none of them so far has made it work either.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    -- left-aligned in Firefox and IE;
    Code:
    <DOCTYPE html PUBLIC "http://www.w3.org/1999/xhtml">
    -- left-aligned in Firefox, right-aligned in IE;
    Code:
    <!DOCTYPE html PUBLIC "http://www.w3.org/1999/xhtml">
    -- left-aligned in Firefox, right-aligned in IE;
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/1999/xhtml">
    -- left-aligned in Firefox and IE. Need help rather urgently.
    [EDIT: Putting
    Code:
    	display : block;
    in the CSS declaration didn't work either.]
    [EDIT: Nor did setting the text-align for the <body> to "center" and the text-align for the <div id='container'> to "left".]
    Last edited by danielcopelandnz56; 12-14-2011 at 06:27 PM.

  7. #7
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: CSS question

    The auto-margins part is right (explaining why you see it everywhere) which means that what you're applying it to must be wrong -- or at least not what you think it is. If you insist on using XHTML 1.0 Transitional,* then your first doctype declaration is the "rightest" of the bunch. (The third is missing the URL to the DTD, so browsers will go into "quirks mode". Firefox stays pretty close to the standard, but IE's rendering is very different -- it acts like IE5.x.)

    We'd need to see a minimal example of your markup (all of the divs/containers, but you can sort of gloss over the content with some dummy text or comments) to help you find the problem.

    ___________________
    * I've been fighting XHTML as a concept since it first reared its ugly head. HTML is a subspecies of SGML, which is intended as a text document markup language. XML is a "mimic" language that is not actually related; it only bears an external resemblance to SGML and HTML because it uses the same "alphabet" (the tagging schema and DTDs). Did you know that there is no reason why sibling paragraphs should come in any particular order on the displayed page in XHTML, or that your "ordered" lists can be in any order? The only thing keeping user agents from rendering, say, the shortest paragraphs first is convention -- the rules of XML (and XHTML is an XML document type) don't include ordering precedence among siblings in a hierarchy. A serial reading of the document (as with SAX) will always get the order right, but a tree view (DOM) doesn't have to if the document is XHTML. I'm glad it's gone.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  8. #8
    danielcopelandnz56 is offline x10Hosting Member danielcopelandnz56 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    Re: CSS question

    Here's my content HTML:
    Code:
    <body>
    	<div id='backgroundbody'>
     		<div id='whitebox'></div>
     		<div id='content'>
     			<div id='heading'><img src='TITLEIMAGE.gif' /></div>
     			<div id='contactdetails'>[address and phone number]<br />
    				[e-mail]
     			</div><hr />
     			<div id='topmenu'>
     				<div class='menuitem'>&nbsp;</div>
     				<div class='menuitem'>&nbsp;</div>
     				<div class='menuitem'><span class='highlight'>HOME</span></div>
     				<div class='menuitem'><a href='[page 1 url]'>PAGE 1</a></div>
     				<div class='menuitem'><a href='[page 2 url]'>PAGE 2</a></div>
    				<div class='menuitem'><a href=''[page 3 url]'>PAGE 3</a></div>
     			</div><br />
     			<hr class='spaceunder' />
     			<hr class='spaceunder' />
     			<div id='maintext'>
     				<span class='intro'>[front-page text goes here, but I don't think this is the issue as it's happening on all the pages]</span>
     			</div>
     			<div id='illustration'><img src='[front-page illustration here]' /></div>
    			<br />
     			<hr />
     			<div id='copyrightinfo'>[copyright notice]</div>
     		</div>
     	</div> 
    </body>
    Please help!
    Last edited by danielcopelandnz56; 12-14-2011 at 11:54 PM. Reason: Tidying up code

  9. #9
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: CSS question

    I see you've used "backgroundbody" rather than the more conventional "container" as the id for your outermost div. Are you using #backgroundbody or #container in your CSS?
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  10. #10
    danielcopelandnz56 is offline x10Hosting Member danielcopelandnz56 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    9

    Re: CSS question

    #backgroundbody. I did check and double-check for mistyped IDs.

    ---------- Post added at 12:33 AM ---------- Previous post was at 12:29 AM ----------

    Actually, here's the full CSS as well. I can't find any errors; maybe you can.
    Code:
    body {
    	margin : 0;
    	border : 0;
    	padding : 0;
    	color : #908f8d;
    	font-family : "Adobe Garamond", "Adobe Garamond Pro", "Garamond", "Palatino Linotype", "Perpetua", "Times New Roman", serif;
    	font-size : 16px;
    	font-weight : 450;
    	text-align : center;
    }
    
    body a:link {
    	color : #161719;
    	text-decoration : none;
    }
    
    body a:visited {
    	color : #161719;
    	text-decoration : none;
    }
    
    body a:hover {
    	color : #ecc196;
    	text-decoration : none;
    }
    
    body a:active {
    	color : #ecc196;
    	text-decoration : none;
    }
    
    #backgroundbody {
    	position : absolute;
    	width : 1024px;
    	margin-left : auto;
    	margin-right : auto;
    	height : 100%;
    	background-color : #a3a3a3;
    	background-image : url('[background image URL]');
    	background-attachment : fixed;
    	background-repeat : no-repeat;
    	background-position : -200px 0px; 
    	padding : 0;
    	border : 0;
    	text-align : left;
    }
    
    #whitebox {
    	position : absolute;
    	width : 821px;
    	left : 85px;
    	height : 100%;
    	padding : 16px;
    	background-color : #ffffff;
    	opacity : 0.66667;
    	filter : Alpha(opacity=66.667);
    }
    
    #content {
    	position : absolute;
    	width : 821px;
    	left : 85px;
    	height : 100%;
    	padding : 16px;
    }
    
    #content hr {
    	color : #908f8d;
    	clear : both;
    }
    
    .spaceunder {
    	margin-bottom : 25px;
    }
    
    #heading {
    	margin-top : 25px;
    	margin-bottom : 8px;
    	font-family : "Engravers MT", "Wide Latin", serif;
    	font-size : 40px;
    	color : #161719;
    }
    
    #contactdetails {
    	font-size : 14px;
    }
    
    #topmenu {
    	margin-top : 30px;
    	font-family : "Avenir 55 Roman", "Calibri", "Gautami", "Helvetica", "Arial", sans-serif;
    	font-size : 15px;
    	font-weight : 900;
    }
    
    .menuitem {
    	position : relative;
    	float : left;
    	width : 16.667%;
    	text-align : right;
    }
    
    .highlight {
    	color : #ecc196;
    }
    
    #maintext p {
    	color : #44566a;
    }
    
    .intro, .contactintro {
    	font-size : 24px;
    	color : #161719;
    }
    
    .doublecol {
    	width : 821px;
    	margin : 0 auto;
    }
    
    .leftcol, .contactintro {
    	position : relative;
    	margin-left : 0;
    	float : left;
    	width : 402px;
    }
    
    .rightcol {
    	position : relative;
    	float : right;
    	width : 402px;
    }
    
    #illustration {
    	margin-top : 24px;
    }
    
    #mapimage {
    	position : relative;
    	float : right;
    	width : 402px;
    }
    
    #copyrightinfo {
    	font-size : 12px;
    }

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Answer a Question / Ask a Question
    By dolphindeveloper in forum Off Topic
    Replies: 0
    Last Post: 07-16-2011, 04:17 PM
  2. [question]Adding Domain[question]
    By pratik.rathod16245 in forum Free Hosting
    Replies: 3
    Last Post: 01-18-2011, 04:17 AM
  3. JS speed question & PHP security question
    By shant93 in forum Programming Help
    Replies: 11
    Last Post: 01-02-2011, 08:55 AM
  4. MySQL question and a Mailing List question
    By CrazyPunch in forum Programming Help
    Replies: 4
    Last Post: 11-22-2010, 08:53 PM
  5. Answer a question/Ask a question
    By humphrey in forum Off Topic
    Replies: 29
    Last Post: 11-26-2005, 07:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers