当前位置:  开发笔记 > 前端 > 正文

如何在中间(垂直)对齐文本

如何解决《如何在中间(垂直)对齐文本》经验,为你挑选了1个好方法。

我现在正在努力这么多个小时,但我仍然无法找到解决方案.我做了这个漂亮的网格,可以调整文本长度和浏览器调整.现在的问题是我无法将文本放在框中间.

我已经尝试了一切..我使用了几个属性来实现这一点,但没有任何效果.

text-align: center;
vertical-align: middle;
line-height: "same as div";

css代码:

.parent {
  text-align:center;
  margin:0px;
  width:100%;
  padding:0px;
  font-size:18px;
  color:#000;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  -ms-flex-pack: justify;
      justify-content: space-between;
}

.child {
  padding:18px 25px;
  background: rgba(0, 0, 0, .5);
  list-style-type:none;
  width:inherit;
  margin:5px;

}

小智.. 5

这是你想要的吗?

.parent {
    text-align:center;
    margin:0px;
    width:100%;
    padding:0px;
    font-size:18px;
    color:#000;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    vertical-align: middle;
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    -ms-flex-pack: justify;
    justify-content: space-between;

}

.child {
    position: relative;
    background: rgba(0, 0, 0, .5);
    padding:10px;
    list-style-type:none;
    width:inherit;
    align-items: center;
    justify-content: center;
    height:inherit;
    display: inline-flex;
    vertical-align: middle;
    margin:5px;
}



    
    
    


sometext
somemoretext somemoretext
sometext
sometext
somemoretext somemoretext somemoretext somemoretext
sometext

这是通过flex作为你的jsfiddle来完成的.你可以通过"父显示表和垂直对齐中间"和"子显示表格单元格和面板中间"删除你的flex样式更容易.



1> 小智..:

这是你想要的吗?

.parent {
    text-align:center;
    margin:0px;
    width:100%;
    padding:0px;
    font-size:18px;
    color:#000;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    vertical-align: middle;
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    -ms-flex-pack: justify;
    justify-content: space-between;

}

.child {
    position: relative;
    background: rgba(0, 0, 0, .5);
    padding:10px;
    list-style-type:none;
    width:inherit;
    align-items: center;
    justify-content: center;
    height:inherit;
    display: inline-flex;
    vertical-align: middle;
    margin:5px;
}



    
    
    


sometext
somemoretext somemoretext
sometext
sometext
somemoretext somemoretext somemoretext somemoretext
sometext
推荐阅读
手机用户2502852037
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有