I'm in the process of creating a webpage where users can choose the color and storage capacity of an item. Only one color/capacity can be selected at a time, and once chosen, it should be highlighted with a border.
The issue I encountered is that when applying the border, it displaces other elements on the page, as shown below:
https://i.stack.imgur.com/tsJqY.png
My initial thought was to give all elements a border: 2px solid rgba(0,0,0,0)
to prevent displacement and then use JavaScript to modify the border properties upon selection. However, I believe this approach may not be the most elegant solution.
Below is the HTML code...
<ul>
<li onclick="changeName('Gold')"><div class="select-color" id="gold"></div></li>
<li onclick="changeName('Silver')"><div class="select-color" id="silver"></div></li>
<li onclick="changeName('Space Grey'); "><div class="select-color" id="space-grey"></div></li>
</ul>
and the CSS code...
ul li {
width: 47px;
height: 47px;
border-radius: 12px;
border: 2px solid rgba(0,0,0,0);
padding: 3px;
}
.select-color {
width: 45px;
height: 45px;
border-radius: 8px;
border: 1px solid #c2bebb;
-webkit-box-shadow: inset 0px -99px 46px -86px rgba(0,0,0,0.42);
-moz-box-shadow: inset 0px -99px 46px -86px rgba(0,0,0,0.42);
box-shadow: inset 0px -99px 46px -86px rgba(0,0,0,0.42);
}
#gold {
background-color: #f5e7dc;
}
#silver {
background-color: #e2e2e2;
}
#space-grey {
background-color: #232323;
}
If anyone has suggestions on a better way to handle this situation, I would greatly appreciate it. Thank you!