我认为在已知的width
元素上添加margin
的auto
会使元素居中,因为两边的边距将变得相等。但是,我不确定我要出错的地方:如何将此按钮置于页面上?为什么按钮不居中?
p {
font-family: helvetica, sans-serif;
font-size: 18px;
}
button {
background-color: lightblue;
color: white;
padding: 15px 32px;
border-radius: 4px;
border: 5px solid lightblue;
}
.upload-button {
width: 300px;
margin: 10px auto;
}
button:hover {
background: white;
border: 5px solid lightblue;
color: lightblue;
}
html, body {
height: 100%;
}
body {
width: 960px;
margin: auto;
}
<button id="upload-button" class="upload-button" type="button">why is this button not centered</button>
你希望它仅水平水平和垂直居中或? –