Lets say I have x number of Items in a flex row.
flex-flow: row nowrap;
How can I dynamically set the leftmost side to justify to the left, and gradually shift the justification right until the rightmost item is justified on the right. Like this for example:
|Left | Leftish | Middle | Rightish | Right|
How can I accomplish this in a dynamic/responsive manner regardless of the number of items in the row?
This is what I have so far. It's almost perfect, but not quite.
https://jsfiddle.net/g6bbuj9s/
$(document).ready(function() {
var labelChildren = $('#xAxisLabels').children().length
var halfway = labelChildren / 2
var counter = 1
$('#xAxisLabels').children().each(function() {
var child = $(this)
if (counter == 1) {
child.css("text-align", "left");
} else if (counter > 1 & counter < halfway) {
child.css("text-align", "left");
child.css("text-indent", (((100 / labelChildren) * counter) - (counter * 9)) + "%");
} else if (counter == halfway) {
child.css("text-align", "center");
child.css("justify-content", "center");
} else if (counter == (halfway + .5)) {
child.css("text-align", "center");
child.css("justify-content", "center");
} else if (counter > halfway & counter < labelChildren) {
child.css("text-align", "right");
child.css("direction", "rtl");
child.css("text-indent", (((100 / labelChildren) * (counter % halfway)) - ((counter % halfway) * 9)) + "%");
} else if (counter == labelChildren) {
child.css("text-align", "right");
child.css("justify-content", "right");
child.css("display", "block");
}
counter += 1
});
});
.flexitem {
flex: 1;
display: flex;
}
.flexrow {
position: relative;
flex-flow: row nowrap;
display: flex;
}
.xAxis {
max-width: 100%;
width: 100%;
}
<div id="xAxisLabels" class="flexrow">
<h5 class="flexitem xAxis">1</h5>
<h5 class="flexitem xAxis">2</h5>
<h5 class="flexitem xAxis">3</h5>
<h5 class="flexitem xAxis">4</h5>
<h5 class="flexitem xAxis">5</h5>
<h5 class="flexitem xAxis">6</h5>
<h5 class="flexitem xAxis">7</h5>
</div>