简体   繁体   中英

Align Label and Icon in same line

I want to show text follwed by an icon.
I'm using material icons.

在此处输入图片说明

I want to achieve what it is on the left. But the right side is the one I'm getting.

I tried padding,margin,line height and everything but I couldn't make them align.

The Working webpage for the above issue is here

Html

                <div class="package-rating-detail">
                    <label>{{package.rating}}</label>
                    <mdl-icon class="mdl-color-text--orange">star_rate</mdl-icon>
                </div>

css

.package-rating-detail {
    float: left;
    margin-left: 20px;
}

So how can I align the label and the icon.

Try flex :

.package-rating-detail[_ngcontent-c3] {
    display: inline-flex;
    align-items: center;
    margin-top: 0.3em; // cosmetic
    margin-left: 1em; // cosmetic
}

UPDATE: You can improve the alignment and make it look better by adding some space between the star and the label:

.package-rating-detail[_ngcontent-c3] > label {
    margin-right: 0.2em;
    margin-top: 0.2em;
}

(the margin-top will take the label a bit down, which looks better in my opinion).

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM