html - 如何使用 css 在圆形 div 中垂直居中我的文本

标签 html css geometry

我想知道我在我的 css 中忽略了什么,这会阻止文本正确地垂直居中?下面是我当前的代码,and here is a fiddle .

这是我的html

<div class="donateButton"><a href="#">Donate</a></div>

这是我的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;
}

提前感谢您的任何见解。

我也想最终做出响应,但我想那将是另一个问题:)

最佳答案

如果您确定文本只有一行,您可以这样做:

.donateButton a {
    display:block;
    width:100%;
    color:#FFFFFF;
    font-size:1em;
    text-decoration:none;
    line-height:100px;
}

关于html - 如何使用 css 在圆形 div 中垂直居中我的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29813110/

相关文章:

css - Bootstrap Carousel Firefox 定位

java - 如何使用 JavaFX、JCSG 和 FXyz 进行差分运算后获得闭合的 3D 网格?

geometry - 如何计算任意三角形与正方形的相交面积?

html - 来自 wordpress 的 CSS 没有改变

html - 在 HTML5 中跨页面加载存储本地音频文件数据

css - Internet Explorer 中的透明背景

algorithm - 盒子背面剔除

html - CSS:2 面 3D 翻转重叠/出血

php - 将 SQL 数据库查询结果显示为链接

android - Monospace CSS 在 Android 版 Chrome 中不起作用