我觉得这很明显,但我似乎无法在这里找到任何答案。
我试图制作5个圆形div,内联,中间有一个代表成绩的字母。然后,我希望主题标题低于成绩(但仍在圈内)。
这是我到目前为止所写的内容:
HTML:
<div class="subject">A</div>
<div class="subject">B</div>
<div class="subject">C</div>
<div class="subject">D</div>
<div class="subject">E</div>
CSS:
.subject {
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;
另外,我似乎无法使用以下方式将圆圈水平居中:
margin: 0 auto;
或
margin-left: auto;
margin-right: auto;
.subject {
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;
}
&#13;
<div class="subject">A</div>
<div class="subject">B</div>
<div class="subject">C</div>
<div class="subject">D</div>
<div class="subject">E</div>
&#13;
感谢任何建议,谢谢!
答案 0 :(得分:2)
您可以执行以下操作,我创建了另一个div并添加了text-align:center
属性。现在这些圆圈水平居中。
.subject {
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;}
.circle{
text-align:center;
}
&#13;
<div class="circle">
<div class="subject">A</div>
<div class="subject">B</div>
<div class="subject">C</div>
<div class="subject">D</div>
<div class="subject">E</div></div>
&#13;
答案 1 :(得分:2)
将div
包裹在容器中并向其添加text-align: center
。
使用伪元素:after
插入字幕。请查看以下示例
.container {
text-align: center;
}
.subject {
border-radius: 100%;
display: inline-block;
background-color: gray;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
font-family: Arial;
border-radius: 100%;
color: white;
font-size: 100px;
position: relative;
}
.subject:after {
display: inline-block;
position: absolute;
font-size: 16px;
content: attr(data-sub);
left: 50%;
transform: translateX(-50%);
top: 30%;
}
<div class="container">
<div class="subject" data-sub="Maths">A</div>
<div class="subject" data-sub="French">B</div>
<div class="subject" data-sub="Biology">C</div>
<div class="subject" data-sub="German">D</div>
<div class="subject" data-sub="Chemistry">E</div>
</div>