Div内部的UL垂直居中| Bootstrap 3.3.7

时间:2017-01-25 23:07:54

标签: css html5 twitter-bootstrap html-lists

我是StackOverflow(以及HTML5 / CSS)的新手,这是我的第一篇文章。 (我不会说英语很好)

我试图在div中创建导航栏,但我无法垂直居中。我试过了:

  • vertical-align:middle;
  • 更改内容div的高度并使UL居中
  • "发挥"具有显示属性
  • 阅读我在互联网上找到的所有帖子,但我无法弄明白。

    .article {   边框:1px固体;   border-color:rgba(210,246,1,1); }



<div class="row article">
  <div class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
    <ul class="nav nav-pills nav-stacked">
      <li>
        <a href="#">
          <img src="{% static 'imagenes/logo.png' %}" alt="Stia" class="logopeque">Convenio Vigente
        </a>
      </li>
      <li>
        <a href="#">
          <img src="{% static 'imagenes/logo.png' %}" alt="Stia" class="logopeque">Escala Salarial vigente
        </a>
      </li>
      <li>
        <a href="#">
          <img src="{% static 'imagenes/logo.png' %}" alt="Stia" class="logopeque">Escalas Salariales Anteriores
        </a>
      </li>
    </ul>
  </div>
  <div class="col-xs-12 col-sm-8 col-md-9 col-lg-9">
    <section>
      <p class="centrarp">
        <h3>Convenio 244/94</h3>
        <h5 class="justificar">TRABAJADORES COMPRENDIDOS - ENUNCIACION DE ACTIVIDADES</h5>
        <p class="justificar centrarp">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
          irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur
          adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
          velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </section>
  </div>
</div>
&#13;
&#13;
&#13;

this is the result

1 个答案:

答案 0 :(得分:0)

因为您不希望在您网站的每个.row.article上使用此功能,所以我添加了一个自定义类:.vCenter

@media(min-width: 768px) {
  .row.article.vCenter {
    display: flex;
  }
  .row.article.vCenter>.col-lg-3 .nav-pills {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row article vCenter">
  <div class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
    <ul class="nav nav-pills nav-stacked">
      <li>
        <a href="#">
          <img src="{% static 'imagenes/logo.png' %}" alt="Stia" class="logopeque">Convenio Vigente
        </a>
      </li>
      <li>
        <a href="#">
          <img src="{% static 'imagenes/logo.png' %}" alt="Stia" class="logopeque">Escala Salarial vigente
        </a>
      </li>
      <li>
        <a href="#">
          <img src="{% static 'imagenes/logo.png' %}" alt="Stia" class="logopeque">Escalas Salariales Anteriores
        </a>
      </li>
    </ul>
  </div>
  <div class="col-xs-12 col-sm-8 col-md-9 col-lg-9">
    <section>
      <p class="centrarp">
        <h3>Convenio 244/94</h3>
        <h5 class="justificar">TRABAJADORES COMPRENDIDOS - ENUNCIACION DE ACTIVIDADES</h5>
        <p class="justificar centrarp">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
          irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur
          adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
          velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </section>
  </div>
</div>

如果您希望它们更“间隔”,则可以space-around而不是space-between而不是center来尝试justify-content

在部署之前,不要忘记通过Autoprefixer解析最终的CSS。