How to make superfish dropdown menu responsive?

前端 未结 5 1214
感动是毒
感动是毒 2020-12-01 04:59

I am using superfish dropdown menu with skelton framework. I wanted it to work on mobiles as well. By default its showing the dropdown items but it hover over the items belo

5条回答
  •  广开言路
    2020-12-01 05:20

    As Ed pointed out it seems problematic to solve all the different superfish/css issues for a responsive menu.

    After looking through the options here and elsewhere I found a Pure CSS responsive menu which has been quicker and easier to modify than superfish, and does not have the overheads of jquery or javascript. It also has second level menus.

    I checked the demo with screenfly to check responsiveness and mobile layout before using it. The CSSscript.com version (link above) gives a horizontal responsive layout for mobiles, unlike the codepen demo page.

    The code is in a single HTML file which you can easily split into a linked CSS file, only 2 media queries manage the responsive changes and even then only with minimal changes. The '+' symbols can be deleted without issues.

    Only one tiny downside: the first link downloads a HTML has a javascript at the bottom adding obvious google analytics tracking, easily removed and not on codepen.

    Explanation author andor nagy - code from codepen

    /* CSS Document */
    
    @import url(http://fonts.googleapis.com/css?family=Open+Sans);
    @import url(http://fonts.googleapis.com/css?family=Bree+Serif);
    
    body {
    	background: #212121;
    	font-size:22px;
    	line-height: 32px;
    	color: #ffffff;
    	word-wrap:break-word !important;
    	font-family: 'Open Sans', sans-serif;
    	}
    
    h1 {
    	font-size: 60px;
    	text-align: center;
    	color: #FFF;
    }	
    
    h3 {
    	font-size: 30px;
    	text-align: center;
    	color: #FFF;
    }
    
    h3 a {
    	color: #FFF;
    }
    
    a {
    	color: #FFF;
    }
    
    h1 {
    	margin-top: 100px;
    	text-align:center;
    	font-size:60px;
    	font-family: 'Bree Serif', 'serif';
    	}
    
    #container {
    	margin: 0 auto;
    	max-width: 890px;
    }
    
    p {
    	text-align: center;
    }
    
    #relatedContent {
      max-width: 800px;
      margin: 200px auto;
    }
    
    #relatedContent .item {
      max-width: 44%;
      padding: 3%;
      float: left;
      text-align: center;
    }
    
    #relatedContent .item a img {
      max-width: 100%;
    }	
    
    nav { 
    	margin: 50px 0;
    	background-color: #E64A19;
    }
    
    nav ul {
    	padding:0;
    	margin:0;
    	list-style: none;
    	position: relative;
    	}
    	
    nav ul li {
    	display:inline-block;
    	background-color: #E64A19;
    	}
    
    nav a {
    	display:block;
    	padding:0 10px;	
    	color:#FFF;
    	font-size:20px;
    	line-height: 60px;
    	text-decoration:none;
    }
    
    nav a:hover { 
    	background-color: #000000; 
    }
    
    /* Hide Dropdowns by Default */
    nav ul ul {
    	display: none;
    	position: absolute; 
    	top: 60px;
    }
    	
    /* Display Dropdowns on Hover */
    nav ul li:hover > ul {
    	display:inherit;
    }
    	
    /* Fisrt Tier Dropdown */
    nav ul ul li {
    	width:170px;
    	float:none;
    	display:list-item;
    	position: relative;
    }
    
    /* Second, Third and more Tiers	*/
    nav ul ul ul li {
    	position: relative;
    	top:-60px; 
    	left:170px;
    }
    
    	
    /* Change this in order to change the Dropdown symbol */
    li > a:after { content:  ' +'; }
    li > a:only-child:after { content: ''; }

    Pure CSS Drop Down Menu

    A simple dropdown navigation menu made with CSS Only. Dropdowns are marked with a plus sign ( + )

    Read tutorial here

提交回复
热议问题