Aswin Kumar Aswin Kumar - 4 months ago 9
CSS Question

when zooming the page the alignment of div boxes changes and collides

I created 2 div boxes inside the container class. when zooming the page in and out, the alignment of the div boxes gets changed and collide with each other. I attached my html and css. I need the dix boxes to be fixed inside the container class while zooming in and out. I am stuck here.. Any help please?



<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type = "text/css">
*{
margin:0;
padding:0;
font-family:Arial, Helvetica, sans-serif;
}
body{
background-color:#e1e3e4;
}
.main{
width:90%;
margin: 0 auto;
}
header{
height:160px;
background-color:#3c948b;
}
.container{
background-color: #f3f3f3;
min-height:500px;

}
.content{
float:left;
position:relative;
top:10px;
left:10px;
border: 2px solid #111;
width:70%;
}
.panel{
position:relative;
float:left;
top:10px;
left:20px;
border: 2px solid #111;
width:330px;


}
</style>
</head>
<body>
<div class="main">
<header>
<h1>My personal blog</h1>
</header>
<div class="container">
<div class="content">
#content
</div>
<div class="panel">
#panel
</div>

</div>
</div>
</body>
</html>




Answer

How about removing the floats and doing it with a display: table?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type = "text/css">
*{
    margin:0;
    padding:0;
    font-family:Arial, Helvetica, sans-serif;
}
body{
    background-color:#e1e3e4;
}
.main{
    width:90%;
    margin: 0 auto;
}
header{
    height:160px;
    background-color:#3c948b;
}
.container{
    width: 100%;
    display: table;
    background-color: #f3f3f3;
    min-height:500px;
}
.content{
    display: table-cell;
    top:10px;
    border: 2px solid #111;
    width:70%;
}
.panel{
    display: table-cell;
    top:10px;
    border: 2px solid #111;
    width:330px;
}
</style>
</head>
<body>
<div class="main">
	<header>
    	<h1>My personal blog</h1>
	</header>
    <div class="container">
		<div class="content">
			#content
		</div>
		<div class="panel">
			#panel
		</div>
  
   </div>
</div>
</body>
</html>