我试图显示包含在position: absolute;
仅一行中的div中的文本。
父级为position:relative;
,父级的宽度可能小于包含文本的div。
我希望我的position: absolute;
div文本停留在一行上,我怎么能做到这一点?目前,div的最大宽度是父级的宽度。
这是我用来解释问题的jsfiddle:https ://jsfiddle.net/El_Matella/fb15mq68/
非常感谢你的帮助 :)
您可以使用white-space
属性防止文字换行:
white-space: nowrap
与一样折叠空白
normal
,但抑制文本内的换行符(换行)。
white-space: pre
保留空白序列,仅在源和
<br>
元素中的换行符处折行。
可能,您想要第一个。
.box {
white-space: nowrap;
}
.container {
background: pink;
width: 100px;
height: 100px;
margin: auto;
position: relative;
}
.box {
position: absolute;
right: 0;
background: green;
top: 100%;
white-space: nowrap;
}
<div class="container">
<div class="box">
This is the text I want to display inline
</div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句