加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

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

发布时间:2020-12-14 19:38:44 所属栏目:资源 来源:网络整理
导读:参见英文答案 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用于垂直居中两行文本.两行文字相距太远.这是我正在谈论的图像:
参见英文答案 > 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读