I have two divs under one parent div
, the parent div has 100% width:
<div id="parent"> <div class="left"></div> <div class="right"></div> </div>
The conditions are:
I have tried both float:left, and dispaly:inline-block but neither solution seems to work.
Any suggestion would be appreciated.
I'd go with @sandeep's display: table-cell
answer if you don't care about IE7.
Otherwise, here's an alternative, with one downside: the "right" div
has to come first in the HTML.
See: http://jsfiddle.net/thirtydot/qLTMf/
and exactly the same, but with the "right div" removed: http://jsfiddle.net/thirtydot/qLTMf/1/
#parent { overflow: hidden; border: 1px solid red } .right { float: right; width: 100px; height: 100px; background: #888; } .left { overflow: hidden; height: 100px; background: #ccc } <div id="parent"> <div class="right">right</div> <div class="left">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam semper porta sem, at ultrices ante interdum at. Donec condimentum euismod consequat. Ut viverra lorem pretium nisi malesuada a vehicula urna aliquet. Proin at ante nec neque commodo bibendum. Cras bibendum egestas lacus, nec ullamcorper augue varius eget.</div> </div>
@Yijie; Check the link maybe that's you want http://jsfiddle.net/sandeep/NCkL4/7/
EDIT:
http://jsfiddle.net/sandeep/NCkL4/8/
OR SEE THE FOLLOWING SNIPPET
#parent{ overflow:hidden; background:yellow; position:relative; display:table; } .left{ display:table-cell; } .right{ background:red; width:50px; height:100%; display:table-cell; } body{ margin:0; padding:0; }
<div id="parent"> <div class="left">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div> <div class="right">fixed</div> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With