使div不自动拉伸到容器宽度 [英] Make div NOT auto stretch to container width

查看:390
本文介绍了使div不自动拉伸到容器宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:

您可以阻止div从自动伸展到其包含元素的宽度,并且只能沿水平方向伸展多达内容里面它的力量?



有点像div的默认垂直行为,但水平应用。这可能吗?

解决方案

您必须设置显示 property inline-block

 < div style =display:内联块>文字< / DIV> 


My question is simple:

Can you stop a div from auto-stretching to the width of its containing element and have it only stretch horizontally as much as the content inside it forces?

Kind of like the default vertical behavior of divs but applied horizontally. Is this possible?

解决方案

You'd have to set the display property to inline-block

<div style="display: inline-block">Text</div>

这篇关于使div不自动拉伸到容器宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆