【问题标题】:How make the middle sharp match the text line. The text is not in the sharp [duplicate]如何使中间的锐利匹配文本行。文字不在尖锐[重复]
【发布时间】:2018-05-22 03:05:48
【问题描述】:

编辑:还有其他帖子回答了我的帖子,但我让我的帖子在线发布,因为有些人不知道这是关于“flexbox 中的垂直对齐”技巧。我的主题允许与它建立链接。

我尝试使我的锐利匹配文本的中间部分。

我尝试过 flexbox 甚至网格,但不知道出了什么问题。

我想做什么:

这是我的 Jsfiddle,如果有人有任何想法:

http://jsfiddle.net/rkEMR/10617/

div{ 
display: flex;
  align-items: center;

} #record {
   grid-area: text;
   border: solid;
   border-color: #656666;
   border-width: 1px;
   margin-left: 3.8em;
   margin-top: 0.3em;
   width: 10rem;
   height: 3rem;
   background-color: white;
   font-family: 'Tajawal', sans-serif;
   font-size: 1.5em;
   text-align: center; 
 }

 #circle {
   display: inline-block;
   grid-area: symbol;
   margin: 0;
   padding: 0;
   background: red;
   width: 25px;
   height: 25px;
   text-align: center;
   -webkit-border-radius: 50px;
   -moz-border-radius: 50px;
   border-radius: 50px;
  /* padding-top: 5px;
   line-height:  5em;*/
 }
<div> <button id="record"> Record <div id="circle"> </div></button>
</div>

【问题讨论】:

    标签: css flexbox vertical-alignment


    【解决方案1】:

    您的 flex 属性在错误的位置。您需要将它们应用于要居中的元素的直接父级,即#record

    如果你申请:

    #record {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    

    按钮的内容将居中。

    #record {
       grid-area: text;
       border: solid;
       border-color: #656666;
       border-width: 1px;
       margin-left: 3.8em;
       margin-top: 0.3em;
       width: 10rem;
       height: 3rem;
       background-color: white;
       font-family: 'Tajawal', sans-serif;
       font-size: 1.5em;
       text-align: center;
       display: flex;
       justify-content: center;
       align-items: center;
     }
    
     #circle {
       display: inline-block;
       grid-area: symbol;
       margin: 0;
       margin-left: 10px;
       padding: 0;
       background: red;
       width: 25px;
       height: 25px;
       text-align: center;
       -webkit-border-radius: 50px;
       -moz-border-radius: 50px;
       border-radius: 50px;
      /* padding-top: 5px;
       line-height:  5em;*/
     }
    <div> <button id="record"> Record <div id="circle"> </div></button>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 2012-10-27
      相关资源
      最近更新 更多