I'm pretty sure I managed to do this by accident while developing this page, but now I cannot for the life of me figure out what I did.
I am trying to create three <div>
s as follows:
- All divs same width
- Width tto be as per widest
<div>
- Total width to be no more than needed (ie not full screen width)
- The collection of
<div>
s to be centred in page
So far I have the following:
.switch-buttons-container {
display: flex;
flex-flow: wrap;
justify-content: center;
margin: auto;
}
.button-div {
flex: 1 1 0;
padding: 5px;
color: grey;
border: 1px solid black;
background-color: rgba(0,0,0,0.25);
border-radius: 0px 0px 10px 10px;
line-height: 28px;
font-size: 22px;
margin-left: 2px;
margin-right:2px;
font-weight: bold;
cursor: pointer;
}
.selected {
color: white;
background-color: rgba(0,0,0,0.5);
}
.indicator, .indicator-selected {
display: inline-block;
width: 20px;
height: 20px;
border-radius: 10px;
border: 1px solid black;
margin-right: 10px;
}
.indicator {
background-color: grey;
}
.indicator-selected {
background-color: yellow;
}
.button-text {
display: inline-block;
}
<div class="switch-buttons-container" id="systems-selection-box">
<div class="button-div selected" id="system1">
<div class="indicator-selected"> </div>
<div class="button-text">System 1</div>
</div>
<div class="button-div" id="system2">
<div class="indicator"> </div>
<div class="button-text">Sys 2</div>
</div>
<div class="button-div" id="system3">
<div class="indicator"> </div>
<div class="button-text">3</div>
</div>
</div>
As you can see, this fills the full width of the screen rathen than making the buttons only as wide as they need to be.
Note that the text content of the buttons is not known at design time and there are other areas of the page which have different width requirements so this can't be limited in the body element.
My guess is that I need to fix something in the .switch-buttons-container
class, but I've searched and searched and tried all kinds but just can't get this right.