html – flex-wrap导致下一行有太大的差距

前端之家收集整理的这篇文章主要介绍了html – flex-wrap导致下一行有太大的差距前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Remove space (gaps) between multiple lines of flex items when they wrap1个
> How does flex-wrap work with align-self,align-items and align-content?2个
我有这个flexBox用于垂直居中两行文本.两行文字相距太远.这是我正在谈论的图像:

这是我的代码

CSS

.vertical-center {
  min-height: 100%;  /* Fallback for vh unit */
  min-height: 100vh; /* You might also want to use
                        'height' property instead.

                        Note that for percentage values of
                        'height' or 'min-height' properties,the 'height' of the parent element
                        should be specified explicitly.

                        In this case the parent of '.vertical-center'
                        is the <body> element */

  /* Make it a flex container */
  display: -webkit-Box;
  display: -moz-Box;
  display: -ms-flexBox;
  display: -webkit-flex;
  display: flex; 

  /* Align the bootstrap's container vertically */
    -webkit-Box-align : center;
  -webkit-align-items : center;
       -moz-Box-align : center;
       -ms-flex-align : center;
          align-items : center;

  /* In legacy web browsers such as Firefox 9
     we need to specify the width of the flex container */
  width: 100%;

  /* Also 'margin: 0 auto' doesn't have any effect on flex items in such web browsers
     hence the bootstrap's container won't be aligned to the center anymore.

     Therefore,we should use the following declarations to get it centered again */
         -webkit-Box-pack : center;
            -moz-Box-pack : center;
            -ms-flex-pack : center;
  -webkit-justify-content : center;
          justify-content : center;

          flex-wrap: wrap;

}

p.white,h1.white,h2.white,h3.white,h4.white,h5.white,h6.white {
    color: white;
}

.flexBox-text {
    margin: -50px,0px,-50px,0px;
}

HTML

<div class="vertical-center">
      <h1 class="text-center white flexBox-text">{{mottoText}}</h1>
      <h3 class="text-center white flexBox-text">{{mottoSubText}}</h3>
    </div>

忽略角度两种语法.如何让两行文本更接近?

解决方法

使用flex-direction:列并从h1和h3中删除边距
.vertical-center {
  display: flex;
  flex-direction: column;
  height: 100vh;
  align-items: center;
  justify-content: center;
}

p.white,h6.white {
    color: black;
    margin: 0;
}
<div class="vertical-center">
   <h1 class="text-center white flexBox-text">THIS IS TITLE</h1>
   <h3 class="text-center white flexBox-text">SUBTITLE</h3>
</div>
原文链接:https://www.f2er.com/html/223907.html

猜你在找的HTML相关文章