【发布时间】:2022-11-14 23:19:24
【问题描述】:
我有一个 HTML 输入元素。我希望元素位于中心,但由于右边距不起作用,元素稍微偏右。 box-sizing: border-box; 无法解决问题。
我的代码
body {
margin: 0;
padding: 10px;
font-family: Arial, Helvetica, sans-serif;
}
* {
margin: 40px;
padding: 10px;
}
input {
border-style: solid;
border-color: #5f9341;
border-width: 2px;
width: 100%;
box-sizing: border-box;
}
<html>
<head>
<link rel="stylesheet" href="css/index.css">
<script src="js/index.js"></script>
</head>
<body>
<input type="text" id="input-el">
<button id="input-btn">SAVE INPUT</button>
</body>
</html>
【问题讨论】:
-
这回答了你的问题了吗? How can I horizontally center an element?