开发者

Float two side by side one fluid one fixed

开发者 https://www.devze.com 2023-01-11 07:54 出处:网络
Here\'s the dilemma. <div id=\"l开发者_如何学Goists-container> <ul id=\"list-one\"></ul>

Here's the dilemma.

<div id="l开发者_如何学Goists-container>
<ul id="list-one"></ul>
<ul id="list-two"></ul>
</div>

I need content in list-one to expand 100% of parent div (list-container), if list-two has content, I want both lists to be 50% widths -floating side by side.

What happens is that list-two ends up clearing list-one, rather than floating to the right. Can anyone please help? This is what I have:

#list-container{width:600px}
ul#list-one{display:inline; float:left}
ul#list-two{display:inline; float:right; width:50%}


Use display:table. Also put in some hidden Internet Explorer markup. Some of it is run together because IE will add white space if you don't close the tags right after content.

<div id="lists-container" style="display:table; width:100%">
  <!--[if lt IE 8]>
  <table border=0 cellspacing=0 cellpadding=0>
    <tbody>
  <![endif]-->
  <div style="display:table-row">
    <!--[if lt IE 8]>
      <tr>
        <td width="50%">
    <![endif]-->
    <div style="display:table-cell; width:50%">
      <ul id="list-one"></ul>
    </div><!--[if lt IE 8]></td><td width="50%"><![endif]-->
    <div style="display:table-cell; width:50%">
      <ul id="list-two"></ul>
    </div><!--if lt IE 8]></td></tr><!endif]-->
  </div><!--if lt IE 8]></tbody></table><!endif]-->
</div>

This gives you nice, predictable, table-like behavior but still uses semantic markup. It works in IE 6+ and EOMB.

Note: I read about this somewhere online some time ago. I think it was a blog. If anybody can find and credit the source, I'd appreciate it. I can't find it!

If you don't want to use display:table, here is some code that will get you close. The applied width is 50% of the parent container + border + padding + margin, so this will behave differently at different widths, but this kind of works.

<style type="text/css">
  #list-container {
    width:600px
  }
  ul#list-one {
    border:1px solid red;
    display:inline;
    float:left;
    width:49%;
    margin:0;
    padding:0;
  }
  ul#list-two {
    width:49%;
    padding:0;
    margin:0;
    border:1px solid blue;
    display:inline;
    float:left;
  }
</style>

<div id="lists-container">
  <ul id="list-one">
    <li>item 1</li>
  </ul>
  <ul id="list-two">
    <li>item 2</li>
  </ul>
</div>


I've been working on a div that I need a twitter feed block floating right at 300px and then a fluid content block on the left. I always wanted to stay mobile friendly so hoped for the blocks to wrap to the next lines when the browse window was shrunk.

This worked for me:

<div id="tw" style="display:inline; float:right; width:300px;">Tweets</div>
<div id="content" style="display:inline-block;">
0

精彩评论

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