CSS:我不能将宽度设置为“自动”总是出现100% [英] CSS: I can't set width to "auto" always appear 100%
本文介绍了CSS:我不能将宽度设置为“自动”总是出现100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于某些原因
div的宽度是100%,如果我将它设置为auto,没有任何变化。尝试 display:block;
,仍然没有。
我在
index.html
< head&
< title> project x< / title>
< link rel =stylesheettype =text / csshref =style.css>
< / head>
< body>
< div class ='box'>这是一个框< / div>
< div class ='box'>这是另一个方块< / div>
< / body>
这是 style.css
.box {
border:1px solid#555;
display:block;
width:auto;
}
我喜欢破解问题,但这一个破解了我。
编辑
我想让div取字的宽度。
解决方案
使用 display:inline-block
并添加一个类
.clear {clear:两个;}
将它放置在框之间
for some reason
the width of the div is 100% and if i set it to auto, nothing changes. tried display: block;
and still nothing.
what I have in
index.html
<head>
<title>project x</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class='box'>This is a box</div>
<div class='box'>This is another box</div>
</body>
and this is the style.css
.box {
border: 1px solid #555;
display: block;
width: auto;
}
I enjoy cracking problems but this one crack me.
Edit
I want the div to take the width of the words. I don't want it to be 100%.
解决方案
use display: inline-block
and add a class
.clear { clear:both;}
place it in between the boxes
so
这篇关于CSS:我不能将宽度设置为“自动”总是出现100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文