麻烦在括号

时间:2016-12-20 15:28:59

标签: html css adobe-brackets

我试图将4列放在一行中。尝试使用我想要的代码笔或类似的工作,但在adobe-bracket中不起作用,我不知道是否有错误或某些东西...... 有没有人有任何想法?

PD:在我的括号输出中,一切都在左边。



body {
  position: relative;
}
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
.container-fluid {
  width: inherit;
  height: inherit;
  margin: 0;
  padding: 0;
}
.content {
  padding: 100px 0;
}
.content-2 {
  color: violet;
  background-color: blueviolet;
}
div.img {
  margin: 5px;
  float: center;
  width: 180px;
}
div.img img {
  width: 100%;
  height: auto;
}
div.desc {
  padding: 15px;
  text-align: center;
}
.row-centered {
  text-align: center;
}
.col-centered {
  display: inline-block;
  float: none;
  margin-right: 0 auto;
  width: 90%;
}

<section class="content content-2">
  <div class="container">
    <div class="row row-centered">
      <div class="img col-md-2 col-centered">
        <img src="forest.jpg" alt="Forest">
        <div class="desc">
          <h3>CREATIVIDAD</h3> 
          <p>hhhhhhhhhhhhhhhh</p>
        </div>
      </div>
      <div class="img col-md-2 col-centered">
        <img src="forest.jpg" alt="Forest">
        <div class="desc">
          <h3>DISEÑO</h3> 
          <p>hhhhhhhhhhh</p>
        </div>
      </div>
      <div class="img col-md-2 col-centered">
        <img src="forest.jpg" alt="Forest">
        <div class="desc">
          <h3>MULTIMEDIA</h3> 
          <p>hhhhhhhhhhhhh</p>

        </div>
      </div>
      <div class="img col-md-2 col-centered">
        <img src="forest.jpg" alt="Forest">
        <div class="desc">
          <h3>WEB</h3> 
          <p>hhhhhhhhhhh</p>

        </div>
      </div>
    </div>
  </div>
</section>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

使用 CSS Flexbox 。将flexbox属性应用于.row-centered以及.col-centered

.row-centered {
  display: flex; /* Flex Container */
  flex-wrap: wrap; /* Wrap the content to next line if required */
  justify-content: center; /* Horizontally content to center */
  align-items: center;
}

.col-centered {
  display: flex; /* Flex Container */
  flex-direction: column; /* Flex Direction - Column */
  justify-content: center; /* Vertically Center Alignment */
  float: none;
  margin-right: 0 auto;
  width: 90%;
}

请看下面的这个代码段(使用全屏):

body {
  position: relative;
}
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
.container-fluid {
  width: inherit;
  height: inherit;
  margin: 0;
  padding: 0;
}
.content {
  padding: 100px 0;
}
.content-2 {
  color: violet;
  background-color: blueviolet;
}
div.img {
  margin: 5px;
  float: center;
  width: 180px;
}
div.img img {
  width: 100%;
  height: auto;
}
div.desc {
  padding: 15px;
  text-align: center;
}
.row-centered {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.col-centered {
  display: flex;
  flex-direction: column;
  justify-content: center;
  float: none;
  margin-right: 0 auto;
  width: 90%;
}
<section class="content content-2">
  <div class="container">
    <div class="row row-centered">
      <div class="img col-md-2 col-centered">
        <img src="http://placehold.it/30x30" alt="Forest">
        <div class="desc">
          <h3>CREATIVIDAD</h3> 
          <p>hhhhhhhhhhhhhhhh</p>
        </div>
      </div>
      <div class="img col-md-2 col-centered">
        <img src="http://placehold.it/30x30" alt="Forest">
        <div class="desc">
          <h3>DISEÑO</h3> 
          <p>hhhhhhhhhhh</p>
        </div>
      </div>
      <div class="img col-md-2 col-centered">
        <img src="http://placehold.it/30x30" alt="Forest">
        <div class="desc">
          <h3>MULTIMEDIA</h3> 
          <p>hhhhhhhhhhhhh</p>

        </div>
      </div>
      <div class="img col-md-2 col-centered">
        <img src="http://placehold.it/30x30" alt="Forest">
        <div class="desc">
          <h3>WEB</h3> 
          <p>hhhhhhhhhhh</p>

        </div>
      </div>
    </div>
  </div>
</section>

希望这有帮助!