I would like a list of four items, and an image, to display within a div element; I need the first item on the list to sit beneath the image, and the next three items to sit to the right of the image.
The four items must be in the same list, and the image cannot be part of this list. I have tried various ways but cannot get this to work as I’d like.
Can anyone help with this please?
.list-container .list:first-child {
/* display: flex; */
flex-direction: column;
color: green;
/* flex-direction: row | row-reverse | column | column-reverse; */
}
.list-container .list li:not(:first-child) {
display: flex;
color: red;
align-items: flex-start;
}
.image {
max-width: 50%;
height: auto;
float: left;
}
.list-container {
flex-grow: 1;
padding-left: 10px;
}
.list {
list-style-type: none;
padding: 0;
}
.list-item {
margin-bottom: 50px;
}
<div class="container">
<div class="">
<img src="https://www.w3schools.com/html/workplace.jpg" alt="Image" class="image" />
<div class="list-container">
<ul class="list">
<li class="list-item">List Item 1</li>
<li class="list-item">List Item 2</li>
<li class="list-item">List Item 3</li>
<li class="list-item">List Item 4</li>
</ul>
</div>
</div>
</div>
2
Answers
Try display grid.
Main point is to create same grid space for both elements inside the container. Positions of the list items can be changed with ‘nth-child’
You may try to code 2 columns instead!
Below code gets this output: