Flex:水平超越屏幕

时间:2016-12-07 04:52:41

标签: css flexbox

一切都很好,但是如果屏幕较小,我希望它在中心对齐,它会居中对齐,但屏幕外还会出现一个空格。

代码:



//provide only one character String that you want to check and remove
if (value.matches(".*[' - ?]$")){
        value = value.substring(0, value.length()-1);
}

//provide two character String that you want to check and remove
if (value.matches(".*[-- ly ab cd ef]$")){
        value = value.substring(0, value.length()-2);
}

//provide three character String that you want to check and remove
if (value.matches(".*[-- lyy abc def ghi]$")){
        value = value.substring(0, value.length()-3);
}

//provide four character String that you want to check and remove
if (value.matches(".*[-- lyyy abcd efgh ijkl]$")){
        value = value.substring(0, value.length()-4);
}

.example {
  line-height: 30px;
  background-color: #363636;
  color: #ffffff;
  height: 353px;
  padding: 26px 0 0 0;
}
.example-links {
  width: 960px;
  margin: 0 auto;
  font-size: 12px;
  display: -webkit-flex;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
  justify-content: flex-start;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
}
.example-1 {
  height: 55px;
  margin-left: 3px;
  padding: 0 69px 0 0;
  position: relative;
}
.example-2 {
  text-transform: uppercase;
  -moz-column-count: 2;
  -webkit-column-count: 2;
  column-count: 2;
  -moz-column-gap: 52px;
  -webkit-column-gap: 52px;
  column-gap: 52px;
  padding: 0 20px 0 0;
  margin: 0 0 0 44px;
  position: relative;
}
.example-networks {
  -moz-column-count: 2;
  -webkit-column-count: 2;
  column-count: 2;
  margin-left: 74px;
  -moz-column-gap: 52px;
  -webkit-column-gap: 52px;
  column-gap: 83px;
}
@media only screen and (max-width: 960px) {
  .example-links {
    -webkit-flex-direction: column-reverse;
    flex-direction: column-reverse;
    -webkit-align-items: center;
    align-items: center;
    justify-content: space-between;
    align-content: center;
    flex-wrap: wrap;
    margin-bottom: 30px;
  }
  .example-1 {
    height: auto;
    margin: 0;
    padding: 0;
    position: relative;
    margin-bottom: 30px;
  }
  .example-2 {
    text-transform: uppercase;
    -moz-column-count: 2;
    -webkit-column-count: 2;
    column-count: 2;
    -moz-column-gap: 52px;
    -webkit-column-gap: 52px;
    column-gap: 52px;
    padding: 0;
    margin: 0;
    position: relative;
    margin-bottom: 30px;
  }
  .example-3 {
    margin-bottom: 30px;
    text-transform: uppercase;
    -moz-column-count: 2;
    -webkit-column-count: 2;
    column-count: 2;
    margin-left: 0;
    -moz-column-gap: 52px;
    -webkit-column-gap: 52px;
    column-gap: 83px;
  }
}




https://jsfiddle.net/Eisenhansel/gmnff17y/

1 个答案:

答案 0 :(得分:1)

它工作正常。只需修改使用.example-links而不是max-width的类width css,如下所示:

.example-links {
  max-width: 960px;
  width:100%;
}



.example {
  line-height: 30px;
  background-color: #363636;
  color: #ffffff;
  height: 353px;
  padding: 26px 0 0 0;
}
.example-links {
  max-width: 960px;
  width:100%;
  margin: 0 auto;
  font-size: 12px;
  display: -webkit-flex;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
  justify-content: flex-start;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
}
.example-1 {
  height: 55px;
  margin-left: 3px;
  padding: 0 69px 0 0;
  position: relative;
}
.example-2 {
  text-transform: uppercase;
  -moz-column-count: 2;
  -webkit-column-count: 2;
  column-count: 2;
  -moz-column-gap: 52px;
  -webkit-column-gap: 52px;
  column-gap: 52px;
  padding: 0 20px 0 0;
  margin: 0 0 0 44px;
  position: relative;
}
.example-networks {
  -moz-column-count: 2;
  -webkit-column-count: 2;
  column-count: 2;
  margin-left: 74px;
  -moz-column-gap: 52px;
  -webkit-column-gap: 52px;
  column-gap: 83px;
}
@media only screen and (max-width: 960px) {
  .example-links {
    -webkit-flex-direction: column-reverse;
    flex-direction: column-reverse;
    -webkit-align-items: center;
    align-items: center;
    justify-content: space-between;
    align-content: center;
    flex-wrap: wrap;
    margin-bottom: 30px;
  }
  .example-1 {
    height: auto;
    margin: 0;
    padding: 0;
    position: relative;
    margin-bottom: 30px;
  }
  .example-2 {
    text-transform: uppercase;
    -moz-column-count: 2;
    -webkit-column-count: 2;
    column-count: 2;
    -moz-column-gap: 52px;
    -webkit-column-gap: 52px;
    column-gap: 52px;
    padding: 0;
    margin: 0;
    position: relative;
    margin-bottom: 30px;
  }
  .example-3 {
    margin-bottom: 30px;
    text-transform: uppercase;
    -moz-column-count: 2;
    -webkit-column-count: 2;
    column-count: 2;
    margin-left: 0;
    -moz-column-gap: 52px;
    -webkit-column-gap: 52px;
    column-gap: 83px;
  }
}

<footer class="example">
  <section class="example-links">
    <ul class="example-1">
      <li>Lorem Ipsum</li>
      <li>Lorem Ipsum</li>
    </ul>
    <ul class="example-2">
      <li>Lorem Ipsum</li>
      <li>Lorem Ipsum</li>
      <li>Lorem Ipsum</li>
      <li>Lorem Ipsum</li>
    </ul>
    <ul class="example-3">
      <li>Lorem Ipsum</li>
      <li>Lorem Ipsum</li>
      <li>Lorem Ipsum</li>
      <li>Lorem Ipsum</li>
    </ul>
  </section>
</footer>
&#13;
&#13;
&#13;