Html 将文本和容器置于圆圈内
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26754787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Center text and container inside a circle
提问by ttmt
I have a Bootply here: http://www.bootply.com/XLGE6Vpjov
我在这里有一个 Bootply:http: //www.bootply.com/XLGE6Vpjov
I need the 3 circles centered in there containers and then I need the text inside to be centered horizontally and verticaly.
我需要在那里的容器中居中的 3 个圆圈,然后我需要将里面的文本水平和垂直居中。
How can I center the text vertically?
如何使文本垂直居中?
I know the border-radius
won't work in IE8 but I don't mind it being a square there.
我知道border-radius
在 IE8 中不起作用,但我不介意它在那里是一个正方形。
<div class="container">
<div class="row">
<div class="col-md-4 block text-center">
<p class="circle">Some Text here Some text here Some text here Some text here</p>
</div>
<div class="col-md-4 block">
<p class="circle">Some Text here</p>
</div>
<div class="col-md-4 block">
<p class="circle">Some More Text here</p>
</div>
</div>
</div>
.block{
border: 1px solid red;
text-align: center;
vertical-align: middle;
}
.circle{
background: red;
border-radius: 200px;
color: white;
height: 200px;
font-weight: bold;
width: 200px;
}
回答by Bojan Petkovski
You can try something like this http://jsfiddle.net/6cygbd37/1/
你可以试试这样的http://jsfiddle.net/6cygbd37/1/
See working example below :
请参阅下面的工作示例:
/*--CSS--*/
.block {
border: 1px solid red;
text-align: center;
vertical-align: middle;
}
.circle {
background: red;
border-radius: 200px;
color: white;
height: 200px;
font-weight: bold;
width: 200px;
display: table;
margin: 20px auto;
}
.circle p {
vertical-align: middle;
display: table-cell;
}
<!--HTML-->
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<div class="container">
<div class="row">
<div class="col-md-4 block">
<div class="circle">
<p>Some Text here Some text here</p>
</div>
</div>
<div class="col-md-4 block">
<div class="circle">
<p>Some Text here</p>
</div>
</div>
<div class="col-md-4 block">
<div class="circle">
<p>Some More Text here</p>
</div>
</div>
</div>
</div>
回答by Avinash Antala
Your Answer is ...
你的答案是...
.block{
border: 1px solid red;
text-align: center;
vertical-align: middle;
}
.circle{
background: red;
border-radius: 200px;
color: white;
height: 200px;
font-weight: bold;
width: 200px;
}
.circle span{
display: table-cell;
padding-top:40%;
}
<div class="container">
<div class="row">
<div class="col-md-4 block">
<p class="circle" align="center"><span>Some Text here Some text here Some text here</span></p>
</div>
<div class="col-md-4 block">
<p class="circle" align="center"><span>Some Text here Some text here Some text here</span></p>
</div>
<div class="col-md-4 block">
<p class="circle" align="center"><span> Some text here</span></p>
</div>
</div>
</div>
回答by Raul Marrero Rodríguez
One solution could be add line-height:200px;
to your .circle
class So the line Height will be the same height as the circle itself.
可以将一种解决方案添加line-height:200px;
到您的.circle
班级中,因此线高将与圆本身的高度相同。
.circle {
/* your code */
line-height:200px;
}
回答by Colin Bacon
You can use display: table-cell
instead of inline-block
您可以使用display: table-cell
代替inline-block
Example
例子
.circle {
display: table-cell;
}