如何居中圖像
學習如何使用 CSS 將圖像居中。
居中圖像:

如何居中圖像
第一步 - 添加 HTML:
<img src="paris.jpg" alt="Paris" class="center">
第二步 - 添加 CSS:
要使圖像居中,請將左右外邊距設置為 auto
,并將其設置為塊元素:
.center { display: block; margin-left: auto; margin-right: auto; width: 50%; }
請注意,如果寬度設置為 100%
(全角),則無法居中。
相關頁面
教程:CSS 圖像