我在寻找的东西,如:CSS调整格宽度文本内容宽度可达X像素
width: (200px or content width)
任何想法?
[编辑] Added显示该问题的小提琴:http://jsfiddle.net/9fhtsgfd/
我在寻找的东西,如:CSS调整格宽度文本内容宽度可达X像素
width: (200px or content width)
任何想法?
[编辑] Added显示该问题的小提琴:http://jsfiddle.net/9fhtsgfd/
<div>
默认为display: block
,这意味着它将占用全角。如果您希望它只占用其内容的空间,则可以尝试使用inline-block
。
然后,如果您只希望<div>
将拉伸至 X像素,则可以使用max-width
。
div {
display: inline-block;
max-width: 200px;
background-color: blue; /* for illustration only */
}
<div>short content</div>
<div>longer content here longer content here longer content here longer content here longer content here longer content here longer content here </div>
正如你所知道的,这也把旁边的海誓山盟的div。
听起来像是你正在寻找的CSS属性最小宽度
min-width:200px;
width:auto;
对不起,也许我读问题不对。
max-width:200px;
display:inline-block; //xec is correct inline-block instead of display block lets it adjust from 0-max-width. I was missing that piece until he posted his answer. His is correct.
这将采取文本并将其包装在200px宽,但容器将从0 px扩展到200px。如果它不以这种方式行事,那么你可能有其他的CSS造成问题。
听起来像某种有条件的需要?例如:http://www.conditional-css.com/usage(右侧?) – jbutler483 2014-09-19 15:46:47