Ask Your Question
2

How can two divs be arranged alongside each other, with the left one displaying text and the right one displaying an image?

asked 2023-04-06 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-08-24 15:00:00 +0000

bukephalos gravatar image

To arrange two divs alongside each other, you can use CSS flexbox or CSS grid. Here’s an example using flexbox:

HTML:

<div class="container">
  <div class="text">Some text goes here</div>
  <div class="image"> <img src="image.png"> </div>
</div>

CSS:

.container {
  display: flex;
  align-items: center;
}

.text {
  flex: 1;
  padding: 10px;
}

.image {
  flex: 1;
  text-align: center;
}

Explanation:

  • The container element is set to display: flex to enable flexbox layout.
  • The align-items property centers the two elements vertically.
  • The .text and .image elements are both given a flex: 1 property, which means they will take up equal amounts of space inside the container.
  • The .text element is given some padding to create some space around the text.
  • The .image element is centered using the text-align property. You can also use justify-content property if you need to align elements horizontally.

This will display the text on the left and the image on the right, both elements side by side.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-06 11:00:00 +0000

Seen: 12 times

Last updated: Aug 24 '21