如何使中间div填充浮动元素之间的空间? [英] How make middle div to fill space between floating elements?
问题描述
我有三个div元素:left,middle和right。
左右是固定和浮动的。
这是我的代码:
<!DOCTYPE html>
< html>
< head>
< style>
* {border:dotted 1px red;}
#left {
width:200px;
float:left;
}
#middle {
float:left;
}
#right {
width:200px;
float:right;
}
< / style>
< / head>
< body>
< div id =left>左< / div>
< div id =middle>中< / div>
< div id =right>右< / div>
< / body>
< / html>
有关如何做的任何想法?我尝试了不同的解决方案,但没有设法做我想要的。
关键是重组你的html, code> middle 最后,从中间
中删除 float
href =http://web.archive.org/web/20150618153020/http://colinaarts.com/articles/the-magic-of-overflow-hidden/?>将其替换为 overflow :hidden
。
HTML p> < div id =left>左< / div>
< div id =right>右< / div>
< div id =middle>中< / div>
CSS
#left {
width:200px;
float:left;
}
#middle {
overflow:hidden;
}
#right {
width:200px;
float:right;
}
I have three div elements: left, middle and right. Left and right are fixed and floating. What I want is the middle div to fill the gap in between them.
This is my code:
<!DOCTYPE html>
<html>
<head>
<style>
* {border: dotted 1px red;}
#left {
width: 200px;
float: left;
}
#middle {
float: left;
}
#right {
width: 200px;
float: right;
}
</style>
</head>
<body>
<div id="left" > left </div>
<div id="middle"> middle </div>
<div id="right" > right </div>
</body>
</html>
Any ideas on how to do this? I tried different solutions but didn't manage to do what I want.
The key is to restructure your html to have middle
last, remove the float
from the middle
and replace it with overflow: hidden
.
HTML
<div id="left" > left </div>
<div id="right" > right </div>
<div id="middle"> middle </div>
CSS
#left {
width: 200px;
float: left;
}
#middle {
overflow: hidden;
}
#right {
width: 200px;
float: right;
}
这篇关于如何使中间div填充浮动元素之间的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!