I have been working on a small web app and the layout breaks up whenever I zoom in or out. I've tried numerous solutions posted on the web and on the forum including using em instead of px units in my css. That did not solve the issue, as the picture below shows. My Board breaks when I zoom in or out
I'd like for the board to look like this on both small and large screens: How The Board Should look like
I'm guessing the problem is with how I have positioned elements, but beyond having a slight idea of where the problem might be, I'm stumped. Can someone point out what might be causing the issue?
Here's the HTML and CSS I'm working with.
.container-fluid{
min-width: 1366px;
max-width: 2048px;
margin: 0px auto;
width: 100%;
}
.brow1 {
position: fixed;
top: 3.125em;
left: 29.375em;
float: right;
}
.brow1>div {
border-right:3px solid #328adb;
display: inline-block;
width: 4rem;
height: 4rem;
justify-content: center;
text-align: center;
background: rgba(255, 255, 255, 0.739);
position:relative;
}
.brow2 {
position: fixed;
top: 3.125em;
right: 3.438em;
}
.brow2>div {
border-bottom:0.188em solid #328adb;
margin-bottom: 0.250em;
display: block;
width: 4rem;
height: 4rem;
justify-content: center;
text-align: center;
background: rgba(255, 255, 255, 0.739);
position:relative;
}
.brow3 {
position: fixed;
bottom: 8.125em;
right: 3.438em;
}
.brow3>div {
border-left:3px solid #328adb;
display: inline-block;
width: 4rem;
height: 4rem;
justify-content: center;
text-align: center;
background: rgba(255, 255, 255, 0.739);
position:relative;
}
.brow4 {
position: fixed;
top: 7.813em;
left: 29.375em;
}
.brow4>div {
border-top:0.188em solid #328adb;
margin-bottom: 0.313em;
display: block;
width: 4rem;
height: 4rem;
justify-content: center;
text-align: center;
background: rgba(255, 255, 255, 0.739);
position:relative;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="">
<meta name="keywords" content="">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<div class="brow1">
<div id="tile_1" class="">1</div>
<div id="tile_2" class="">2</div>
<div id="tile_3" class="">3</div>
<div id="tile_4" class="">4</div>
<div id="tile_5" class="">5</div>
<div id="tile_6" class="">6</div>
<div id="tile_7" class="">7</div>
<div id="tile_8" class="">8</div>
<div id="tile_9" class="">9</div>
<div id="tile_10" class="">10</div>
</div>
<div class="brow2">
<div id="tile_11" class="">11</div>
<div id="tile_12" class="">12</div>
<div id="tile_13" class="">13</div>
<div id="tile_14" class="">14</div>
<div id="tile_15" class="">15</div>
</div>
<div class="brow3">
<div id="tile_25" >25</div>
<div id="tile_24" >24</div>
<div id="tile_23" >23</div>
<div id="tile_22" >22</div>
<div id="tile_21" >21</div>
<div id="tile_20" >20</div>
<div id="tile_19" >19</div>
<div id="tile_18" >18</div>
<div id="tile_17" >17</div>
<div id="tile_16" >16</div>
</div>
<div class="brow4">
<div id="tile_30" >30</div>
<div id="tile_29" >29</div>
<div id="tile_28" >28</div>
<div id="tile_27" >27</div>
<div id="tile_26" >26</div>
</div>
</div>
</body>
<link rel="stylesheet" media="screen and (max-width: 1920px)" href="style.css">
</html>
If you want elements to appear in a specific position, then you are best to use
position:absolute
- you can places things exactly where you want them. This isn't used very often in responsive websites, but your requirements are for a fixed-width display so in this case it is perfect for you.You can create a container that has
position:relative
- that means that the elements we place inside it are relative to it - i.e. they are contained within it and all positions are relative to inside that container.Then for your element, you use
position:absolute
and place them exactly where you want withtop
,left
etc.Now you can place the new container (I gave it the class
brow-container
in the example below) wherever you want it to be, and all of the elements will move as a single unit instead of having to measure the position of each one separately.Working example: FYI I have removed the min-width from
.container-fluid
so you can see it in the snippet window: