Make menu scrollable on smaller screen - html

My menu is using a series of nested <ul> tags with sub <ul> and <li> within existing <li> calls. This is pretty standard for most menu's are far as I am aware. To make my website work well on mobile devices, I have decided to take a more responsive design approach and use #media query's to show or hide content as the browser is resized.
When my menu is shrunk down, the drop downs are hidden (for now). I will most likely introduce a hamburger type menu later on where you can click on a + icon beside the menu on the mobile version and see it's sub links.
As of right now, when the browser is resized the menu is then ordered as an absolute display and this disables the scrolling on the menu. If a user, say on an iPhone, turns the phone sideways, the menu is then cut off and they cannot scroll down to see the rest of the menu in this orientation. Here is an image to depict the issue:
And here is an example of the nested html code:
<div id="navmenu">
<ul>
<li><div class="home"></div></li>
<li class='storelink dropdown'><a class='dropbtn' href='/store'>Store</a>
<div class='dropdown-content'>
<a href='/store?group=1'>All Items</a>
</div>
</li>
<li class='cartmenu'><a href='/cart'>Cart</a></li>
<li class='accountmenu dropdown'><a class='dropbtn' href='/account'>Account</a>
<div class='dropdown-content'>
<a href='/account'>Customer login</a>
</div>
</li>
<li><a href='/services'>Services</a></li>
</ul>
</div>
and finally the relevant css
#navmenu .dropdown:hover .dropdown-content {
display: block;
position: absolute;
}
#navmenu {
overflow-y: scroll;
display: none;
clear: both;
background: #333;
left: 0;
position: absolute;
float: none;
margin: 0;
padding: 0;
width: 100%;
border-bottom: 2px solid #fff;
}
#navmenu ul {
width: 100%;
text-align: center;
}
#navmenu li {
float: none;
clear: both;
background: #333;
width: 100%;
text-align: center;
}
#navmenu li a {
display: block;
width: 100%;
clear: both;
margin: 0;
padding: 10px 0;
}
Why won't this scroll when resized? Thanks

Try adding this:
#navmenu {
height: 100%;
...
}

Hmm, you can try giving your #navmenu a fixed height.
Alternatively, you can try setting #navmenu to position:fixed (not absolute) and height:100%.

Related

<ul> Background colour won't work. I'm trying to add a background for my page breadcrumbs

I'm trying to add my website breadcrumbs to a list and change the list background to #0765de, i have tried as seen below, only the <li> background will change colour.
I have to change the width of li so the text is in the page so the background cuts off. that's why I need it in ul.
Heres the HTML:
<ul class="breadcrumb_unli">
<li class="breadcrumb_unli">{ include'breadcrumb' }</li>
</ul>
Heres the CSS:
.breadcrumb_unli ul {
width: 100%;
overflow: hidden;
background-color: #0765de;
}
.breadcrumb_unli li {
width: 60%;
color: white;
margin: auto;
margin-top: -30px;
padding: 10px 10px 10px 0px;
}
Any help would be appreciated.
to select a ul with a specific class you should do this:
ul.breadcrumb_unli {
width: 100%;
overflow: hidden;
background-color: #0765de;
}
if it didn't work, try adding display: block or display: inline-block to the ul

Text displays on top of popup menu

I made a simple HTML page with a simple drop-down menu (made with CSS). I have a problem with the drop-down text transparency: it shows the bottom text (as explained in the image below). The text in the menu is a link, so it's included in a tag. I tried to change the text color and opacity property but doesn't solve the problem. Any idea?
.menu {
margin-right: 0px;
margin-left: -40px;
}
li {
display: block;
float: left;
width: 25%;
height: 50px;
line-height: 50px;
font-family: Helvetica, sans-serif;
font-size: 20px;
text-align: center;
color: white;
background-color: #000000;
}
.pat:hover {
color: #EC008C;
}
.l {
width: 100%;
height: 50px;
margin-left: -20px;
}
.sub-menu {
visibility: hidden;
}
.menu .pat:hover .sub-menu {
visibility: visible;
}
<ul class="menu">
<li>Home</li>
<li class="pat">Patenti
<ul class="sub-menu">
<li class="l">Patente A</li>
<li class="l">Patente B</li>
<li class="l">Patenti superiori</li>
</ul>
</li>
<li>News</li>
<li>Contatti</li>
</ul>
Instead of visibility: hidden; and visibility: visible; on hover for submenus, it's better to use display: none and display: block, and use position: absolute on the submenu and position: relative on its parent menu entry.
The reason display: none doesn't take any space (and position: absolute will prevent the visible submenu to change the design of the main menu entries), whereas visibility: hidden; reserves the space for the hidden element and just makes it invisible, which makes it impossible to properly position it independently of objects which it should cover when visible.
Just add position: relative to .menu. It will create a stacking context causing it to appear above body text.
Here is a modified pen. I have rewritten all rules but only the last one is important.

Responsive nav tweak

I'm working on making a responsive menu that by default is displayed inline with the site title. However on mobile the menu needs to display as a list below the site title and it's toggled by hitting a + or -. I've achieved all of this except for two small issues.
I can't seem to get the menu to display relative to the document flow so that it overlaps the text on the pages
I need the menu to be the full width of the page.
I'm not sure if I just need to take this menu and put it in its own div outside of the nav or if I'm just forgetting some css rule. It's currently set up as:
<nav>
<div id="nav-div">
<div id="title"></div>
<div id="menu-toggle"></div>
<div id="nav-links">
<ul>
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
</ul>
</div>
</div>
</nav>
CSS:
#nav-links {
position:absolute;
width:100%;
ul {
}
li {
display:block;
float: none;
border-bottom: 1px solid black;
&:last-child {
border-bottom: none;
}
a {
}
}
}
You need to set top and left properties on #nav-links. And if you set right too, you wont need width: 100%. Also make it position:relative. Like this:
#nav-div {
position: relative;
height: 50px;
}
#nav-links {
position:absolute;
left: 0;
right: 0;
...
}
Change 50px to whatever your navbar height is.
The way I ended up doing this was:
ul {
position: absolute;
width: 100%;
right: 0px;
left: 0px;
li {
width: 100%;
a {
width: #small-width; //defined with my variables
margin: 0px auto;
display: block;
}
}
}

Bootstrap: align element to bottom doesn't work

I have a problem similar to this one:
Bootstrap 3 Align Text To Bottom of Div
Except that its proposed solution doesn't work in my case. My HTML is:
<header class="masthead">
<a class="navbar-brand" href="index.php"><img src="logo.png" alt="My Logo"></a>
<div class="container-fluid">
<div class="navbar-right" id="nav_derecha">
<ul id="lang">
<li><img src="es.png" alt="Español"></li>
<li><img src="en.png" alt="English"></li>
<li><img src="fr.png" alt="Français"></li>
<li><img src="de.png" alt="Deutsch"></li>
</ul>
<ul id="login_area">
Login | Register
</ul>
</div>
</div>
</header>
And my CSS is:
header.masthead {
background-color: #103961;
height: 82px;
margin-bottom: 0px;
box-shadow: none;
}
header.masthead nav {
background: #339966;
border: 0px;
box-shadow: none;
/* max-width: 1100px; */
margin-left: auto;
margin-right: auto;
}
.navbar-brand > img {
width: 270px;
}
#media only screen and ( min-width: 768px ) {
#nav_derecha {
position: relative;
}
#login_area {
position: absolute;
bottom: 0;
right: 0;
}
}
#login_area li a{
color:white !important;
}
#lang li {
display: inline;
}
Using the "position:absolute" trick, the login/register links appear right on top of the language bar. I want the language bar to appear on the upper-right corner, and the login area below it, aligned to the bottom of the header. How can I do this?
I think something like this, is what you are looking for:
.nav-holder{
display:inline-block;
vertical-align:top;
}
#lang{
-webkit-padding-start: 0;
margin:0;
}
http://jsfiddle.net/1w6xr92j/7/
Need to make block elements inline-block elements, so that they sit side by side.
Also, I saw some padding that webkit was putting on the ul by default, so I took that off.
Aligning vertically to the top is all we needed to get the links to sit up at the top.
edit: positioning your masthead relatively, and then your container fluid, absolutely, will contain your links as you want. You can then also set your "right" property so that the container sits however far away from the right side you want.
If you would like anything else clarified, just let me know.
I changed two sections of your CSS to this:
#media only screen and ( min-width: 768px ) {
#nav_derecha {
position: relative;
}
#login_area {
position: absolute;
text-align: right; /* used to say bottom:0; right: 0 -> you can remove this line too, if you wish */
}
}
#login_area{ /* there is no li a inside this ul, so I removed them from the css */
color:white !important;
}
See updated bootply

Horizontal menu not stretching to full width on hover in certain browsers

I have a horizontal menu that is made up of a series of ul's and li's. The submenus look great so I don't need to do anything with those. The primary ul looks great until you hover over the far right li.
When doing that, it looks good in Safari but the hover comes about 2 pixels short of the background on the ul in Firefox and IE and even more in Chrome. I have tried adjusting the padding to make it look good in Firefox and IE but then you still have the same issue in Chrome and in Safari, that far right li breaks down to a new line. Of course, adjusting it to look good in Chrome makes all the other browsers break to a new line. This site is using Wordpress which creates the menu dynamically so I can only change the CSS. Here is the basic idea for the code:
<html>
<head>
<style type="text/css">
#header {
margin: 0 auto;
width: 980px;
}
ul li {
font-size: 13px;
line-height: 21px;
}
#header .main-nav #menu-main-navigation {
background: #169BAC;
width: 100%
}
#header .main-nav > div ul {
width: 100%;
list-style: none;
float: left;
margin: 0;
padding: 0;
vertical-align: baseline;
}
#header .main-nav > div ul li ul{
top: 43px;
}
#header .main-nav .menu-div>ul>li {
padding: 5px 14px;
float: left;
border-right: solid 1px #54AEC2;
}
#header .main-nav .menu-div ul li:hover {
background: #2A588D;
}
#header .main-nav .menu-div>ul>li:first-child {
padding-top: 9px;
height: 28px;
}
#header .main-nav .menu-div>ul>li:last-child {
padding: 5px 26px;
border-right: none;
}
#header .main-nav .menu-div>ul>li a{
line-height: 15px;
text-decoration: none;
color: #FFF;
padding: 0px 13px;
text-align: center;
display: inline-block;
}
</style>
<head>
<body>
<header id="header">
<nav class="main-nav">
<div class="menu-div">
<ul id="menu-main-navigation" class="menu">
<li id="menu-item-275">Home</li>
<li id="menu-item-310">For New<br />Patients</li>
<li id="menu-item-376">Cleanings &<br />Prevention</li>
<li id="menu-item-381">General<br />Dentistry</li>
<li id="menu-item-453">Restore Your<br />Smile</li>
<li id="menu-item-462">Dental Anxiety &<br />Sedation Options</li>
<li id="menu-item-463">Dentistry For<br />Kids</li>
<li id="menu-item-464">Insurance &<br />Payment Options</li>
</ul>
</div>
</nav>
</header>
</body>
You can see the site at http://riverbend.caswellwebcreations.com.
Thank you for any help that you can give me on this.
The width of the li elements is being defined by their padding and the font-size (and padding) of the a elements inside them. The font propertys are not uniform between browsers, some browsers put text bigger or smaller than others. That seems to be the problem.
If you want to stretch the li elements "cross-browser" you should define the width of the li elements via css like this:
#menu-item-275{
width: 64px;
}
#menu-item-310{
width: 77px;
}
#menu-item-376{
width: 96px;
}
#menu-item-381{
width: 82px;
}
#menu-item-453{
width: 104px;
}
#menu-item-462{
width: 131px;
}
#menu-item-463{
width: 105px;
}
#menu-item-464{
width: 132px;
}
If you sum the width of each li item (plus padding and border) you get the width of the menu container: 980px. And the browsers will take that width to render the li's.
I hope this works!
UPDATE
Just found another (and more easy) solution!: https://stackoverflow.com/a/14361778/3762078
#header .main-nav .menu-div>ul>li:last-child {
padding: 5px 20px;
border-right: none;
float: none; /* ADD THIS */
overflow: hidden; /* AND THIS */
}
'float: none'. Forces last li element to be as wide as it can (the
default block element's behavior).
'overflow: hidden'. Prevents the last li element to stretch to ul's full width.
Although this doesn't prevent the width changes to all li elements on every browser, hence making the last li's width be thinner or wider (and sometimes expanding that li's height), is a nice solution.