Move links to list menu when mediascreen size is changed

Asked

Viewed 55 times

1

I’m having a hard time putting some links inside another link.

For example:

#menu_header_right{
float:right;
}
.dropdown{
	width:80px;
	position: relative;
    display: inline-block;}
    		
.dropdown-content {
	display: none;
    position: absolute;
    right:0px;
	top:55px;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);}

.dropdown-content a {
	color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;}

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

.dropdown:hover .dropdown-content {
	display: block;}
<div id="menu_header_right">
	<a class="anunciar"   href="pg_anunciar.php"/>Anuciar Imóvel</a>
	<a class="entrar"     href="pg_logout.php"/>Logout</a>
	<a id="pg_inicial_perfil" href="pg_perfil.php"/></a>
	<a class="entrar"     href="pg_login.php"/>Login</a>
	<a class="criarconta" href="pg_cadastro_usuario.php"/>Criar Conta</a>
	<div class="dropdown">
	  <a class="menu_header_right"  href="pg_cadastro.php"/>Menu</a>
  	  <div class="dropdown-content">
  	  	<a href="#">Link 1</a>
	    <a href="#">Link 2</a>
	    <a href="#">Link 3</a>
	    
	  </div>
	</div>
</div>

The idea is that when resizing the screen all the links are inside the "menu" link along with the link1, Link2 and link3. I appreciate any idea or direction.

  • Is it a bootstrap? Want to do some effect?

  • @Williamasimilar to Andino No, not very simple thing... I just need to do the same movement... Then I cake some effects....

1 answer

1

From what I understood the only thing that is missing is to apply the media-query, in this case you can use a basic Meria-query only for width, however you need to choose the "maximum width" to apply the effect (or at least, it depends on the desired order):

In this case we will assume (by I tested) that the minimum width to use the dropdown version would be 360px (the average width of the #menu_header_right), so you can use something like:

@media (max-width: 360px) {
    /* seu estilo aqui */
}

#menu_header_right{
    float:right;
}
#menu_header_right a {
     display: inline-block;
}
.dropdown{
    width:80px;
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right:0px;
    top:55px;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

#menu_header_right .dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
 }

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

.dropdown:hover .dropdown-content {
    display: block;
}

@media (max-width: 360px) {
    #menu_header_right{
        float: none;
    }
    #menu_header_right a{
        display: block;
    }

    .dropdown{
        width: auto;
        position: relative;
        display: block;
    }

    .dropdown-content {
         display: block;
         position: static;
    }

    #menu_header_right a.menu_header_right {
        display: none;
    }
}
<div id="menu_header_right">
	<a class="anunciar"   href="pg_anunciar.php"/>Anuciar Imóvel</a>
	<a class="entrar"     href="pg_logout.php"/>Logout</a>
	<a id="pg_inicial_perfil" href="pg_perfil.php"/></a>
	<a class="entrar"     href="pg_login.php"/>Login</a>
	<a class="criarconta" href="pg_cadastro_usuario.php"/>Criar Conta</a>
	<div class="dropdown">
	  <a class="menu_header_right"  href="pg_cadastro.php"/>Menu</a>
  	  <div class="dropdown-content">
  	  	<a href="#">Link 1</a>
	    <a href="#">Link 2</a>
	    <a href="#">Link 3</a>
	    
	  </div>
	</div>
</div>

Note that all elements within the media-query overwrite the initial properties:

#menu_header_right{
    float: none;
}
#menu_header_right a{
    display: block;
}

.dropdown{
    width: auto;
    position: relative;
    display: block;
}

.dropdown-content {
     display: block;
     position: static;
}

And this is a "special case":

#menu_header_right a.menu_header_right {
    display: none;
}

Use only:

.menu_header_right {
    display: none;
}

The rule #menu_header_right a will have priority, because the Ids and more descriptive rules usually have a higher priority in the "cascade", then either you use more descriptive #menu_header_right a.menu_header_right following the highest value rule, or using !important.

In case I put a display: none; because if the links are vertical and visible, the menu will not be necessary.

To understand more about the priorities I recommend these links:

  • So, I have the mediaqueries set up here, the penalty is on display:None. How to give a None display in the links Advertise/Log in/Log in/Create account when the media is reached and play these links along with the links 1,2,3, ie I want that when getting mobile for example just look like the link menu and inside the others, I don’t know if I’m expressing myself as were to be understood...

  • My question is whether I will need other "ids" for the same links that I am setting display:None, or if there is any way to do without this Gambi... I don’t know with js or php...

  • @Magichat copies the HTML and CSS I posted, puts it in a new clean html file, then opens it in the browser and resizes the width of the window until it is less than 360px, is that in Stacksnippet there is no way to simulate the effect :/

  • So, manow, it has the same effect when you put the snippet on the full screen, that is, the link menu goes away, and the links Hover automatically open, but that’s not the point. The goal is to disappear "Announce/Login/Logout/Create account" and only get "Menu" and when Hover "Menu" opens with the links already it plus the 4 that are gone, check?

  • @Magichat that toggle menu?

Browser other questions tagged

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