我正在嘗試使用html和css創建一行,在瀏覽器的左側和右側顯示兩個圖像,並在這兩個圖像的中間顯示文本。我試圖讓他們全都與鑲嵌物水平對齊。下面是相關代碼:如何獲得三個元素水平對齊?
<div class="col" id="egg_area">
<img id="egg_img" src="img/egg.png"></img>
</div>
<div class="col-6" id="introduction">
<p>Hello! Welcome to the Bacon, Egg, and Cheese Sandwich Web Map! The map below will allow you to search for the best deals on your favorite breakfast sandwich! Simply click a location anywhere within the 5 boroughs to reveal its nearest delis. By clicking each of the revealed markers you can view more details about each specific deli.</p>
</div>
</div>
<div class="col" id="bacon_area">
<img id="bacon_img" src="img/bacon.png"></img>
</div>
相關CSS:
#egg_area {
position: absolute;
display: inline;
}
#egg_img {
position: relative;
width: 100px;
display: inline;
}
#intro_area {
height: 500px;
font-size: large;
display: inline;
}
#title {
text-align: center;
margin: 0 auto;
color: white;
text-decoration: underline;
width: 250px;
margin-top: 50px;
}
#introduction {
text-align: center;
margin: 0 auto;
margin-top: 55px;
width: 100px;
color: white;
margin-top: -9px;
display: inline;
}
#bacon_area {
position: absolute;
display: inline;
}
#bacon_img {
position: relative;
width: 100px;
display: inline;
}
第一形象似乎與居中對齊文本,但第二圖像溢出到一個新行。我試過改變圖像大小。任何幫助將不勝感激!
我會推薦你使用CSS網格或flex,這會給你很大的靈活性。如果你需要幫助,請告訴我。 – osa
[水平對齊div]的可能重複(http://stackoverflow.com/questions/9277311/horizontally-aligning-divs) – Rob