SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CSS inheritance problem

    I'm developing a two column layout site. But the problem arises when ever I'm trying to float the two columns, they are not inheriting the background color of the parent div.

    my code is.
    Code CSS:
     
    * { margin:0; padding:0; border:0;}
     
    body { width:100%; height:100%; font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; font-size:16px; 
    	background:url(icons/WoodenWallw.jpg); color:#CF9;	margin:0; padding:0; }
     
    #container { width: 900px; margin:0 auto; padding-top:10px;}
     
     #main  { background-color:#886D53;}
     
    #maincontent {  width:500px; float:left; padding:15px;}
    #sidebar{ width: 290px; padding:0 10px; margin:0; border-left:solid #aaa 1px; float: right; }
    Code HTML4Strict:
     
    <body>
    	<div id="container">
            <div id="main">
            	<div id="maincontent">
     
    data goes here......
     
                    </div><!--End of maincontent div-->
     
                    <div id="sidebar">
     
    data goes here.........
     
     </div><!--End of sidebar div-->
     
              </div><!--End of main div-->
     
    	</div><!--End of container div-->
        <div id="footer">
      </div>
     
    </body>
    </html>


    How to solve this ? After specifying the floating objects, they are not inheriting the background color of its immediate parent's color. But if I won't float those two columns then they are inheriting the color.

    What is the glitch here ?

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Backgrounds are not inherited, but the initial value is transparent which lets the parent's background shine through.

    However, floated elements are removed from the document flow and don't affect their block-level parents. If all children are floated, the parent collapses to zero height and no background will be visible.

    There are several ways to make a parent expand to enclose its floated children. In this case the simplest way is probably to add,
    Code CSS:
    #main {overflow:hidden}
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for the reply

    AutisticCuckoo.

    This is working, but then all of my contents are floating towards the right side only. and leaving the left side blank.

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It shouldn't do that, with the CSS you've shown.

    Your maincontent is 530px wide and your sidebar is 311px, which gives 841px in total. That's less than the total width of 900px, so it should work.

    You should probably provide a link to the live site to get more help. (I'm off to a meeting now, but some of the gurus will probably step in.)
    Birnam wood is come to Dunsinane

  5. #5
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,795
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by cools_sonu View Post
    Thanx for the reply

    AutisticCuckoo.

    This is working, but then all of my contents are floating towards the right side only. and leaving the left side blank.
    Not with the code shown above it doesn't

    There must something else going on. Do you have a link or perhaps post all the code so we can check

    You will need a width here for IE6 though.

    Code:
    #main {
        background-color:#886D53;
        overflow:hidden;
        width:900px;
    }

  6. #6
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx AutisticCuckoo & Paul O'B

    Now after putting the width too, this is working just fine in all browser except safari.

    So in all now this is working fine.

    Thanx very much.

  7. #7
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,795
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    If you are still having problems with safari then post your updated code and we'll take another look.

    If it's all sorted then glad we could help

  8. #8
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Paul O'B View Post
    If you are still having problems with safari then post your updated code and we'll take another look.

    If it's all sorted then glad we could help
    Thanx. Well I don't have a live website to show u as I'm testing on localhost.

    So I'm posting all my codes here both html and css.
    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <title>Main Layout</title>
    </head>

    <body>
        <div id="container">
            <div id="header">
                <h1 title="Dummy Testing">
                  <a href="index.php">
                    <img src="css/icons/logo5.gif" width="80" height="100">A Dummy Website
                  </a>
                </h1>
                
                <div id="headerSide">
                  <div id="adds">
                      <p>This site is best viewed on Google Chrome</p>
                      <p>Download it here &raquo; 
                        <a href="http://www.google.com/chrome/index.html" target="_blank">
                          <img src="css/icons/google-chrome.png" width="20" height="20" />
                        </a>
                      </p>
                  </div>
                  
                  <div id="homeBar">
                      <p >
                        <a href="index.php" >
                          <img id="homeImage" class="homeImage" alt="Home" src="css/icons/home.ico" width="25"
                          height="25" title="Home">&nbsp;&nbsp;
                        </a>
                        <a href="login.php" title="login here" class="homeBar">Login!</a>
                        <a href="register.php" title="Register to file your return" class="homeBar">Register?</a>
                      </p>
                  </div>
                </div>
                
                <div id="nav">
                  <div id="menuBar">
                      <a href="index.php" class="menuBar"><span>Home</span></a>
                      
                      <a href="about.php" class="menuBar"><span>About</span></a>
                      
                      <a href="services.php" class="menuBar"><span>Services</span></a>
                      
                      <a href="faq.php" class="menuBar"><span>FAQ</span></a>
                      
                      <a href="contact.php" class="menuBar"><span>Contact</span></a>
                  </div>
                </div>
            </div>
            
            <div id="main">
                
                    <div id="maincontent">
                        
                        <h1>Frequently Asked Questions</h1>
                        <h3 id="what">What is Lorem Ipsum?</h3>
                        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
                        
                        <h3 id="why">Why do we use it</h3>
                        <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
                        
                        <h3 id="where">Where does it come from?</h3>
                        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

    The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham</p>
                       
                    </div><!--End of maincontent div-->
                    
                    <div id="sidebar">
                    <h3>Suggested Questions?</h3>
                    <p><a href="#what">What is Lorem Ipsum</a></p>
                    <p><a href="#why">Why do we use it?</a></p>
                    </><a href="#where">Where does it come from?</a>
          
        
        
                    
                    </div><!--End of sidebar div-->
              
                 
            </div><!--End of main div-->
        </div><!--End of container div-->
        <div id="footer">
         <p>All &copy; Dummy Website&reg;
          <?php 
          ini_set
    ('date.timezone''Asia/kolkata');
          
    $startTime "Nov 2006";
          
    $currentTime date("M y");
          
          if(
    $startTime == $currentTime
          {
              echo 
    "($currentTime)";
          } 
          else 
          {
              echo 
    "($startTime &#8212 $currentTime)";
          }
          
          
    //echo $currentTime; 
          
    ?>. &nbsp;&nbsp;
              <a href="privacy.html">Privacy Policy</a> |
              <a href="term.html">Terms & Conditions</a>
           </p>
        </div>
        
    </body>
    </html>

    And the CSS code:
    Code CSS:
     
     
    /* Color 
     
    	#886d53 = Background for content
    	#00BFFF = Form Text Color
    	#2A3F55 = Form (Fieldset) Border Color
    	#1B9D95 = Link Color
     
    */
     
    /* Global Designing */
     
    * { margin:0; padding:0; border:0;}
     
    body { width:100%; height:100%; font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; font-size:16px; 
    	background:url(icons/WoodenWallw.jpg); color:#CF9;	margin:0; padding:0; }
     
    #container { width: 900px; margin:0 auto; padding-top:10px;}
     
     
     
    /* Header Section */
     
    #header { height: 150px; position:relative; margin:0; padding: 0; border:0; border-bottom:20px #886d53;}
     
    #header a { color:#999; text-decoration:none; margin:0; padding-top:20px; }
    	#header a:hover { color:#00BFAA;}
     
    #headerSide { position:absolute; left: 600px; top:0; font-size:11px; }
    	#homeBar { margin-top:15px; font-size:16px; right:0; }
    	#homeBar .homeBar { padding:2px 6px; margin:0 2px 10px 2px; background:url(icons/menu_bg.gif); }
    	 #header a.homeBar:hover { color:#FFF; background:url(icons/menubg-over.gif) repeat-x center; font-weight:bold;}
     
     
     
    /* Menu Bar */
     
    #nav { height:34px; position:relative; color:#E0E0E0;bottom:0px; margin-top:10px;}
    #menuBar { height:34px;  font-size:15px; text-transform:uppercase; font-weight:bold; padding:0 20px;
    		  background: url(icons/menu_bg.gif) repeat-x bottom left; border-bottom: 12px solid #886d53;  }
     
    		#menuBar a:hover { color:#fff; background:#000 url(icons/menubg-over.gif) repeat-x bottom left; }
     
    #menuBar a span { padding:12px 20px; height:21px; font-weight: normal; float:left;
    		font-family: "Myriad Pro", Helvetica, Arial, Verdana, sans-serif; }
     
    		#menuBar a:hover span {  display:block; width:auto; cursor:pointer;}
     
    #menuBar a#current, #menuBar a#current:hover { color:#fff; line-height:275%;
    		background:#886d53 url(icons/menuleft-active.gif) no-repeat top left; }
     
    #menuBar a#current span { display:block; padding:3px 20px; width:auto; height:32px;
    	background:#886d53 url(icons/menuright-active.gif) no-repeat top right; }
     
     
    /* Content Area*/
    #main  { background-color:#886D53; overflow:hidden; width:900px; }
     
    /* Main Content Area */	
     
    	#main #maincontent {  width:550px; padding:15px; float:left;}
     
    	#maincontent p { font-family:Verdana, Geneva, sans-serif; font-size:15px; text-align:justify; line-height:1.4em; color:#fff; margin:1ex 0; }
     
    	#maincontent h1 { font-size:1.6em; font-weight:bold; color:#1b9d95; margin: 0 0 .4ex 0; }
    	#maincontent h2 { font-size: 1.2em; color:#3c3809; margin: .4ex 0; }
    	#maincontent h4 { font-size: 1.1em; font-weight:bold; color:#666; margin:1ex 0 -.2ex 0; }
     
    /* Side Bar area */
     
    	#sidebar{ width: 290px; float: right; padding:0 10px; margin:0; border-left:solid #aaa 1px; }
    	#sidebar h3 { font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; font-size: 1.1em; line-height:1.2em; color:#1B9D95; }
     
    /* Footer */
     
    div#footer { clear:both; background:transparent; margin: 0 auto; padding:5px;}
    #footer p { font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; font-size:0.75em; color:#fff; margin: 0; padding: 0; text-align:center; }
     
    #footer a { color:#1B9D95; text-decoration:none; }

  9. #9
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,795
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Looks like safari is snagging the float so add this to create a clean break and start it on a new line.

    Code:
    #main {
        background-color:#886D53;
        overflow:hidden;
        width:900px;
        clear:both;
    }

  10. #10
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cools,

    Try uploading your code to the W3C validator. That will show you places where simple things are wrong. Different browsers react differently to some errors.

    Simply not closing an img tag with a /> may be the problem.
    Each day is a learning experience.

  11. #11
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Paul O'B View Post
    Looks like safari is snagging the float so add this to create a clean break and start it on a new line.

    Code:
    #main {
        background-color:#886D53;
        overflow:hidden;
        width:900px;
        clear:both;
    }
    Yea Paul

    thanx really very much, after putting the clear:both safari lives upto the mark..

    hehe Now I'm really very much happy ..

    Alast haha!

  12. #12
    SitePoint Zealot cools_sonu's Avatar
    Join Date
    Jan 2010
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CSU-Bill View Post
    Cools,

    Try uploading your code to the W3C validator. That will show you places where simple things are wrong. Different browsers react differently to some errors.

    Simply not closing an img tag with a /> may be the problem.
    Yupp Bill thanx for that tip.

    Now I'l do that first. but here folks are really cool and always help others.

    Your tag line is really inspiring.


Bookmarks

Posting Permissions

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