I have a design for a top-of-the-page dashboard in HTML that has the following requirements:
- Everything should be vertically centered within the dashboard.
- It should have a button in the exact center.
- It should have text centered at the 25% and 75% marks.
- It should have one last group of text all the way to the left.
Like this, but not with horrible colors:
I was able to achieve the top three goals (or very close to it) using display: flex
and giving appropriate sizes to everything, like so:
HTML:
<div class="header">
<span class="left-text">LEFT TEXT</span>
<button class="button">BUTTON</button>
<span class="right-text">RIGHT TEXT</span>
</div>
CSS:
.header {
position: absolute;
top: 55px;
height: 40px;
width: 100%;
background-color: beige;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.button {
height: 26px;
width: 100px;
order: 2;
flex-grow: 0;
}
.left-text {
order: 1;
flex-grow: 1;
text-align: center;
}
.right-text {
order: 3;
flex-grow: 1;
text-align: center;
}
This last requirement, though, is really throwing me for a loop; without everything being nice and centered, I feel like flex
is going to need some ugly adjustments. I feel like this would be much easier if I could layer div
or span
elements on top of each other however I liked, but something tells me I can't. Are there any good solutions for this problem? Am I close?
EDIT: added image of mockup.