How to Vertical Center Text Next to an Image in HTML/CSS

Vertically align text next to an image?

Actually, in this case it's quite simple: apply the vertical align to the image. Since it's all in one line, it's really the image you want aligned, not the text.

<!-- moved "vertical-align:middle" style from span to img -->
<div>
<img style="vertical-align:middle" src="https://via.placeholder.com/60x60" alt="A grey image showing text 60 x 60">
<span style="">Works.</span>
</div>

How do I vertical center text next to an image in html/css?

This might get you started.

I always fall back on this solution. Not too hack-ish and gets the job done.

EDIT: I should point out that you might achieve the effect you want with the following code (forgive the inline styles; they should be in a separate sheet). It seems that the default alignment on an image (baseline) will cause the text to align to the baseline; setting that to middle gets things to render nicely, at least in FireFox 3.

<div>    <img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg" style="vertical-align: middle;" width="100px"/>    <span style="vertical-align: middle;">Here is some text.</span></div>

Vertical align text along side image

wrap your image and text in div .container, and set the rules for flex and align-item center.

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

.image {
width: 58%;
padding-top: 60%;
margin-right: 2%;
position: relative;
float: left;
position: relative;
background-image: url("https://cdn.shopify.com/s/files/1/0292/7217/8793/files/photo-1556760647-90d218f7ca5b.jpg?v=1589200183");
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 50%;
}
.textcontainer {
width: 40%;
position: relative;
float: left;
}
<div class="container">
<div class="image">
</div>
<div class="textcontainer">
Some text which i would like centred
</div>
</div>

HTML + CSS for Centering Vertical Text next to an Image

You could use flexbox. See the example:

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

https://jsfiddle.net/zb2ozq1k/1/

How to vertically center text next to image?

You've got vertical-align: top in there; what you want is vertical-align: middle, on both the link and the image it's supposed to sit next to.

.section_content {    width: 400px;}
.section_content > ul > li > img { width: 40px; height: 40px; padding: 5px;}
.section_content > ul > li > a,.section_content > ul > li img { vertical-align: middle;}
.section_content > ul > li { list-style-type: none;}
.section_content > ul { list-style-type: none;
padding-top: 45px; padding-left: 5px;}
<div class="section_content">        <ul>            <li><img src="img/linkedin.svg"><a href="https://be.linkedin.com/in/lel">LinkedIn</a></li>            <li>GitHUb</li>        </ul>    </div>

Align an image div in the vertical center of a text div next to it

You will need to remove the float and use a wrapper instead: https://jsfiddle.net/qhf8Lczg/1/

.mcnTextContent {  position: relative !important;  margin: 0 !important;  padding: 0 !important;}
.mcnTextContent { position: relative; left: 0px; padding: 10px !important;}
.mcnTextBlockOuter { padding: 0px !important;}
.mcnTextBlockInner { padding: 0px !important; background-color: white;}
.positionr { position: relative !important; display: flex; justify-content: space-between;}
.textcolumn { display: inline-block; width: 370px; height: auto !important; border: 1px solid red;}
.textcolumn h1 { text-transform: uppercase; color: black !important; font-family: "Arial" !important; font-weight: initial;}
.textcolumn p { font-family: "Arial" !important; font-size: 14px !important; color: black !important;}
.imagecolumn { display: inline-block; border: 1px solid blue;}
.imagecolumn img { padding-left: 15px; padding-top: 10px;}
.img-wrapper { position: relative; top: 50%; transform: translateY(-50%);}
<div class="positionr">  <div class="textcolumn">    <h1>Header</h1>    <p>Lorem ipsum dolor sit amet, an doming bonorum pri, ferri oratio malorum pro et, per tritani phaedrum consulatu in. Vix ei persius assentior, omnes volumus pri id. Eos odio altera dictas no. Erat omnium nominati vix eu, sit et commune pertinacia. Id      laudem officiis referrentur vix.</p>  </div>  <div class="imagecolumn">    <div class="img-wrapper">      <img src="http://via.placeholder.com/50x50" />      <img src="http://via.placeholder.com/50x50" /><br />      <img src="http://via.placeholder.com/50x50" />      <img src="http://via.placeholder.com/50x50" />    </div>  </div></div>


Related Topics



Leave a reply



Submit