Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Feb 2011
    Posts
    109
    Thanks
    6
    Thanked 1 Time in 1 Post

    Really simple html problem

    or so I imagine...

    I want to insert a transparent background image into the main #content of my page.

    The #content contains two divs (#contentLeft and #contentRight) before being closed off. However, because I don't want to set the height of the #content, I can't see any image I insert. I would have though that the #content would automatically stretch to incorporate whatever height dimensions #contentLeft and #contentRight use but this obviously isn't the case.

    The only way I can think of a getting around this (other than setting the height) is to create another div which incorporates #content, #contentLeft, #contentRight and probably #footer. This would make a inserting a rounded edge image into #footer problematic (unless I used a jpeg that had the background coulour matched with the body background colour).

    Hope my question is clear.

    Code:
    <body>
    	<div id="wrapper">
    		<div id="banner">
                    </div>
            	<div id="nav">
                	<ul>
                    	<li><a href="index.html" title="Click for Home">Home</a></li>
                        <li><a href="about.html" title="Click for About">About</a></li>
                        <li><a href="news.html" title="Click for News">News</a></li>
                        <li><a href="involved.html" title="Click for get Involved">Get Involved</a></li>
                        <li><a href="services.html" title="Click for Services">Services</a></li>
                        <li><a href="links.html" title="Click for Links">Links</a></li>
                    </ul>
                </div>
    		 <div id="content">
                    	<div id="contentLeft">
    			</div>
                    	<div id="contentRight">
    			</div>
                    </div>
                    	     <div id="footer">
       	                     </div>
             </div>
    </body>

  • #2
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    I think we need to see more than a snippet of your code. Better would be a live link to your site.
    Teed

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,677
    Thanks
    6
    Thanked 1,008 Times in 981 Posts
    I suppose you need to read on containing floats. Specifically, the content div is collapsing to zero when you float those child divs. You need to clear the float inside that content div and an easy way to do this is:

    Code:
    #content:after {
      content: ".";
      display: block;
      height: 0;
      clear: both;
      visibility: hidden;
    }
    IE7 and 6 don’t understand the :after pseudo class but incorrectly contain a float if the element has layout. For this you can apply height: 1% to the container div.

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello garabildi,
    An even easier way of clearing floats adding overflow: auto; to the element that contains the floats.

    See here for a description of how that works.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #5
    Regular Coder
    Join Date
    Feb 2011
    Posts
    109
    Thanks
    6
    Thanked 1 Time in 1 Post
    Spot on, Excavator!

    I've tested it in a few browsers (latest FF, Opera and Win 8) and the more concise version seems to work fine. But I am a little worried that the design view of Dreamweaver (CS4) doesn't seem able to handle this fix. Instead of two child divs appearing within the parent they appear to the left. In other words, I've got a site that stretches 1600px across the Design view. #content = 800px, #contentLeft = 400px, #contentRight = 400px. I'm hoping that this is just Dreamweaver.

  • #6
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Quote Originally Posted by garabildi View Post
    the design view of Dreamweaver (CS4) doesn't seem able to handle this fix.
    DW design view is a joke. It doesn't render code like any known browser. Don't depend on it at all, much better to use code view and F12.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #7
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Live view does a fair job at rendering, but as Excavator says, I would never rely on DW to render code. Always view code in live browsers.

    Design view isnt really meant as a preview of what code will look like in a browser. For example, any server-side code wont be parsed in design view alone. Live view will though.
    Last edited by teedoff; 02-25-2011 at 07:00 PM.
    Teed

  • #8
    Regular Coder
    Join Date
    Feb 2011
    Posts
    109
    Thanks
    6
    Thanked 1 Time in 1 Post
    Cheers guys.

    Yeah, I know it's pretty crap (it also appears funny in Live version). I guess I'm just used to design and live view rendering something fairly close to what you see in a browser. But if this is just a case of design view having a conniption, as opposed to some rotten coding on my part (which is HIGHLY likely give my experience level), I'm happy.

  • #9
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,677
    Thanks
    6
    Thanked 1,008 Times in 981 Posts
    Quote Originally Posted by Excavator View Post
    An even easier way of clearing floats adding overflow: auto; to the element that contains the floats.
    Sorry to chime in so late. This is definitely true but I have to add that this isn’t a solution for every case as it may cause issues if you are positioning or otherwise moving elements outside of the boundaries of that element. The :after rule may be a little more elaborate but doesn’t cause issues in that respect.

    Another alternative just comes to mind: Create a block formatting context for the content div by floating it itself (applying a 100% width). This will also cause interior floats to be contained and doesn’t cause the problems the overflow solution does.

  • #10
    Regular Coder
    Join Date
    Feb 2011
    Posts
    109
    Thanks
    6
    Thanked 1 Time in 1 Post
    Thanks, I'll keep this in mind next time such issues arise.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •