Home > Net >  How to extend div to bottom of the screen
How to extend div to bottom of the screen

Time:09-20

I am trying to create a side menu, but div won't extend to the bottom of the screen. If I try to put position: absolute or fixed, it works, but then my content gets beneath the menu. Also by putting position:relative

@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
body {
  height: 100%;
  width: 100%;
  background: #1F1E1E;
  font-family: 'Roboto', sans-serif;
  margin: 0;
  padding: 0;
}

.nav-menu {
  height: 100%;
  width: 200px;
  position: relative;
  font-family: verdana;
  font-size: 12px;
  font-weight: 200;
  background-color: #2e353d;
  color: white;
  float: left;
  margin: 0px;
  padding: 0px;
}

.nav-menu .brand {
  background-color: #23282e;
  line-height: 50px;
  display: block;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: #ff5500;
  text-shadow: 0 0 0 #ff5500;
  -webkit-animation: loading 1.5s ease-in-out infinite alternate;
}

@-webkit-keyframes loading {
  to {
    text-shadow: 20px 0 70px #1f2938;
    color: #03e9f4;
  }
}

.nav-menu .menu-btns {
  list-style: none;
  margin: 0px;
  line-height: 35px;
  cursor: pointer;
}

.btn {
  padding-left: 0px;
  border-left: 3px solid #2e353d;
  border-bottom: 1px solid #23282e;
}

.btn:hover {
  border-left: 3px solid #d19b3d;
  background-color: #4f5b69;
}

.menu-btns .tab-label {
  text-decoration: none;
  color: #e1ffff;
}

.tab-item,
.tab-content-container .tab-item:target~.tab-item {
  display: none;
}

.tab-item {
  width: calc(100% - 40px);
  max-width: 100%;
}

.tab-content-container .tab-item:target,
.tab-item:last-child {
  display: block;
}
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>test</title>
  <link rel="stylesheet" type="text/css" href="assets/css/style.css">
</head>

<body>
  <div >
    <div >
      <span >T</span>
      <span >E</span>
      <span >S</span>
      <span >T</span>
      <span >I</span>
      <span >T</span>
    </div>
    <div >
      <div >
        <a  href="#tab-content1">1</a><br>
      </div>
      <div >
        <a  href="#tab-content2">2</a><br>
      </div>
      <div >
        <a  href="#tab-content3">3</a><br>
      </div>
      <div >
        <a  href="#tab-content4">4</a><br>
      </div>
    </div>
  </div>
  <div >
    <div  id="tab-content1">
      <p>Tab 1</p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
    </div>

    <div  id="tab-content2">
      <p>Tab 2</p>
      It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    </div>

    <div  id="tab-content3">
      <p>Tab 3</p>
      It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </div>

    <div  id="tab-content4">
      <p>Tab 3</p>
      It was popularised in the 1960s with the release of 212312 sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </div>
  </div>
</body>

my menu for some reason gets lower than top of the screen. Is there something I'm missing?

I have been at this problem for hours, and can't figure it out.

CodePudding user response:

Try vh "viewport height" instead of %:

.nav-menu {
  height: 100vh;
  width: 200px;
  position: relative;
  font-family: verdana;
  font-size: 12px;
  font-weight: 200;
  background-color: #2e353d;
  color: white;
  float: left;
  margin: 0px;
  padding: 0px;
}

See the following snippet:

@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');


body {
  height: 100%;
  width: 100%;
    background: #1F1E1E;
    font-family: 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
}

.nav-menu {
  height: 100vh;
  width: 200px;
  position: relative;
  font-family: verdana;
  font-size: 12px;
  font-weight: 200;
  background-color: #2e353d;
  color: white;
  float: left;
  margin: 0px;
  padding: 0px;
}

.nav-menu .brand {
  background-color: #23282e;
  line-height: 50px;
  display: block;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: #ff5500;
  text-shadow: 0 0 0 #ff5500;
  -webkit-animation: loading 1.5s ease-in-out infinite alternate;
}

@-webkit-keyframes loading {
  to {
    text-shadow: 20px 0 70px #1f2938;
    color: #03e9f4;
  }
}


.nav-menu .menu-btns {
  list-style: none;
  margin: 0px;
  line-height: 35px;
  cursor: pointer;
}

.btn{
  padding-left: 0px;
  border-left: 3px solid #2e353d;
  border-bottom: 1px solid #23282e;
}

.btn:hover {
  border-left: 3px solid #d19b3d;
  background-color: #4f5b69;
}

.menu-btns .tab-label {
  text-decoration: none;
  color: #e1ffff;
}


.tab-item,
.tab-content-container .tab-item:target ~ .tab-item{display: none;}
.tab-item{
    width: calc(100% - 40px);
    max-width: 100%;
}
.tab-content-container .tab-item:target,
.tab-item:last-child{display: block;}
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>test</title>
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
</head>
<body>  
    <div >
        <div >     
            <span >T</span>
            <span >E</span>
            <span >S</span>
            <span >T</span>
            <span >I</span>
            <span >T</span>
        </div>
        <div >
            <div >
                <a   href="#tab-content1">1</a><br>
            </div>
            <div >
                <a   href="#tab-content2">2</a><br>
            </div>
            <div >
                <a   href="#tab-content3">3</a><br>
            </div>
            <div >
                <a   href="#tab-content4">4</a><br>
            </div>
        </div>
    </div>
    <div >
        <div  id="tab-content1">
            <p>Tab 1</p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        </div>
    
        <div  id="tab-content2">
            <p>Tab 2</p>
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
        </div>
    
        <div  id="tab-content3">
            <p>Tab 3</p>
    It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        </div>
    
        <div  id="tab-content4">
                <p>Tab 3</p>
        It was popularised in the 1960s with the release of 212312 sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        </div>
    </div>
</body>
</html>

CodePudding user response:

A table or series of tables may be the way to go.

  • Related