Displaying rows of images on 100% width - html

I need to display images in my grid with the following idea: every li elements of each ultag should stay in the same row and be 100% width of the container.
As you can see in the jsfiddle, for the demo, I created 3 ul. So I would like 3 rows of images.
The jsfiddle: is here
The final result should be like below:
I don't know how to proceed so that every row takes 100% width.
So every row (ul) may contains 1, 2, 3, 4 or 5 images.

every li elements of each ultag should stay in the same row and be 100% width of the container
You needs to use Flexbox
Result
ul {
display: flex;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
margin-bottom: 3px;
}
li {
flex-grow: 1;
}
li+li {
margin-left: 3px;
}
img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
<ul>
<li>
<img src="https://via.placeholder.com/250x200?text=A1">
</li>
<li>
<img src="https://via.placeholder.com/150x200?text=A2">
</li>
<li>
<img src="https://via.placeholder.com/350x200?text=A3">
</li>
</ul>
<ul>
<li>
<img src="https://via.placeholder.com/200x200?text=B1">
</li>
<li>
<img src="https://via.placeholder.com/300x200?text=B2">
</li>
<li>
<img src="https://via.placeholder.com/150x200?text=B3">
</li>
</ul>
<ul class="fivePerRow">
<li>
<img src="https://via.placeholder.com/250x200?text=C1">
</li>
<li>
<img src="https://via.placeholder.com/150x200?text=C2">
</li>
<li>
<img src="https://via.placeholder.com/350x200?text=C3">
</li>
<li>
<img src="https://via.placeholder.com/200x200?text=C4">
</li>
<li>
<img src="https://via.placeholder.com/300x200?text=C5">
</li>
</ul>
And same code on JSFiddle

I think using Flexbox will do the job.
ul {
width: 100%;
list-style: none;
display: flex;
justify-content: space-between;
}
li {
display: inline-block;
vertical-align: top;
}
Codepen Demo

Related

how do I put the oversized logo overlap the nav?

thanks for your help. I just starting to learn HTML and CSS. I have been wrestling with this oversize logo problem for a week now. How do I put the logo overlap the nav like a layer look?
my html file:
<nav class = "navigation-bar">
<link rel="stylesheet" href="{% static 'financeapp/style1.css' %}">
<div class = "navigation-container">
<ul>
<li><img class = "logo" src ="{% static 'financeapp/family examiner 2.png' %}"
alt="company logo" height = 150px width = 150px>
<li> Home </li>
<li> About </li>
<li> Contact </li>
<li> Join Us </li>
</ul>
</div>
my css file:
.navigation-bar {
display:flex;
margin: 0;
padding: 0;
align-items: center;
text-align: center;
}
.logo {
float: left;
}
.navigation-container {
display: flex;
justify-content: space-betwee;
width: 100%; /*left side*/
margin-top: 5rem;
border: 1px solid;
border-color: green;
}
.navigation-container ul {
margin: 0;
padding: 0;
width: 100%; /*right side*/
height: 70px;
background-color: yellow;
}
.navigation-container li {
display: inline;
}
.navigation-container a {
padding: 10px;
text-decoration: none;
thanks for your time.
First you need to put your image inside your List
<div class = "navigation-container">
<ul>
<li><img class = "logo" src ="{% static 'financeapp/family examiner 2.png' %}"
alt="company logo" height = 150px width = 150px style="background-color: black;"></li>
<li> Home </li>
<li> About </li>
<li> Contact </li>
<li> Join Us </li>
</ul>
</div>
Then you can put a margin-top on your list to make it go down, so the picture does properly fit later
.navigation-container {
display: flex;
justify-content: space-betwee;
width: 100%; /*left side*/
margin-top: 5rem;
}
Then you can set your .logo to margin-top: -43px; as example and the logo will move up.
You will need to play around with the numbers to make it so you like the look.
Also important note is that none of this is responsive and it will probably not look good later on.
You always should start to design for mobiles first.

How to center unordered list of images? [duplicate]

This question already has answers here:
How to center an unordered list?
(8 answers)
Closed 3 years ago.
I am trying to center an unordered list of imagines on a website.
I have tried using 'text-align: center;', margins(which works, kinda, but looks super sloppy)
#nav{
margin-left:44%;
margin-bottom: 10px;
width: 100%;
text-align: center;
background-color: transparent;
height: 40px;
margin-bottom: 100px;
}
#nav li a {
padding: 10px;
text-decoration: none;
font-weight: bold;
color: #FFFFFF;
background-color: transparent;
float: left;
text-align: center;
display: inline;
}
<div id="nav">
<ul>
<li>
<img src='./public/images/discord.png' style="height:40px;border:0;">
</li>
<li>
<img src='./public/images/youtube.png' style="height:40px;">
</li>
<li>
<img src='./public/images/twitch.png' style="height:40px;border:0;">
</li>
</ul>
</div>
The list just doesn't center properly, as expected with manually set margins.
I recommend using flex box to handle problems like these. The first example in the snippet shows centering using flex box. The second example shows centering an unordered list.
To center an unordered list, I've set the margin left and right on the containing element (#nav) to auto. For this to center the list, you will need to know the exact width of the list. I've calculated to be 3 x 40px for each image, plus 20px for spacing for each image, making 180px in total.
A common problem some run into when dealing with undordered is that lists come with default padding on the left. For perfect centering, I've removed the list style bullets, and removed the padding too.
.flex {
display: flex;
justify-content: center;
}
.flex>div {
margin-right: 20px;
}
#nav {
margin: 0 auto;
width: 180px;
}
#nav>ul {
padding-left: 0px;
}
#nav li {
list-style-type: none;
text-decoration: none;
float: left;
margin-right: 20px;
}
<h2>Display flex</h2>
<div class="flex">
<div>
<img src='https://picsum.photos/40' style="height:40px;border:0;">
</div>
<div>
<img src='https://picsum.photos/40' style="height:40px;">
</div>
<div>
<img src='https://picsum.photos/40' style="height:40px;border:0;">
</div>
</div>
<h2>Centered UL</h2>
<div id="nav">
<ul>
<li>
<img src='https://picsum.photos/40' style="height:40px;border:0;">
</li>
<li>
<img src='https://picsum.photos/40' style="height:40px;">
</li>
<li>
<img src='https://picsum.photos/40' style="height:40px;border:0;">
</li>
</ul>
</div>

Responsive height of images on resize

I'm really stuck with responsive images short story I'm trying to make a simple grid like this
https://avenue-demo.squarespace.com
in this avenue website all the images have the same height and width when you resize the browser the images are resizing fine now here is my code
<ul class="grid">
<li>
<a href="">
<img src="https://images.unsplash.com/photo-1546725923-697533ae284d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80" alt="">
</a>
</li>
<li>
<a href="">
<img src="https://images.unsplash.com/photo-1546934164-73ef3631f62d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=933&q=80" alt="">
</a>
</li>
<li>
<a href="">
<img src="https://images.unsplash.com/photo-1547014751-2b43a527b6fa?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1100&q=80" alt="">
</a>
</li>
</ul>
css :
.grid {
display: flex;
max-width: 1100px;
justify-content: space-between;
margin: 0 auto;
list-style: none;
}
.grid li {
width: 30%;
}
img {
max-width: 100%;
}
the problem is the images are not the same height when I set the height of the img to height 100% yes the images do have the same height but on resize they are shrinking not resizing like this website I posted, how can I fix it ?
As per my understanding you need to have square images to get the shown responsiveness, even though i have made some css changes to your code, to look like the images from website (which is not suggested always)
here is the code pen link
https://codepen.io/avreddy/pen/vvabbP
.grid {
display: flex;
max-width: 1100px;
justify-content: space-between;
margin: 0 auto;
list-style: none;
}
.grid li {
width: 30%;
}
.grid li a{
position: relative;
width: 100%;
padding: 50% 0;
display : block;
}
.grid li a img{
position: absolute;
width : 100%;
top: 0;
left: 0;
height: 100%;
object-fit : cover;
}
img {
max-width: 100%;
}
<ul class="grid">
<li>
<a href="">
<img src="https://images.unsplash.com/photo-1546725923-697533ae284d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80" alt="">
</a>
</li>
<li>
<a href="">
<img src="https://images.unsplash.com/photo-1546934164-73ef3631f62d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=933&q=80" alt="">
</a>
</li>
<li>
<a href="">
<img src="https://images.unsplash.com/photo-1547014751-2b43a527b6fa?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1100&q=80" alt="">
</a>
</li>
</ul>

UL/LI CSS menu not aligning properly

I am having issues getting my menu to align properly. The images are all spaced far away from each other even when they should be closer. I am new to using Ul and Li and am not sure how to fix this. Ideally I would have the images across the whole screen with no space on the right or left and just a thin space between each image, but instead, there is a large space. I am unsure if this is something in the Ul Li tags or if there is something I can do with margin.
Could someone please advise me. I am including a jsfiddle to show what it currently looks like. https://jsfiddle.net/f1bctqzn/ is what I am currently getting. How do I these lines to touch their respective sides of the screen and still have a small space between the rest.
<li class="header"><img src="https://i.imgur.com/T4ZAaK3.png" class ="kale-grain-bowls"></li>
<li class="header"><img src="https://i.imgur.com/T4ZAaK3.png" class ="kids-real-meals"></li>
Add padding: 0 to your ul and margin: 1px (or something) to li
Also, add width: 100% to img
See this fiddle
To add space betwwen the li items, don't add the margin property to the ul, but add a margin to the li items (I used the 2px you had set for the ul). To add a margin only between the li items, I used
li.header{
margin-left:2px;
}
li.header:first-child{
margin-left: 0;
}
Adjusted the margins and used a flexbox to adjust the images across the whole screen.
Check it out and let me know your feedback. Thanks!
body {
margin: 0;
padding: 0;
}
ul.toplist {
list-style: none;
padding: 0;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
}
li.header {
display: inline-block;
height: 100%;
margin-right: 1px;
}
img.kale-grain-bowls,
img.salads,
img.burgers-sandwiches,
img.sides,
img.smoothies-milkshakes,
img.kids-real-meals {
max-width: 100%;
max-height: 100px;
}
<ul class="toplist">
<li class="header">
<a href="/menu/kale-grain-bowls">
<img src="https://i.imgur.com/T4ZAaK3.png" class="kale-grain-bowls">
</a>
</li>
<li class="header">
<a href="/menu/salads">
<img src="https://i.imgur.com/T4ZAaK3.png" class="salads">
</a>
</li>
<li class="header">
<a href="/menu/burgers-sandwiches">
<img src="https://i.imgur.com/T4ZAaK3.png" class="burgers-sandwiches">
</a>
</li>
<li class="header">
<a href="/menu/sides">
<img src="https://i.imgur.com/T4ZAaK3.png" class="sides">
</a>
</li>
<li class="header">
<a href="/menu/smoothies-shakes">
<img src="https://i.imgur.com/T4ZAaK3.png" class="smoothies-milkshakes">
</a>
</li>
<li class="header">
<a href="/menu/kids-real-meals">
<img src="https://i.imgur.com/T4ZAaK3.png" class="kids-real-meals">
</a>
</li>
</ul>

How to center image in <li> elements?

I have a ul whose cells consist of an image and a text:
<ul class="special_ul">
<li>
<img src="img/solution_icon_optimize-efficnt.png">
OTT
</li>
<li>
<img src="img/solution_icon_personal.png">
Cloud Computing
</li>
<li>
<img src="img/solution_icon_diti-cx.png">
Managed Services
</li>
<li>
<img src="img/solution_icon_biz-analitics.png">
Social Media
</li>
</ul>
css:
.special_ul li{
padding-right: 10px;
list-style-type: none;
display: inline-block;
text-align: center;
}
.special_ul li img , .special_ul li a{
display:block;
}
The problem is that the text is centered but the images are not:
(i highlighted the list with the mouse so you can see the images are not in the center)
How do I make the images centered (horizontally) as well?
You can just remove img {display: block;}, by default it is inline level, they will get centered with text-align: center; set on the container, which you already did.
Or, add margin: 0 auto; if you need to keep display: block; on the img:
.special_ul li img {
display: block;
margin: 0 auto;
}