如何在Bootstrap 4中使用响应式图像?

时间:2018-08-09 10:05:08

标签: bootstrap-4

我在引导程序4中使用了固定的顶部标题。当转到移动视图时,导航图像显示大。 这是我的代码。

  <a class="nav-link"  data-toggle="dropdown" href="#profile">
     <img class="card-img-top rounded-circle float-left" src="img/photo300x300.jpg" alt="Card image" width="25" height="25" >
  </a>

请帮助 如何在移动视图中显示较小的图像?

1 个答案:

答案 0 :(得分:0)

您可以在Image上使用“ img-fluid”类,并在包装​​上指定宽度。图片将根据容器宽度调整大小。

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />



<nav class="navbar navbar-dark bg-dark">
  <a class="nav-link" data-toggle="dropdown" href="#profile" style="width:10%;">
    <img class="img-fluid rounded-circle float-left img-fluid" src="https://s.ndtvimg.com/images/entities/300/india-6.png" alt="Card image">
  </a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample01" aria-controls="navbarsExample01" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

  <div class="collapse navbar-collapse" id="navbarsExample01">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="https://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
        <div class="dropdown-menu" aria-labelledby="dropdown01">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
    </ul>
    <form class="form-inline my-2 my-md-0">
      <input class="form-control" type="text" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>
sudo apt-get install g++-multilib