小編給大家分享一下css如何實現圖片在div標簽居中,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
方法一:
html:
<div class="title">
<div class="flag"></div>
<div class="content">
<img src="img_p1_title.png">
</div>
</div>css
.title {
width: 100%;
font-size: 0;
height: 10%;
}
.title .content img {
width: 35%;
}
/*--主要的--*/
.content{
display: inline-block;
vertical-align: middle;
}
.flag{
display: inline-block;
vertical-align: middle;
height: 100%;
width: 0;
}方法二:
html
<div class="title"> <img src="img_p1_title.png">
css
.title {
display: flex;
justify-content: center;
align-items: center;
}
.title img {
width: 35%;
}//該方法有些舊系統不支持方法三:
html
<div class="title"> <span>第三種方法</span>
css
.title {
height: 15%;
font-size: 18px;
position: relative;
}
.title span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}方法四:
html
<div class="title"> <span>第四種方法</span>
css
.title {
width: 200px;
height: 200px;
vertical-align: middle;
display: table-cell;
text-align: center;
}以上是css如何實現圖片在div標簽居中的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。