Html 自动调整具有固定高度的div的宽度';内容
通常,当文本内容大于其容器时,会沿Y方向/垂直方向溢出:Html 自动调整具有固定高度的div的宽度';内容,html,css,overflow,flexbox,fluid-layout,Html,Css,Overflow,Flexbox,Fluid Layout,通常,当文本内容大于其容器时,会沿Y方向/垂直方向溢出: ----------------------- |Hello hello hello hel| |lo hello hello hello | |hello hello hello hel| ----------------------- lo hello hello hello hello hello 但是,在这种情况下,我希望它在X方向/水平方向上自动溢出,同时保留并填充div的固定高度。(宽度应相应调整,它可以显示水平滚动条
-----------------------
|Hello hello hello hel|
|lo hello hello hello |
|hello hello hello hel|
-----------------------
lo hello hello hello
hello hello
但是,在这种情况下,我希望它在X方向/水平方向上自动溢出,同时保留并填充div的固定高度。(宽度应相应调整,它可以显示水平滚动条,也可以只是水平溢出容器。)
CSS(3)/flexbox/overflow/text wrapping是否可以实现这一点?或者,如果没有,请使用JavaScript?您可以使用CSS overflow-x:visible/scroll尝试一下,看看是否适合您:
jQuery(document).ready(function($) {
$(".container p").each(function() {
var pwidth = $(this).width();
$(this).width(pwidth)
}),
$('.container').css({"width" : "300px" })
});
试试这个。当其父元素宽度设置为auto(注意初始css值)时,此脚本将获得最长的段落宽度。完成后,将容器设置为300px(或最终希望的任何值)
不利的一面是,它没有单独获得每个p宽度,而只获得最长的一个
在我的脑海中,你不能用宽度为150%的文本容器来实现吗?问题是文本的数量是可变的,所以用150%左右的固定值是不够的。你想限制文本吗?比如说受身体宽度的限制?或者你想让它无限期地继续下去,只要它“持续”?它就像空白:nowrap,但是它应该根据div的高度进行包装,正如我在上面试图说明的那样
jQuery(document).ready(function($) {
$(".container p").each(function() {
var pwidth = $(this).width();
$(this).width(pwidth)
}),
$('.container').css({"width" : "300px" })
});