Div doesn’t get 100% height

Asked

Viewed 43 times

1

I am doing the content division, and I put to my box to be 100% tall and she does not stay, I wanted to know why ? It only stays when I put it in px

My html

<!DOCTYPE html>
<html>
<head>
  <title>Pagina inicial</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" type="text/css" href="estilo.css">
</head>
<body>
  <div class="conteudo">
    <div class="caixa1">

    </div>
    <div class="caixa2">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div>
  </div>
</body>
</html>

My css

*{margin:0; padding: 0;}
body{font-family: Arial, Helvetica, sans-serif; font-size: 15px;}
.conteudo{
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}
.caixa2{
    width: 80%;
    background-color: red;
}
.caixa1{
    width: 20%;
    /*height: 620px;*/
    height: 100%;
    background-color: #E9F1F2;
}

2 answers

1

Yes, it is the expected, because the percentage acts on a fixed amount say so, then you are doing width: 100% nothing really. One of the ways you can use percentage in the daughters' Ivs is by putting a fixed value to the father’s div:

* {
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
}

.conteudo {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  height: 500px;
}

.caixa2 {
  width: 50%;
  background-color: red;
}

.caixa1 {
  width: 50%;
  /*height: 620px;*/
  height: 100%;
  background-color: green;
}
<div class="conteudo">
  <div class="caixa1">

  </div>
  <div class="caixa2">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </div>
</div>

  • Width or height he wants?

  • height that I wanted

1

An approach would be to put in the class .conteudo a height of 100vh. The measure vh is also relative and is based on viewport. Each vh represents 1% of viewport. Test with the following css:

*{margin:0; padding: 0;}
body{font-family: Arial, Helvetica, sans-serif; font-size: 15px;}
.conteudo{
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    background-color: blue;
    height: 100vh;
}
.caixa2{
    width: 80%;
    background-color: red;
}
.caixa1{
    width: 20%;
    background-color: #E9F1F2;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.