時間:2023-07-03 19:57:02 | 來源:網(wǎng)站運營
時間:2023-07-03 19:57:02 來源:網(wǎng)站運營
兩分鐘帶你了解在CSS中三種使圖片居中的方法:<div class="img_wrap"> <img src="wgs.jpg"></div>
css代碼如下:.img_wrap{ width: 400px; height: 300px; border: 1px dashed #ccc; display: table-cell; //主要是這個屬性 vertical-align: middle; text-align: center;}
效果如下:<p class="img_wrap"></p>
css代碼如下:.img_wrap{ width: 400px; height: 300px; border: 1px dashed #ccc; background: url(wgs.jpg) no-repeat center center;}
效果如下圖:<div class="img_wrap"> <p><img src="wgs.jpg"></p></div>
css代碼如下:*{margin: 0px;padding: 0px}.img_wrap{ width: 400px; height: 300px; border: 1px dashed #ccc; text-align: center;}.img_wrap p{ width:400px; height:300px; line-height:300px; /* 行高等于高度 */}.img_wrap p img{ *margin-top:expression((400 - this.height )/2); /* CSS表達式用來兼容IE6/IE7 */ vertical-align:middle; border:1px solid #ccc;}
效果圖如下:關鍵詞:圖片,居中,方法
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。