I have a design where an image is floated to the left next to text with a line-height of 2.
How can I make sure the top of the image aligns perfectly with the top of the text?
- Changing the line-height to reduce the space between text and image is not feasible for this project.
- The styling will be applied site-wide, so manually adjusting margins for each instance is not practical.
- This issue is common and could involve various combinations of text and images.
Is there a way to adjust the spacing correctly without changing the overall line-height?
.left {
float:left;
}
.text {
line-height:2;
}
<div>
<img class="left" src="https://placehold.it/60x60">
<p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
- Using the ::first-line pseudo-element doesn't achieve the desired outcome, especially when wrapping text or in Firefox. See example here: http://jsfiddle.net/Dqmu8/25/