如何在锚标签内居中放置多个图像

时间:2019-02-25 12:55:32

标签: css3 bootstrap-4

我希望图像居中,但是无法在mediumlargeextra-large屏幕上显示图像

 <nav class="navbar">
    <div class="row">
        <div class="col-12 d-flex justify-content-center">
            <a href="/html"><img src="./images/devices.png" alt="devices"></a>
            <a href="/html"><img src="./images/media.png" alt="media"></a>
            <a href="/html"><img src="./images/logo.png" alt="logo"></a>
            <a href="/html"><img src="./images/stream.png" alt="stream"></a>
            <a href="/html"><img src="./images/logout.png" alt="logout"></a>
        </div>
    </div>
</nav>

我尝试了stackoverflow网站上提供的其他解决方案,但没有一个有效。请帮忙,我是新手

1 个答案:

答案 0 :(得分:-2)

我不太了解您需要什么,但是我想您可以参考以下两页:

通常,导航是带有多个链接或下拉菜单的栏。所以我看不出这有什么道理。

这里有两个示例,其中一个是水平排列的.nav类。 其中一个是我垂直排列的.navbar类。

项目的内容居中。

希望这会有所帮助。

.navbar, .nav {
background-color: #A4A4A4;
border: 1px solid red;
}

/* for the purpose of demonstration, I added borders to the Nav-ul */
#top-menu {
border: 1px solid red;
}

.nav-link {
width: 100px;
text-align: center;
/* for the purpose of demonstration, I added borders to the list items */
border: 1px solid black;
}

.dont_copy_this {height: 50px;}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>

<nav class="nav">
    <div class="row">
        <div class="col-12 d-flex justify-content-center">
            <a class="nav-link" href="/html"><img src="./images/devices.png" alt="devices"></a>
            <a class="nav-link" href="/html"><img src="./images/media.png" alt="media"></a>
            <a class="nav-link" href="/html"><img src="./images/logo.png" alt="logo"></a>
            <a class="nav-link" href="/html"><img src="./images/stream.png" alt="stream"></a>
            <a class="nav-link" href="/html"><img src="./images/logout.png" alt="logout"></a>
        </div>
    </div>
</nav>

<div class="dont_copy_this"></div>

<nav class="navbar">
  <ul id="top-menu" class="navbar-nav">
    <li class="nav-item"><a class="nav-link" href="/html"><img src="./images/devices.png" alt="devices"></a></li>
    <li class="nav-item"><a class="nav-link" href="/html"><img src="./images/media.png" alt="media"></a></li>
    <li class="nav-item"><a class="nav-link" href="/html"><img src="./images/logo.png" alt="logo"></a></li>
    <li class="nav-item"><a class="nav-link" href="/html"><img src="./images/stream.png" alt="stream"></a></li>
    <li class="nav-item"><a class="nav-link" href="/html"><img src="./images/logout.png" alt="logout"></a></li>
  </ul>
</nav>