[英]Parent div is flex, children divs are columns with flex:1. How to push the content of the right column to the right side of the column?
我試圖將第二列中的“ HELLO”推到該列的右側,而不更改第一列中“ HELLO”的位置。 實現此目的最簡單的方法是什么?
.row { display: flex; } .column { flex: 1; } .slideshow-photos { width: 100%; height: 100%; object-fit: cover; } .mySlides { width: 100px; height: 100px; }
<div class='row'> <div class='column'> <p>HELLO</p> </div> <div class='column'> <div class="photos-container"> <div class="mySlides"> <img class='slideshow-photos' src="https://www.animalfriends.co.uk/app/uploads/2014/08/06110347/Kitten-small.jpg"> </div> </div< </div> </div>
如果希望最后一列折疊,則可以使用last-of-type
偽類將flex-grow
值重置為0
。
.row { display: flex; } .column { flex: 1; } .column:last-of-type { flex: 0; } .slideshow-photos { width: 100%; height: 100%; object-fit: cover; } .mySlides { width: 100px; height: 100px; }
<div class='row'> <div class='column'> <p>HELLO</p> </div> <div class='column'> <div class="photos-container"> <div class="mySlides"> <img class='slideshow-photos' src="https://www.animalfriends.co.uk/app/uploads/2014/08/06110347/Kitten-small.jpg"> </div> </div< </div> </div>
試試這個代碼,它應該工作
.row { display: flex; justify-content: space-between; } .column { /* not need flex 1 here*/ }
<div class='row'> <div class='column'> <p>HELLO</p> </div> <div class='column'> <p>HELLO</p> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.