引导程序:调整页面大小时,标头中的第二个col-2优先于第一个col-2

时间:2019-04-06 12:37:42

标签: css bootstrap-4

使用简单的Bootstrap 4.0网格具有以下代码。 Codepen

  <!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <style>
    body {
            background-repeat: no-repeat;
            background-position: center center;
            background-size: cover;
            background-attachment: fixed;
            background-color: #005267;
            min-height: 700px;
            height: auto;
            min-height: 100%;
            overflow-y: scroll;
            padding-bottom: 20px;
            font-family:  Arial, Geneva, Helvetica, sans-serif;
        }
    .vertical-align {
        display: flex;
        align-items: center;
        }
    .hr_news {
        font-weight:bold;
        }
    /*2 kill*/
    .header_bg {
        background-color:red; 
        height:90px; 
        vertical-align: middle; 
    }
    .brd_black {border:0px solid #000;}
    </style>
  <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <title>Новости обучения и развития</title>
  </head>
  <body>
   <div class="container-fluid">
     <div class="row">
      <div class="brd_black align-self-center bg-white vertical-align col-2" style="height:90px;"><a href="#"><img src="http://igorisaev.com/logo.png" class="float-left"></a>
      </div>
      <div class="brd_black col-2 bg-white">&nbsp;</div>
        <div class="brd_black col-8 bg-white vertical-align">
            <h4>Новости обучения и развития</h4></div>
        </div>
   </div>
</div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>

当我向图像添加超链接并开始调整页面大小时,空的col-2 cloumn会越过图像的第一列。如果我删除超链接,一切正常。为什么会发生这种情况,我该如何解决?

1 个答案:

答案 0 :(得分:1)

在下面,您可以找到3种情况:

  • 作为您随附的代码笔中的代码
  • 如果您从徽标周围删除<a>
  • 如果您使用col-4

第3个选项应该对您有用,如果没有,请与您分享所需的内容

.vertical-align {
  display: flex;
  align-items: center;
}
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="container-fluid">

  <br/>
  <br/>
  <br/>

  <div class="row">
    <div class="brd_black align-self-center bg-white vertical-align col-2" style="height:90px;">
      <a href="#"><img src="https://www.akberiqbal.com/apple-touch-icon-144x144.png" class="float-left"></a>
    </div>
    <div class="brd_black col-2 bg-white">&nbsp;</div>
    <div class="brd_black col-8 bg-white vertical-align">
      <h4>THIS IS YOUR CODE</h4>
    </div>
  </div>

  <br/>
  <br/>
  <br/>

  <div class="row">
    <div class="brd_black align-self-center bg-white vertical-align col-2" style="height:90px;">
      <img src="https://www.akberiqbal.com/apple-touch-icon-144x144.png" class="float-left">
    </div>
    <div class="brd_black col-2 bg-white">&nbsp;</div>
    <div class="brd_black col-8 bg-white vertical-align">
      <h4>this is when you remove <a> from around the logo</h4>
    </div>
  </div>


<br/>
<br/>
<br/>

  <div class="row">
    <div class="brd_black align-self-center bg-white vertical-align col-4" style="height:90px;">
      <a href="#"><img src="https://www.akberiqbal.com/apple-touch-icon-144x144.png" class="float-left"></a>
    </div>
    <div class="brd_black col-8 bg-white vertical-align">
      <h4>this is when you have col-4 instead of empty col-2</h4>
    </div>
  </div>

</div>