I'm building a portfolio website.
HTML Code
<div id = "hero">
<div id = "social">
<img src = "facebook.svg">
<img src = "linkedin.svg">
<img src = "instagram.svg">
</div>
</div>
CSS code (using SASS)
#hero {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 300px;
#social {
width: 50%;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
img {
width: 2em;
}
}
}
The problem is that I'm not able to resize SVGs using the CSS width
property. Here is what I obtain in different cases:
img { width: 2em; }
img { width: 3em; }
img { width: em; }
Please note how icons collapse toward the middle of the hero
div.
Instead, if I use the CSS height
property:
img { height: 2em; }
img { height: 3em; }
img { height: 4em; }
This behaviour is what I need, but I'm not sure this is the right way. Why this happens? Do you know better ways of resizeing SVG images (especially using the flexbox model)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…