CSS 沒有直接讓文字貼齊容器底部的屬性,但可以透過 position 的相對與絕對定位完成。
讓父容器設定 position: relative,子元素設定 position: absolute,再用 bottom 指定距離。
#txt {
position: relative;
width: 300px;
height: 300px;
border: 1px solid #333;
text-align: center;
}
#txt p {
position: absolute;
bottom: 0;
padding: 0;
margin: 0;
}
這樣段落文字就會貼近容器底部。若要保留一點間距,可將 bottom 設為 10px 或其他數值。