Dropdown div menu with different width in browsers

Asked

Viewed 264 times

3

I dropdown menu and for some reason the width of the div is different in the browsers

The div class is the dropdown-content

Follow the code and prints

.header-menu {
	height: auto;
	float: right;
	font-size: 0;
	margin-right: 20px;
}

.header-menu ul {
  background: #111112;
}

.header-menu ul li {
	height: auto;
	display: inline-block;
}

.header-menu ul li a {
	padding: 20px 12px;
	text-align: center;
	color: #fff;
	font-size: 14px;
	letter-spacing: 0.2px;
	line-height: 70px;
}

.header-menu ul li:hover {
	background: #fd1616; /*Vermelho*/
}

/*Dropdown Menu*/

.dropdown-content {
	display: none;
	position: absolute;
	background: #fd1616;
	width: 119px;
}

.header-menu ul li .dropdown-content a {
	height: 50px;
	padding-left: 20px;
	font-size: 14px;
	letter-spacing: 0.2px;
	line-height: 10px;
  color: #fff;
  display: block;
  text-align: left;
  border-top: solid 1px #111112;
}

.dropdown-content a:hover {
	background: #111112;
}

.dropdown:hover .dropdown-content {
	display: block;
}
<nav class="header-menu">
    <ul>
      <li><a href="ps4.html">PS4</a></li>
      <li><a href="xboxone.html">XBOX ONE</a></li>
      <li><a href="pc.html">PC</a></li>
      <li class="dropdown">
      <a href="outrosconsoles.html">Outros Consoles</a>
      <div class="dropdown-content">
      <a href="#">PS3</a>
      <a href="#">XBOX 360</a>
      <a href="#">WII U</a>
      <a href="#">3DS</a>
      <a href="#">PS Vita</a>
      </div>
      </li>
      <li><a href="esports.html">eSports</a></li>
      <li><a href="reviews.html">Reviews</a></li>
      <li><a href="videos.html">Vídeos</a></li>
    </ul>
</nav>

Chrome and Firefox

inserir a descrição da imagem aqui

Edge

inserir a descrição da imagem aqui

IE

inserir a descrição da imagem aqui

Removing the position: Absolute the width problem has been solved, but this other problem arises...

inserir a descrição da imagem aqui

1 answer

2


The problem is in the position of your menu. You don’t have a parent to handle the submenu. So it looks different in each browser.

I redid your menu:

.header-menu {
  float: left;
  height: 60px;
  width: 100%;
  max-width: 800px;
  background: #111112;
}
.header-menu ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.header-menu ul li {
  line-height: 60px;
  height: 60px;
  display: inline-block;
  padding: 0px 10px;
  text-align: center;
}
.header-menu ul li.dropdown {
  position: relative;
}
.header-menu ul li a {
  color: #fff;
  text-decoration: none;
  font-size: 16px;
  font-family: "Roboto";
  display: block;
}
.header-menu ul li:hover {
  background: #fd1616;
}
/*Dropdown Menu*/

.dropdown-content {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  background: #fd1616;
  width: 100%;
  left: 0;
  top: 120px;
  transition: all 0.25s ease-in;
}
.header-menu ul li .dropdown-content a {
  line-height: 40px;
  height: 40px;
  font-size: 14px;
  color: #fff;
  text-decoration: none;
  display: block;
  text-align: left;
  text-indent: 10px;
  border-top: solid 1px #111112;
}
.dropdown-content a:hover {
  background: #111112;
}
.dropdown:hover .dropdown-content {
  visibility: visible;
  opacity: 1;
  top: 60px;
}
<nav class="header-menu">
  <ul>
    <li><a href="ps4.html">PS4</a>
    </li>
    <li><a href="xboxone.html">XBOX ONE</a>
    </li>
    <li><a href="pc.html">PC</a>
    </li>
    <li class="dropdown">
      <a href="outrosconsoles.html">Outros Consoles</a>
      <div class="dropdown-content">
        <a href="#">PS3</a>
        <a href="#">XBOX 360</a>
        <a href="#">WII U</a>
        <a href="#">3DS</a>
        <a href="#">PS Vita</a>
      </div>
    </li>
    <li><a href="esports.html">eSports</a>
    </li>
    <li><a href="reviews.html">Reviews</a>
    </li>
    <li><a href="videos.html">Vídeos</a>
    </li>
  </ul>
</nav>

See if it works on all browsers.

  • box-sizing forces a different behavior for IE?

  • No. It takes the spaces out and puts them in, so to speak. Even the default spaces that the browser has.

  • Unfortunately did not resolve

  • I’ve gone over your code and I see that the sub has position:absolute, but without a father with position:relative. This is dangerous, there is almost no cross-browser compatibility when it is so. You will have to redo your submenu.

  • I removed the position: Absolute and solved the width problem, but now by hovering the mouse in the submenu, the main menu is positioned next to his last read. Take a look at the print I put up now to better understand

  • 1

    Look at the MENU I made there...

  • I made some modifications to my layout and is working perfectly, thanks!

Show 2 more comments

Browser other questions tagged

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