[英]How to center my text vertically in a circular div with css
I am wondering what I am neglecting in my css, which is preventing the text from being properly centered vertically? 我想知道我在CSS中忽略了什么,这阻止了文本在垂直方向上正确居中? Below is my current code, and here is a fiddle .
下面是我当前的代码, 这是一个小提琴 。
Here is my html 这是我的html
<div class="donateButton"><a href="#">Donate</a></div>
This is my CSS 这是我的CSS
.donateButton {
width:100px;
height:100px;
background-color:#FE6D4C;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
margin:0 auto 30px;
text-align:center;
}
.donateButton:hover {
background-color:#09C;
}
.donateButton a {
display:block;
width:100%;
color:#FFFFFF;
font-size:1em;
text-decoration:none;
padding-top:50%;
line-height:1em;
margin-top:0.5em;
}
Thanks in advance for any insight. 预先感谢您的任何见解。
I also want to make this responsive eventually, but i guess that will be another question :) 我也想最终做出响应,但是我想那将是另一个问题:)
If you're sure that the text will be just one line you can do this: 如果您确定文本只是一行,则可以执行以下操作:
.donateButton a {
display:block;
width:100%;
color:#FFFFFF;
font-size:1em;
text-decoration:none;
line-height:100px;
}
最简单的方法是从文本中删除padding-top,并将行高设置为100px,与div相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.