请告诉我怎么把我的按钮移到页面的中心。因为现在它在右边的角落里,我试了很多次来移动它。
<style>
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 13px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 17px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
font-weight: bold;
}
.button1:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
</style>
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>发布于 2018-05-12 05:40:01
水平对齐时,需要把css放在包含div的地方,来控制子元素……
.container {
display: block;
margin: 0 auto;
text-align: center;
}
<div class="container">
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
</div>如果要使元素垂直居中,请使用...
button {
position: relative;
top: 50%;
transform: translateY(-50%);
}发布于 2018-05-12 06:03:39
或者你也可以使用flexbox,这是一种快速将元素水平和垂直居中的强大方法。
你只需要把你的按钮放在一个容器里,对它应用flexbox,然后margin: auto;就会完成剩下的事情。
.container {
display: flex;
}
.button {
margin: auto;
}<div class="container">
<button class="button button1" type="button" onclick="history.back()" value="חזור וחשב מחדש">חשב מחדש</button>
</div>
https://stackoverflow.com/questions/50300556
复制相似问题