I’m sorry I don’t even know how to ask my question, but basically, I need the title to be above the paragraph and the logo to be on the left side.
#container {
display: flex;
align-items: center;
}
#container p {
margin-left: 1em;
}
#container h4 {}
}
<div id='container'>
<img src="http://placekitten.com/100/100" alt="image" width="50" height="50">
<h4>
Placeholder Title
</h4>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mattis, arcu in tempus tempor, odio velit vehicula erat, sed facilisis sem enim at sapien. </p>
</div>
5
Answers
I got your doubt. Basically flex works on direct child. So according to your picture reference, there are two columns, so you have to wrap h4 and p tag with a div, this makes container with 2 childs and you will get the desired result.
It will not work with Flexbox as you cant change the flex-direction after an element within the same container. As you need to control 2 directions within the same container with your markup you have to use
CSS-Grid
First alternative
Hi! Have you tried using the propety float? Because using the value "left" in this property makes the image go to the left side of the document.
However, it doesn’t work if the image element is inside a parent whose display is flex so you have to put the image before the container. Here is a code snippet:
Second alternative
You can also use a separated div which includes the paragraph and the image and set its display to flex.
And there you are! I hope this helps!
If you do not have access to the HTML and thus can’t create another container, @tacoshys answer is right – you can’t make this two-dimensional layout without
grid
. Flexbox is for one-dimensional layouts. You can, however, wrap your text inside anothercontainer
, and then use theflex
layout to control thetext-container
andimg
.This should definitely work: I did an example on codepen if you need: https://codepen.io/olusegunadex/pen/abqyGaW
for the CSS;
For the HTML: