Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

html - How can I use flexbox to create a horizontal scrolling image gallery where the image size is responsive up to a point

I have a codepen showing where I've got to so far https://codepen.io/HightonRidley/pen/MWbWYgw

.flex-container {
    display: flex;
    overflow-x: auto;
    justify-content: left; 
    padding: 0;
    margin: 0;
    list-style: none; 
}

.flex-item {
    background: grey;
    padding: 5px;
    max-width: 350px;
    min-width:220px;
    margin-top: 10px;
    margin-left: calc(2px + 0.25vw);
    color: white;
    font-weight: bold;
    font-size:calc(10px + 0.25vw);
    text-align: center;
    flex: 1;
    overflow-y: hidden;
}
.myDiv {
    height:30px;
}
img {
    width: 100%; 
}
<div style="width:80%;margin-left:auto;margin-right:auto;"><ul class="flex-container">
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">some text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">some more text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of textlots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of textlots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of textlots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of textlots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of textlots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of textlots of text lots of text lots of text</div></li>
  <li class="flex-item"><img src="https://i.ibb.co/KGW0dPQ/500x500px-test-image.jpg" alt="500x500px-test-image"><div class="myDiv">lots of text lots of text lots of textlots of text lots of text lots of textlots of text lots of text lots of text</div></li>
</ul>
</div>
question from:https://stackoverflow.com/questions/65947479/how-can-i-use-flexbox-to-create-a-horizontal-scrolling-image-gallery-where-the-i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...