I have a number and I want to put a star icon next to it, but in the middle.
The font-size of the number can be changed, but the star should stay in the middle.
For examples:
This is my css:
.my-container {
display: inline-block;
}
.my-text {
font-family: "Courier-new";
font-size:20px
}
.my-icon {
vertical-align: middle;
font-size: 10px;
}
.my-container {
display: inline-block;
}
.my-text {
font-family: "Courier-new";
font-size: 20px
}
.my-icon {
vertical-align: middle;
font-size: 10px;
}
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>
<div class="my-container">
<span class="my-text">5</span>
<span class='icon icon-star my-icon'></span>
</div>
This is my jsfiddle: http://jsfiddle.net/k48ttuLn/
3
Answers
I have used a combination of
line-height
andvertical-align: middle
to achieve this:Preview
Fiddle: http://jsfiddle.net/hn6ekzo5/
I would use flexbox for this. It will vertically center the content no matter the size.
See A guide to flexbox for more examples and tutorials