【发布时间】:2017-03-09 16:16:01
【问题描述】:
我编写了一个简单的表单来测试 CSS 中的宽度。无论我为宽度设置的值如何,边框仍然具有相同的宽度。有人可以帮助我错过什么吗?
<html lang="en-US">
<meta charset="UTF-8">
<head>
<style type="text/css">
label {
width: 10em;
border-color: brown;
border-width: .25em;
border-style: double;
margin-right: .5em;
}
</style>
<title>Trying CSS </title>
</head>
<body>
<form action="#">
<fieldset >
<label> Name </label>
<input type="text"/>
<label >Contact</label>
<input type="text" />
<label >Phone</label>
<input type="text" />
<button type="button">Submit </button>
</fieldset>
</form>
</body>
</html>
【问题讨论】:
-
标签标签默认为
display: inline;,因此宽度将不起作用。您可以使用:display: inline-block;或display: block;设置它以使宽度起作用。position: absolute|fixed、float: left|right也可以让它工作,但只有在你知道需要时才使用它们。 -
请问为什么 float 也能正常工作?
标签: css