【问题标题】:Center text and container inside a circle将文本和容器居中在一个圆圈内
【发布时间】:2018-08-19 22:17:21
【问题描述】:

我在这里有一个 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;
        }

【问题讨论】:

    标签: html css twitter-bootstrap-3


    【解决方案1】:

    你可以试试这样http://jsfiddle.net/6cygbd37/1/

    请参阅下面的工作示例:

    /*--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>

    【讨论】:

    • 这个解决方案对我所需要的最友好。谢谢!
    • 是的,最好的解决方案
    【解决方案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>

    【讨论】:

      【解决方案3】:

      一种解决方案可以将line-height:200px; 添加到您的.circle 类中,这样行Height 将与圆本身的高度相同。

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

      【讨论】:

        【解决方案4】:

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

        例子

        .circle {
          display: table-cell;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-02-02
          • 2018-07-12
          • 2015-03-15
          • 1970-01-01
          • 2016-07-01
          • 2016-04-19
          • 2020-06-06
          相关资源
          最近更新 更多