Bootstrap4 圖片設置

2021-10-08 09:30 更新

Bootstrap4中,我們可以使用各種類對圖片的形狀、對齊等進行設置。具體使用的類如下:


圖片形狀

向一個<img>元素添加類,輕松地在項目中樣式化圖片。

rounded:讓圖片顯示圓角效果

rounded-circle:設置橢圓形圖片

img-thumbnail:用于設置圖片縮略圖(圖片有邊框):

<img src="圖片地址" class="rounded">
<img src="圖片地址" class="rounded-circle">
<img src="圖片地址" class="img-thumbnail">

 在bootstrap4中重命名了圖片相關的一些類,其中:

  • 重命名?.img-responsive?為?.img-fluid?;
  • 重命名?.img-rounded?為?.rounded ?
  • 重命名?.img-circle?為?.rounded-circle?

圖片對齊

使用 .float-right 類來設置圖片右對齊,使用 .float-left 類設置圖片左對齊:

具體使用方法:

<img src="圖片地址" class="float-left"> 
<img src="圖片地址" class="float-right">


響應式圖片

在Bootstrap4,我們可以通過在 <img> 標簽中添加 .img-fluid 類來設置響應式圖片。

.img-fluid 類設置了 max-width: 100%; 、 height: auto; :

實例:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap 實例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet"  rel="external nofollow" target="_blank" >
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js" rel="external nofollow" ></script>
  <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js" rel="external nofollow" ></script>
  <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js" rel="external nofollow" ></script>
</head>
<body>
<div class="container">
  <h2>響應式圖片</h2>
  <p>.img-fluid 類可以設置響應式圖片,重置瀏覽器大小查看效果:</p>
  <img src="http://www.o2fo.com/attachments/image/20180524/1527144620597215.png" class="img-fluid""></div>
</body>
</html>


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號