本文為大家介紹了圖片在div中居中的四種方法,希望對大家有幫助。
方法一:
(推薦教學:css影片教學)
html:
<div class="title"> <div class="flag"></div> <div class="content"> <img src="/static/imghwm/default1.png" data-src="img_p1_title.png" class="lazy" alt="css實作圖片在div中居中的方法有哪些" > </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="/static/imghwm/default1.png" data-src="img_p1_title.png" class="lazy" alt="css實作圖片在div中居中的方法有哪些" >
css
.title { display: flex; justify-content: center; align-items: center; } .title img { width: 35%; }//该方法有些旧系统不支持
方法三:
<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中居中的方法有哪些的詳細內容。更多資訊請關注PHP中文網其他相關文章!
陳述
本文轉載於:csdn。如有侵權,請聯絡admin@php.cn刪除

當他們在2013年去Chrome時,我們失去了歌劇。與Edge今年早些時候也進行了同樣的交易。邁克·泰勒(Mike Taylor)稱這些變化為“減少

在本週的綜述中,Apple進入Web組件,Instagram如何插入腳本以及一些思考的食物,以進行自託管關鍵資源。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前By尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
2 週前ByDDD
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境