如何使中间div填充浮动元素之间的空间? [英] How make middle div to fill space between floating elements?

查看:210
本文介绍了如何使中间div填充浮动元素之间的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个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.

View fiddle example.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆