2013-11-22 58 views
3

HTML伸展一个div以适应所有的屏幕尺寸

<div class="whole"> 
    <div class="fst"></div> 
    <div class="sec"></div> 
    <div class="thd"></div>  
</div> 

CSS

.whole { 
    width: 100%; 
    height: 20px; 
} 
.whole div { 
    height: 20px; 
    display: inline-block; 
    position: relative; 
} 
.fst { 
    float: left; 
    width: 20px; 
    background: blue; 
} 
.sec { 
    background: red; 
} 
.thd { 
    float: right; 
    width: 20px; 
    background: blue; 
} 

内容是否有办法伸展div.sec以适应由div.fst和离开该地区任何屏幕尺寸的div.thddiv.fstdiv.thd的宽度已修复为像素。

有没有解决方案只有CSS?

真的很感谢您的帮助!

请参阅我fiddlehttp://jsfiddle.net/vHHcf/

+2

你的小提琴,你的代码是不一样的 – Ranveer

+0

有自己的方式为这个..无解。但是你可以通过使用媒体查询来实现它。 –

+0

对不起,小提琴更新! – jwall

回答

5

这似乎是你想要的。

jsFiddle example

既然你说.fst.thd有固定的宽度,可以使用calc()100%减去40px值。

.sec { width:calc(100% - 40px); }

更新CSS

.whole { 
    width: 100%; 
    height: 20px; 
} 
.whole div { 
    height: 20px; 
    display: inline-block; 
    position: relative; 
} 
.fst { 
    float: left; 
    width: 20px; 
    background: blue; 
} 
.sec { 
    background: red; 
    width:calc(100% - 40px); 
} 
.thd { 
    float: right; 
    width: 20px; 
    background: blue; 
} 
+1

谢谢!万分感激! – jwall

相关问题