如何使一个div包装两个浮动divs里面?

编程入门 行业动态 更新时间:2024-10-23 20:20:03
本文介绍了如何使一个div包装两个浮动divs里面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道这是一个常见的问题,但我找不到解决方案在web到目前为止。 我想有两个div包装在另一个div,但是这两个div在内部必须对齐相同的级别(例如:左边一个占用20%的宽度的wrappedDiv,右边一个采取另一个80%)。为了实现这个目的,我使用了下面的示例CSS。但是,现在wrap DIV没有包装那些div全部。包装Div具有比包含在内部的两个div小的高度。我如何确保wrap Div具有最大的高度作为包含的div?谢谢!

I don't know if it's a common problem, but I can't find the solution in web so far. I would like to have two divs wrapped inside another div, however these two divs inside have to be align the same level (for example: left one takes 20%width of the wrappedDiv, right one take another 80%). To achieve this purpose, I used the following example CSS. However, now the wrap DIV didn't wrap those divs all. The wrap Div has a small height than those two divs contained inside. How could I make sure that the wrap Div has the largest height as the contained divs? Thanks!!!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>liquid test</title> <style type="text/css" media="screen"> body { margin: 0; padding: 0; height:100%; } #nav { float: left; width: 25%; height: 150px; background-color: #999; margin-bottom: 10px; } #content { float: left; margin-left: 1%; width: 65%; height: 150px; background-color: #999; margin-bottom: 10px; } #wrap { background-color:#DDD; height:100%; } </style> </head> <body> <div id="wrap"> <h1>wrap1 </h1> <div id="nav"></div> <div id="content"><a href="index.htm">&lt; Back to article</a></div> </div> </body> </html>

推荐答案

这是一个常见的问题,块。修复它的最好方法是在第二个 div 后使用 clear:两个。

It's a common problem when you have two floats inside a block. The best way of fixing it is using clear:both after the second div.

<div style="display: block; clear: both;"></div>

它应该强制容器的高度正确。

It should force the container to be the correct height.

更多推荐

如何使一个div包装两个浮动divs里面?

本文发布于:2023-10-08 01:48:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471161.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   div   divs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!