在网格内定位图像

时间:2018-11-27 15:22:08

标签: html css bootstrap-4

我正在尝试使标题中的标志图标更加靠近(我已附上相关部分的图片)。我已经切换了CSS值,但到目前为止没有成功。我也在使用Bootstrap。

以下是相关代码:

.flag {
    height: 25px;
    width: 25px;
    padding: 0px;
}
<nav class="navbar navbar-expand-sm navbar-light bg-light mb-3">
    <div class="container">
        <a class="navbar-brand" href="#">
            <img src="./images/logo/LOGO DARKGLOBE.png" height="100px" width="150px">
        </a>
        
        <ul class="navbar-nav align-items-center">
            <li class="nav-item">
                <a class="nav-link" href="./home.html">Home</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle active" data-toggle=dropdown href="#">Empresa</a>
                <div class="dropdown-menu">
                    <a href="#" class="dropdown-item">Quem somos</a>
                    <a href="#" class="dropdown-item">Missao & Valores</a>
                    <a href="#" class="dropdown-item">Ambiente & Sustentabilidade</a>
                    <a href="#" class="dropdown-item">Higiene, Seguranc & Saude</a>
                    <a href="#" class="dropdown-item">Emprego & Igualdade de Oportunidades</a>
                </div>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Portfolio</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Projectos em Curso</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="./contactos.html">Contacto</a>
            </li>
            <li class="nav-item">
                <div class="row">
                    <div class="col">
                        <a href="#">
                            <img class="flag" src="./images/flags/portugal-flag-button-round-icon-256.png">
                        </a>
                        
                    </div>
                    <div class="col">
                        <a href="#">
                            <img class="flag" src="./images/flags/spain-flag-button-round-icon-256.png">
                        </a>		
                    </div>
                </div>
                <div class="row">
                    <div class="col">
                        <a href="#">
                            <img class="flag" src="./images/flags/france-flag-button-round-icon-256.png">
                        </a>
                    </div>
                    <div class="col">
                        <a href="#">
                            <img class="flag" src="./images/flags/united-kingdom-flag-button-round-icon-256.png">
                        </a>
                    </div>
                </div>
            </li>
            
        </ul>
    </div>
</nav>

我猜这是一个相当简单的修复程序,但这是我第一次从头开始创建网站。我从这里到那里的阅读使我对网页设计有所了解。预先感谢!

Header

1 个答案:

答案 0 :(得分:0)

像这样使用引导程序(这是响应性的):

CSS

    .row {
      background: #f8f9fa;
      margin-top: 20px;
    }

    .col {
       border: solid 1px #6c757d;
       padding: 10px;
    }

    ul {
       list-style-type: none;
    }

    img {
       max-width: 25px;
       height: 25px;
    }

HTML

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div style="margin-top: 20px" class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">

      <li class="nav-item active">
        <a class="nav-link" href="#">Title 1<span class="sr-only">(current)</span></a>
      </li>

      <li class="nav-item">
        <a class="nav-link" href="#">Title 2</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown Title
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action 1</a>
          <a class="dropdown-item" href="#">Action 2</a>
        </div>
      </li>
      <li class="nav-item">
        <ul>
          <li>
            <img  src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4tb7Zyc_O4bp2PqOYv8sTkX8Kp8gzl4RzG-sQmDyH-kvLNs8g"/>
          </li>
          <li>
            <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4tb7Zyc_O4bp2PqOYv8sTkX8Kp8gzl4RzG-sQmDyH-kvLNs8g"/>
          </li>
        </ul> 
      </li>
      <li class="nav-item">
        <ul>
          <li>
            <img  src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4tb7Zyc_O4bp2PqOYv8sTkX8Kp8gzl4RzG-sQmDyH-kvLNs8g"/>
          </li>
          <li>
            <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4tb7Zyc_O4bp2PqOYv8sTkX8Kp8gzl4RzG-sQmDyH-kvLNs8g"/>
          </li>
        </ul> 
      </li>
    </ul>
  </div>
</nav>

http://jsfiddle.net/aq9Laaew/280260/