I try to give to each line of a text the exact width of the parent block. I'm almost done but some lines are slightly shifted because of a weird space within the spans.
Here is a fiddle
var $wrapper = $('#wrapper');
$(window).on('load', function() {
$('.text').each(function() {
if ($(this).width() > $wrapper.width()) {
while ($(this).width() > $wrapper.width()) {
$(this).css('font-size', (parseInt($(this).css('font-size'), 10) - 1));
}
}
});
$wrapper.removeClass('invisible');
});
h1 {
position: relative;
font-weight: 600;
text-align: center;
}
h1 .text {
display: inline-block;
font-size: 40rem;
line-height: 1;
white-space: nowrap;
}
.wrapper {
width: 37.4rem;
margin: 0 auto;
opacity: 1;
transition: opacity 1s ease;
visibility: visible;
}
.wrapper.invisible {
opacity: .00001;
visibility: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper invisible" id="wrapper">
<h1>
<span class="text">Lorem</span>
<span class="text">ipsum dolor sit amet</span>
<span class="text">consectetur adipisicing elit</span>
</h1>
</div>
As you can see, some lines are larger than others. This is because of this space between the edge of the element and the actual text
Is there a way to make this perfectly aligned ?