简体   繁体   中英

dynamic and fixed size in CSS

I need in the same HTML row to have 2 divs: one will stay the same width while the other's size will be increased once the web page is being increased by the end user.

So I defined one div and inside 2 divs like this:

<div>
    <div style="float:left" width="20px">first div</div>
    <div style="float:left" width="100%">first div</div>
</div>

However it does not work!

How can I create 2 divs in the same line that one will be fixed size and the other one relative?

Do I win?

Live Demo

Live Demo #2 (using classes and with support for more than one instance of this)

HTML:

<div id="divHolder">
    <div id="div1">1</div>
    <div id="div2">2</div>
</div>

CSS:

#divHolder {
    overflow: auto
}
#div1 {
    float: left;
    width: 20px;
    background: #ccc
}
#div2 {
    margin-left: 20px;
    background: #888
}

Take a look at this: http://jsfiddle.net/Shaz/GaZYt/2/

The left box will change size depending how much horizontal space is left. The right box will always have a minimum and maximum width of 200px.

Try setting display:inline on the div elements. The default display value for a div is block (which causes them to appear on seperate lines). Here is an example on js fiddle

I believe you may need to use Javascript to handle this case.

$(window).resize(function() {
  var $left = $('#left');
  var $container = $('#container');
  $right.width($container - $left);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM