液体宽度 div 内的右浮动 div。我该如何让它发挥作用?
我有一个 div,该 div 中有一个
标记中的名称(它在布局上的语义是正确的)和一个带有一些描述该
的值的 div代码>值。我希望嵌套的 div 位于右侧,而使其工作的唯一方法是使用固定宽度的容器和 float: right;
。正如您所猜测的,当
的值导致嵌套 div 移动到下方而不是向右时,对象就会中断。我尝试过 min-width
,但它最终拉伸到包含容器 div 的 div 的最大尺寸。我希望它是这样的,当 h4 太大时,整个 div 都会拉伸。
float: right;
。正如您所猜测的,当
的值导致嵌套 div 移动到下方而不是向右时,对象就会中断。我尝试过 min-width
,但它最终拉伸到包含容器 div 的 div 的最大尺寸。我希望它是这样的,当 h4 太大时,整个 div 都会拉伸。
I have a div, within the div is a name in an <h4>
tag (it's semantically correct with the layout) and a div with some values describing that <h4>
value. I want the nested div to be on the right side, and the only way I can get this to work is a fixed-width container and float: right;
. As you can guess, the object breaks when the value of the <h4>
causes the nested div move below instead of to the right. I've tried min-width
, but it ends up stretching to the maximum size of the div containing the container div. I want it to be such that when the h4 is too big the entire div just stretches.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您希望嵌套的
在
太大时向下移动,请将
clear: right
应用于嵌套的。
If you want your nested
<div>
to move down when the<h4>
is too large, applyclear: right
to the nested<div>
.尝试将 h4 设置为 display:block 并向左浮动。
Try setting your h4 to display:block and floating it left.
根据您希望距父级右上角的边距,为父级 div
position:relative
和子级 divposition:absolute
指定一个较小的顶部和右侧值分区为了使扩展宽度表现正确,您应该能够在父 div 上设置与子 div 的宽度相等的右填充,以便 h4 在子 div 太长时不会与子 div 重叠,但会扩展父 div正确地div。Give the parent div
position: relative
and the child divposition:absolute
with a small top and right value based on the margin you desire from the top-right corner of the parent div. In order to get the expanding width behaving correctly, you should be able to set right padding on the parent div equivalent to the width of the child div so that the h4 doesn't overlap the child when it is too long, yet expands the parent div properly.这项工作就像一个魅力:
让我们看看 CSS:
这是防止两个嵌套元素被破坏的简单方法......
max-width 的 40% 只是一个例子,可以是 60~40 :)
希望对你有帮助!
This work's like a charme:
Let's look at the CSS:
This is a simple way to prevent the two nested element's from breaking...
The 40% of max-width is just an example, could be 60~40 :)
Hope that helps U!