0

I would like to have an image in my webpage. The image should be centered on the page, and it should have a text next to it on the right side like this:

enter image description here

My current CSS code to show an image centered is this:

.inlineimage {
text-align:center; 
width:100%;
display:block;
margin:auto;
}

And I use it like this:

<div class="inlineimage">
    <picture>
        <source
            media="(max-width: 900px)"
            srcset="images/image1.jpg">
        <img
            src="images/image2.jpg"
        alt="">
    </picture>
</div>
This is some text that should be shown on the right side of the image, but currently it's shown below the image.

How could I change my CSS code in such a way that the text is shown on the right side of the image?

Thank you!

tmighty
  • 10,734
  • 21
  • 104
  • 218

2 Answers2

2

Use a display: flex; parent positioned 50% from the left, then translate left half of the image's width.

.inlineimage {
  text-align:center; 
  width:100%;
  display:block;
  margin:auto;
}

#flex{
  margin: auto;
  display: flex;
  margin-left: 50%;
  align-items: flex-end;
  transform: translate(-100px); /* Make this half the image width */ 
}

#image{
  height: 100px;
  width: 100px;
  background-color: blue;
}
<div id="flex">
  <div id="image"></div>
  <div>
  This is some text that should be shown on the right side of the image, but currently it's shown below the image.
  </div>
</div>
Libra
  • 2,544
  • 1
  • 8
  • 24
-2

/*set fixed */
.fixed{
position:fixed;
top:0%;
}

.text{
left:10%;
top:-5%;

position:fixed;
}






/*Set Size as a value to save image url by streaching data uri you don't need this code this is just so you can see it */
.size{
width:50px;
height:50px;

}
<span class = 'fixed'>
<img class ='size' src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==">
</span>
<h1 class = "text">Some text</h1>
Rob
  • 14,746
  • 28
  • 47
  • 65
DarticCode
  • 62
  • 4