Reputation: 47
I can't put the text in the middle height of the image it is in with.
This is what I write in the HTML:
<p><img class="languagesIcons" src="img/x.png">x</p>
This is what I write in the CSS:
.languagesIcons {
width: 55px;
margin: 0 10px 0 0;
}
All of that runs in a <div>
which its CSS is:
#languages {
display: grid;
grid-template-columns: repeat(4, 1fr);
font-size: 22px;
gap: 30px;
padding: 20px 0 0 0;
}
Upvotes: 0
Views: 71
Reputation: 56
You could just add vertical-align:middle to your languageIcons class:
.languageIcons{
width:55px;
margin: 0 10px 0 0;
vertical-align:middle;
}
Upvotes: 1
Reputation: 322
You should use position:absolute
on the image and the text placed in a span for example and use position:relative
on the container which is a p tag here. Then you can adjust its position with transform:translateY()
for example.
See the code below :
p{
position:relative
}
.languagesIcons {
width: 55px;
margin: 0 10px 0 0;
position:absolute
}
div{
display: grid;
grid-template-columns: repeat(4, 1fr);
font-size: 22px;
gap: 30px;
padding: 20px 0 0 0;
}
span{
position:absolute;
transform:translateY(50%)
}
<div><p><img class="languagesIcons" src="img/x.png"><span>x</span></p></div>
Upvotes: 1
Reputation: 429
To vertically align text and image, use :
<p>
<img class="languagesIcons" src="img/x.png" style="vertical-align: middle;" >
<span style="vertical-align: middle;" >x</span>
</p>
Upvotes: 0