您好,我的代码有问题。我希望文本在所有设备上居中。但它似乎在框的右侧?例如,尝试使窗口变小,您会看到文本向右移动,而不是一直居中。
我做错了什么?
#box1 {
background-color: rgba(55,190,239,0.6);
color: #FFFFFF;
padding: 105px;
text-align: center;
font-size: 3.1vh;
font-weight: bold;
/*Gradient*/
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
/*Transition*/
-webkit-transition: All 0.5s ease;
-moz-transition: All 0.5s ease;
-o-transition: All 0.5s ease;
-ms-transition: All 0.5s ease;
transition: All 0.5s ease;
}
#box1:hover {
background-color: rgba(55,190,239,0.9);
}
<a href="/fastigheter/"><div id="box1">FASTIGHETER</div></a>
fiddle :https://jsfiddle.net/fg7xe9s9/
最佳答案
您需要退出左右填充:fiddle
#box1 {
background-color: rgba(55,190,239,0.6);
color: #FFFFFF;
padding-top: 105px;
padding-bottom: 105px;
text-align: center;
font-size: 3.1vh;
font-weight: bold;
/*Gradient*/
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
/*Transition*/
-webkit-transition: All 0.5s ease;
-moz-transition: All 0.5s ease;
-o-transition: All 0.5s ease;
-ms-transition: All 0.5s ease;
transition: All 0.5s ease;
}
#box1:hover {
background-color: rgba(55,190,239,0.9);
}
关于javascript - CSS 不在框中居中文本,而是移到右侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29926382/