使用 HTML 和 CSS 将文本和选择框对齐到相同的宽度
当我们在 CSS 中设置某个元素的 宽度 和 高度 时,该元素通常显示得比实际尺寸大。这是因为,默认情况下,会将 内边距 和 边框 添加到元素的宽度和高度中,然后显示该元素。
盒尺寸属性 会将元素的内边距和边框包括在实际宽度和高度中,从而使元素不会显示得比实际尺寸更大。使用此属性的格式为 box-sizing:box-border
示例
你可以尝试运行以下代码以将文本和选择框对齐到相同的宽度 −
<html>
<head>
<style>
input, select {
width: 250px;
border: 2px solid #000;
padding: 0;
margin: 0;
height: 22px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
input {
text-indent: 3px;
}
</style>
</head>
<body>
<input type = "text" value = "Name of Candidate"><br>
<select>
<option>Select Choice</option>
<option>Student</option>
<option>Teachers</option>
<option>Head</option>
</select>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP