Centering in HTML with its varieties has of course been asked and answered innumerable times.
Still, I'm having elementary issues.
.banner_box {
width: 640px; height: 150px;
background-color: #ddd;
margin: 5px;
display: flex;
align-items: center;
}
.left_center_myicon {
display: block;
margin: 0 auto;
float: left;
/*height: 100%;*/
}
<div class="banner_box">
<img class="left_center_myicon" src="myicon.svg" />
</div>
<div class="banner_box">
<a href="index.html"><img class="left_center_myicon" src="myicon.svg" /></a>
</div>
where myicon.svg
consists of one rectangle:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="30pt" height="15pt" viewBox="0 0 400 200" version="1.1">
<g style="fill:rgb(10%,40%,70%);fill-opacity:1;">
<rect x="100" y="50" rx="20" ry="20" width="200" height="100" />
</g>
</svg>
Despite that I am specifying float: left
on both instances of left_center_myicon
, it floats to the left only if it's inside an <a>
tag.
Now my icon is rather small. I can easily make it fill the height of banner_box
by adding height: 100%
. In the lower banner_box
that of course makes the icon 100%
of just the anchor.
How do I set the percent height of an icon, and vertically center it, while left-floating it?
In short, I am able to either left-center an icon
or enlarge it to some percentage
but not both.