左浮动 div 的底部边框大小不同

发布于 2024-12-03 09:59:52 字数 2537 浏览 0 评论 0原文

我的设计师在很多设计中使用了这种技术,但我无法决定 css'ing 的最佳方式,因此它会自动流动(因为它进入 cms)

基本上,当浮动 2column div 结构时,我希望有每个 div 的底部边框。我会将边框放在环绕元素上,但两个 div 之间需要有间隙(右边距)。问题是两个 div 的大小不同,具体取决于内容。 height:100% 似乎无法解决问题(即使将父级设置为 100%)。我需要两个 div 的边框彼此齐平。

附件是任何格式化 css 之前的一些示例代码 - 我能够做到这一点的唯一成功方法是设置每个容器的高度,在这种情况下不起作用,需要流畅。

谢谢 !!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What's the best way?!</title>
<style type="text/css">
div.col50>div{width:45%; float:left; border-bottom:1px solid #000;}
div.col50>div+div{margin:0 0 0 5%;}

div.col50+div.col50{margin:50px 0 0;}

div.col50:before, div.col50:after { content: "\0020"; display: block; height: 0; overflow: hidden; }
div.col50:after { clear: both; }
div.col50{zoom:1;}
</style>
</head>

<body>
<div class="col50">
    <div>
        <p>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.</p>
    </div>
    <div>
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
    </div>
</div>
</body>
</html>

My designer uses this technique in a lot of designs and I can't decide the best way of css'ing this so it's automagically fluid (as it's going into a cms)

Basically, when floating a 2column div structure I would like there to be a bottom border per div. I would put the border on a wrapping element but there needs to be a gap between the two divs (margin-right). The problem is that the two divs are different sizes depending on content. height:100% will not seem to do the trick (even when making the parent 100%). I need the two divs's borders to be level with each other.

Attached is some sample code pre any formatting css- only successful way I have been able to do this is by setting the height per container, which in this case will not work, needs to be fluid.

Thank you !!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What's the best way?!</title>
<style type="text/css">
div.col50>div{width:45%; float:left; border-bottom:1px solid #000;}
div.col50>div+div{margin:0 0 0 5%;}

div.col50+div.col50{margin:50px 0 0;}

div.col50:before, div.col50:after { content: "\0020"; display: block; height: 0; overflow: hidden; }
div.col50:after { clear: both; }
div.col50{zoom:1;}
</style>
</head>

<body>
<div class="col50">
    <div>
        <p>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.</p>
    </div>
    <div>
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
    </div>
</div>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

划一舟意中人 2024-12-10 09:59:53

尝试制作 3 个

's:

Left

float:left;width:45%;margin-right:5%;

右侧

float:right;width:50%;

底部

clear:both;width:100%;

在底部

内,您可以创建两个带边框的

(浮动左右)。

Try to make 3 <div>'s:

Left <div> with float:left;width:45%;margin-right:5%;

Right <div> with float:right;width:50%;

Bottom <div> with clear:both;width:100%;

Inside bottom <div> you can create two <div>'s with border (floated left and right).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文