Created
March 13, 2020 13:04
-
-
Save Farmatique/daac5b1a6b4998bca3c9eec1b90c5ccd to your computer and use it in GitHub Desktop.
Align icon (image element, etc) with only first line of text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>The long long text with icon before that should be vertically aligned to first line of text<h1> | |
h1{ | |
font-size: 40px; | |
line-height: 1.444; | |
} | |
h1:before{ | |
content: 'A'; // here is the first trick: pseudoelement with some text gives us the height of the 1st line of main-element`s text | |
display: inline-block; | |
background: url(youricon.png) no-repeat; | |
background-size: 10px; | |
background-position: 0 center; | |
color: transparent; // here is the second trick - we hide text, but bg-image still visible, bingo! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment