0
I have a doubt and I would like your help, I already researched a lot and did not find a solution.
I’m trying to position a div over a div. I found some ways to do this on the internet, however, I did not really like the result and would like to know if there is another alternative.
One of the ways I found was to put the position as Absolute and set the top to zero in the second Div. This way, the second Div is over the first Div, however, ends up "escaping / leaking" on the right side, not respecting the first Div.
The following is an example of a code:
(migrated from Jsfiddle)
body{
width: 100%;
height: 100vh;
font-family: "Montserrat", "Helvetica", arial, sans-serif;
font-weight: 600;
text-align: center;
}
.container {
max-width: 100%;
height: 100vh;
/*overflow:hidden;*/
}
.container-fluid {
padding: 0;
}
.primeiro {
max-width: 100%;
height: 100vh;
color: red;
}
.segundo {
max-width: 100%;
height: 100vh;
color: blue;
position: absolute;
top: 0;
}
.terceiro {
max-width: 100%;
height: 100vh;
color: orange;
position: absolute;
top: 0;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Matheus Leandro</title>
<!-- Meta tags Obrigatórias -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- CSS -->
<link rel="stylesheet" href="css/style.css">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="container-fluid">
<div class="primeiro">
<h1>T 1 esteee T 1 esteee T 1 esteee T 1 esteee</h1>
</div>
<div class="segundo">
<h1>T 2 esteee T 2fadfasdfasfasfdfsasff esteee T 2 esteee T 2 esteee</h1>
</div>
<div class="terceiro">
<h1>T 3 esteee T 3 esteefafadfadfafasfse T 3 esteee T 3 esteee</h1>
</div>
</div>
</div>
</div>
</div>
<!-- JavaScript (Opcional) -->
<!-- jQuery primeiro, depois Popper.js, depois Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
Note: the first Div (which should be respected) is with the red letters, if you observe, the second Div (blue) and the third Div (orange) are larger (right side mainly) than the first.