我認爲在已知的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>
你希望它僅水平水平和垂直居中或? –