有没有可能让一个子元素溢出其父 div?
我已经隐藏了所有的子 div 以防止溢出,但是我需要其中一个子元素溢出并浮动在限制的父元素外面。
请访问http://sandbox.pixelcraftwebdesign.com/engineering 并使用随机数进行一些计算。
右上角的小红数字需要浮动在输出 div 的外部。
有没有可能让一个子元素溢出其父 div?
我已经隐藏了所有的子 div 以防止溢出,但是我需要其中一个子元素溢出并浮动在限制的父元素外面。
请访问http://sandbox.pixelcraftwebdesign.com/engineering 并使用随机数进行一些计算。
右上角的小红数字需要浮动在输出 div 的外部。
我不完全确定你需要什么,但这里有一个示例,展示了一个子div浮动在外面并显示其所有内容:http://jsfiddle.net/dcpDa/
<div id="parent">
<div class="dontShow">Dont Show All Of Me</div>
<div class="dontShow">Dont Show All Of Me</div>
<div class="dontShow">Dont Show All Of Me</div>
<div class="dontShow">Dont Show All Of Me</div>
<div class="doShow">Okay, Show All Of Me</div>
<div class="dontShow">Dont Show All Of Me</div>
<div class="dontShow">Dont Show All Of Me</div>
<div class="dontShow">Dont Show All Of Me</div>
</div>
CSS:
div {
width: 5em; /*constrain div */
height: 1em;
border: 1px solid #aaa;
background-color: #ccc;
}
.dontShow { overflow: hidden; } /* do not show overflow */
.doShow {
width: auto; /* over ride constraints and show all */
height: auto;
position: absolute; /* break from flow */
left: 15em; /* position where you want */
}
最近我发现了两篇关于CSS定位的文章,它们非常有用:
CSS浮动布局101
CSS定位101
.nowrap {
white-space: nowrap;
}
假设您希望宽度保持不变:
.output
中删除overflow:hidden
。.output .right
设置为width:257px;overflow:hidden
。.result-rh, .result-temp
设置为width:241px
。此修复方法允许容器溢出,但在右侧隐藏溢出。 它还为右侧提供了适当的大小,以防止结果 SPAN 被裁剪。
在Firefox 3.6.17中对我有效。 应该也适用于其他浏览器。
使用position: absolute;
在您想要显示的子元素上。然后,您可以使用top
、left
、height
和width
来将其定位到所需位置。
overflow:hidden
,并且你将子元素定位到外部,那么子元素将不可见。 - Matthew Rapati
doctype
控制着你的渲染模式(quirks 或 standards)。你的指定了 HTML3.2,这将把你的文档置于 quirks 模式下。有许多编写 doctype 的方式。这里有一篇不错的文章:http://www.alistapart.com/articles/doctype/。但是,我的偏好是保持简短明了。这个简洁的语法将使你的文档处于 standards 模式下:<!DOCTYPE html>
。 - gilly3