中心文本和圆圈内的容器

时间:2014-11-05 10:25:26

标签: html css twitter-bootstrap-3

我在这里有一个Bootply:http://www.bootply.com/XLGE6Vpjov

我需要在容器中居中的3个圆圈,然后我需要里面的文字水平和垂直居中。

如何将文本垂直居中?

我知道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;
        }

4 个答案:

答案 0 :(得分:16)

您可以尝试使用此类http://jsfiddle.net/6cygbd37/1/

见下面的工作示例:

&#13;
&#13;
/*--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;
}
&#13;
<!--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>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

你的回答是......

.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>

答案 2 :(得分:1)

一个解决方案可以是line-height:200px;类添加.circle因此,线条高度与圆圈本身的高度相同。

.circle {
  /* your code */
  line-height:200px;
}

答案 3 :(得分:1)

您可以使用display: table-cell代替inline-block

实施例

.circle {
  display: table-cell;
}