开发者

Two div element next to each other (For page header)

I am trying to make something look like following (don't concern color here. my concern here is the shape);

Two div element next to each other (For page header)

I tried something with following code but didn't succeed!

  <html>
    <head>
      <style type="text/css">

        #header{border:3px solid gray;padding:10px;}
        #header-left-container{border:1px solid gray;float:left;width:30%;}
        #header-right-container{border:1px solid gray;float:right;width:69%;}

      </style>
    </head>
    &l开发者_如何学Ct;body>

      <div id="header">

        <div id="header-left-container">
          pooo
        </div>
        <div id="header-right-container">
          bla bla bla.....
        </div>

      </div>

    </body>
  </html>

I know this can be done with table easily but I don't wanna use table in my application where I can do the same with div elements.

any suggestion here?


http://jsfiddle.net/j4DnG/7/

What you need to do is clearing the area arround the 2 floated divs. Doing this by modern technuiqe is giving the parent the property of Overflow:Hidden or Auto (what ever fitting you more. I recommend hidden)

In the past people user clearfix (google on that). Todays we use that approach.

As well people used to put clear:both after the creation of the two elements. That has a negative side- 1 more element in the dom.


You need to add overflow:auto; to the #header css; without that divisions don't expand to contain floated elements.


your code looks fine...

suggestions:
Just Add clearfix after floating divs so as they will be contained inside the parent object like:

<style>.clarFix{clear:both;}</style>
<div class="clearfix"></div>


Add

<br style="clear:both" />

after second div. Or make the container div float: left. Or use one of the css frameworks if You don't want to become css master before You create a webpage. One is http://960.gs/


Do you use firebug? go on twitter.com and see how they have defined a left and a right container is the style sheet . They're not using table to implement it. just div


Just replace the float: right; declaration with a margin-left: 30%; declaration for #header-right-container. You don't need to float both of them. This way, you will only need to clear floats if the left block is taller than the right block. See this fiddle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜