SupremeLeader
SupremeLeader

Reputation: 59

Overflow:hidden doesn't appear to work

I am creating a responsive menu and use only html and css for this.

But when I try to add content to the site it starts the div in the menu. I already tried to use overflow:hidden on the div around the entire menu but for some reason this doesn't work.

I created another menu and used overflow:hidden on the div around the menu and that worked but sadly can't used it because it has no dropdown menu.

I hope I provided you with enough information to help me other wise just asked! Thanks.

@font-face

{
  font-family: 'Gautami';
  src: url('gautami.ttf');
}
body {
  padding: 0px;
  margin: 0px;
}
#menu {
  width: 100%;
}
/*Strip the ul of padding and list styling*/

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  position: absolute;
}
/*Create a horizontal list with spacing*/

li {
  display: inline-block;
  float: left;
}
/*Style for menu links*/

li a {
  display: block;
  min-width: 140px;
  height: 50px;
  text-align: center;
  line-height: 50px;
  font-family: 'Gautami', Arial;
  color: #2072ba;
  text-decoration: none;
}
/*Hover state for top level links*/

.MenuLink:hover {
  background: #e5e6e8;
}
/*Style for dropdown links*/

li:hover ul a {
  background: #2072ba;
  color: white;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid white;
}
/*Hover state for dropdown links*/

li:hover ul a:hover {
  background: #e5e6e8;
  color: #2072ba;
}
/*Hide dropdown links until they are needed*/

li ul {
  display: none;
}
/*Make dropdown links vertical*/

li ul li {
  display: block;
  float: none;
}
/*Prevent text wrapping*/

li ul li a {
  width: auto;
  min-width: 100px;
  padding: 0 20px;
}
/*Display the dropdown on hover*/

ul li a:hover + .hidden,
.hidden:hover {
  display: block;
}
#right {
  float: right;
}
/*Style 'show menu' label button and hide it by default*/

.show-menu {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-decoration: none;
  color: #2072ba;
  text-align: center;
  padding: 25px 0px 25px 0px;
  display: none;
  width: 100%;
  border-bottom: solid 1px #2072ba;
}
/*Hide checkbox*/

input[type=checkbox] {
  display: none;
}
/*Show menu when invisible checkbox is checked*/

input[type=checkbox]:checked ~ #menu {
  display: block;
}
.content {
  background-color: grey;
  bottom: 0px;
  margin: 0% 10% 0% 10%;
}
/*Responsive Styles*/

@media screen and (min-width: 1201px) {
  #MenuDiv {
    overflow: hidden;
  }
  #menu {
    border-bottom: 1px solid #2072ba;
  }
}
@media screen and (max-width: 1200px)
/*increase your windows size to see my problem or decrease the max width and min width until your can see the large menu*/

{
  #MenuLinkImg {
    display: none;
  }
  /*Make dropdown links appear inline*/
  ul {
    position: static;
    display: none; 
    padding: 0px;
    overflow: hidden;
  }
  /*Create vertical spacing*/
  li {
    border-bottom: solid 1px #2072ba;
  }
  /*Make all menu links full width*/
  ul li,
  li a {
    width: 100%;
  }
  /*Display 'show menu' link*/
  .show-menu {
    display: block;
  }
  #right {
    float: none;
  }
  .content {
    margin: 0px 5% 0% 5%;
  }
}
<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Dropdown menu </title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="DD.css">
    </head>
    <body>
        <div id="MenuDiv">
            <label for="show-menu" class="show-menu">Show Menu</label>
            <input type="checkbox" id="show-menu" role="button">
            <ul id="menu">
                <li><a class="MenuLink" href="#">Home</a></li>
                <li><a class="MenuLink" href="#">Diensten</a></li>
                <li><a class="MenuLink" href="#">Keurmerken</a></li>
                <div id="right">
                    <li>
                        <a class="MenuLink" href="#">Mijn account ↓</a>
                        <ul class="hidden">
                            <li><a class="MenuLinkDD" href="#">Diensten</a></li>
                            <li><a class="MenuLinkDD" href="#">Account informatie</a></li>
                        </ul>
                    </li>   
                    <li><a class="MenuLink" href="#">Inloggen</a></li>
                </div>    
            </ul>
        </div>    
        <div class="content">
            <div id="text">
            testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestttesttest esttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttesttesttesttesttesttestt esttesttesttest testtesttesttesttesttesttestt esttesttest testtesttesttesttesttesttesttesttesttesttesttestte sttesttes ttesttestt esttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttestte sttesttesttesttesttesttesttesttesttesttesttesttesttest
            </div>
        </div> 
    </body>
</html>

Upvotes: 0

Views: 652

Answers (1)

tao
tao

Reputation: 90013

What you want has nothing to do with overflow.

Because on devices wider than 1201px your menu has position:absolute, you are removing it from normal flow of the document. If you don't want it to be rendered overlapping the page content, you need to set a top-padding on your content and place the menu in the provided space:

@media (min-width: 1201px){
  body {
    padding-top: 51px;
  }
  #menu {
    top: 0;
  }
}

@font-face

{
  font-family: 'Gautami';
  src: url('gautami.ttf');
}
body {
  padding: 0px;
  margin: 0px;
}
#menu {
  width: 100%;
}
/*Strip the ul of padding and list styling*/

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  position: absolute;
}
/*Create a horizontal list with spacing*/

li {
  display: inline-block;
  float: left;
}
/*Style for menu links*/

li a {
  display: block;
  min-width: 140px;
  height: 50px;
  text-align: center;
  line-height: 50px;
  font-family: 'Gautami', Arial;
  color: #2072ba;
  text-decoration: none;
}
/*Hover state for top level links*/

.MenuLink:hover {
  background: #e5e6e8;
}
/*Style for dropdown links*/

li:hover ul a {
  background: #2072ba;
  color: white;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid white;
}
/*Hover state for dropdown links*/

li:hover ul a:hover {
  background: #e5e6e8;
  color: #2072ba;
}
/*Hide dropdown links until they are needed*/

li ul {
  display: none;
}
/*Make dropdown links vertical*/

li ul li {
  display: block;
  float: none;
}
/*Prevent text wrapping*/

li ul li a {
  width: auto;
  min-width: 100px;
  padding: 0 20px;
}
/*Display the dropdown on hover*/

ul li a:hover + .hidden,
.hidden:hover {
  display: block;
}
#right {
  float: right;
}
/*Style 'show menu' label button and hide it by default*/

.show-menu {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-decoration: none;
  color: #2072ba;
  text-align: center;
  padding: 25px 0px 25px 0px;
  display: none;
  width: 100%;
  border-bottom: solid 1px #2072ba;
}
/*Hide checkbox*/

input[type=checkbox] {
  display: none;
}
/*Show menu when invisible checkbox is checked*/

input[type=checkbox]:checked ~ #menu {
  display: block;
}
.content {
  background-color: grey;
  bottom: 0px;
  margin: 0% 10% 0% 10%;
}
/*Responsive Styles*/

@media screen and (min-width: 1201px) {
  #MenuDiv {
    overflow: hidden;
  }
  #menu {
    border-bottom: 1px solid #2072ba;
    top: 0;
  }
  body {
    padding-top: 51px;
  }
}
@media screen and (max-width: 1200px)
/*increase your windows size to see my problem or decrease the max width and min width until your can see the large menu*/

{
  #MenuLinkImg {
    display: none;
  }

  /*Make dropdown links appear inline*/
  ul {
    position: static;
    display: none; 
    padding: 0px;
    overflow: hidden;
  }
  /*Create vertical spacing*/
  li {
    border-bottom: solid 1px #2072ba;
  }
  /*Make all menu links full width*/
  ul li,
  li a {
    width: 100%;
  }
  /*Display 'show menu' link*/
  .show-menu {
    display: block;
  }
  #right {
    float: none;
  }
  .content {
    margin: 0px 5% 0% 5%;
  }
}
<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Dropdown menu </title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="DD.css">
    </head>
    <body>
        <div id="MenuDiv">
            <label for="show-menu" class="show-menu">Show Menu</label>
            <input type="checkbox" id="show-menu" role="button">
            <ul id="menu">
                <li><a class="MenuLink" href="#">Home</a></li>
                <li><a class="MenuLink" href="#">Diensten</a></li>
                <li><a class="MenuLink" href="#">Keurmerken</a></li>
                <div id="right">
                    <li>
                        <a class="MenuLink" href="#">Mijn account ↓</a>
                        <ul class="hidden">
                            <li><a class="MenuLinkDD" href="#">Diensten</a></li>
                            <li><a class="MenuLinkDD" href="#">Account informatie</a></li>
                        </ul>
                    </li>   
                    <li><a class="MenuLink" href="#">Inloggen</a></li>
                </div>    
            </ul>
        </div>    
        <div class="content">
            <div id="text">
            testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestttesttest esttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttesttesttesttesttesttestt esttesttesttest testtesttesttesttesttesttestt esttesttest testtesttesttesttesttesttesttesttesttesttesttestte sttesttes ttesttestt esttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte sttesttestte sttesttesttesttesttesttesttesttesttesttesttesttesttest
            </div>
        </div> 
    </body>
</html>

As a side-note, your CSS is way too general. For starters, you don't want all unordered lists in your website to have position:absolute

Upvotes: 1

Related Questions