CSS Drop-Down Navigation Links Cramped - html

I'm trying to create a responsive, drop-down CSS menu, and I have a media query that targets mobile devices (760 pixels). I'm trying to make all the links occupy the entire width, and that goes well, but the problem is when I display the drop down menu when the width is less than 760 pixels, all of the links of the drop down menu are cramped into the navigation links. I would like to know how to solve this problem, because I have been thinking for a long time and haven't figured out a solution. I want the drop-down menu for services to be directly below services, and the final contact link to go below the drop-down menu. This is the problem:
Below is the HTML and the CSS, as well as a link to the JSFiddle.
HTML:
<div class="wrapper">
<ul class="links">
<li id="active">home
</li><li>about
</li><li>services
<ul class="links">
<li>web development
</li><li>design templates
</li><li>networking
</li><li>custom builds
</li>
</ul>
</li><li>contact</li>
</ul>
</div>
CSS:
html,
body {
margin: 0;
padding: 0;
font-family: Source Sans Pro, Helvetica, sans-serif;
}
.wrapper {
width: 100%;
height: auto;
}
ul.links {
margin: 0px;
padding: 0px;
list-style: none;
background-color: #EBEBEB;
}
ul.links a {
color: #737373;
text-decoration: none;
}
ul.links ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
}
ul.links li {
background: none;
color: #737373;
display: inline-block;
position: relative;
font-size: 19px;
padding-top: 22px;
padding-bottom: 22px;
padding-left: 35px;
padding-right: 35px;
transition: background 0.2s linear 0s, color 0.2s linear 0s;
-webkit-transition: background 0.2s linear 0s, color 0.2s linear 0s;
}
ul.links ul li {
position: relative;
font-size: 18px;
display: block;
float: left;
width: 100%;
}
ul.links li:hover {
background-color: #6ECFFF;
}
ul.links li:hover ul {
display: block;
}
ul.links li:hover .link {
color: #F0F0F0;
}
ul.links ul li:hover .link2 {
color: #F0F0F0;
}
#active {
background-color: #6ECFFF;
}
#active a {
color: #F0F0F0;
}
#media screen and (max-width: 760px) {
ul.links li
{
width: 100%;
}
ul.links ul {
position: absolute;
left: 0;
}
ul.links ul li {
background: #EBEBEB;
}
}
JSFiddle: https://jsfiddle.net/7tkn7zzs/

You should make ul.links ul { to position: relative; in media query to display it proper.
ul.links ul {
position: relative;
left: 0;
}
Working Fiddle

ul.links ul {
position: relative;
left: -35px; /* equal to padding left */
}

Related

Disappearing mobile navbar in wordpress

My wordpress website (mustafasprojects.com) is missing its mobile navbar when I pull it up in wordpress. It is there in the html file when I inspect it but I cannot get the same navbar to appear in wordpress. as far as my html code it's the standard navbar stuff.
<header id="header">
<h1>Mustafa's Projects</h1>
<nav id="nav">
<ul>
<li>Home</li>
<li>My Work</li>
</ul>
</nav>
</header>
#header {
position: fixed;
z-index: 10000;
left: 0;
top: 0;
width: 100%;
background: rgba(255, 255, 255, 0.95);
height: 3em;
line-height: 3em;
box-shadow: 0 0 0.15em 0 rgba(0, 0, 0, 0.1);
animation: 1s ease-out 0s 1 SlideInFromTop;
}
#header h1 {
height: 3em;
left: 1em;
line-height: 3em;
margin: 0;
padding: 0;
position: absolute;
top: -.225em;
font-size: 1.2em;
}
#header h1 a {
color: #000
font-size: 1.1em;
border: 0;
}
#header nav {
position: absolute;
right: 0.5em;
top: .525em;
height: 1em;
line-height: 1em;
vertical-align: middle;
}
#header nav ul {
margin: 0;
}
#header nav ul li {
display: inline-block;
margin-left: 0.5em;
font-size: 0.95em;
}
#header nav > ul > li a {
display: inline-block;
height: 1.7em;
line-height: 1.7em;
padding: 0 .3em;
border-radius: 6px;
}
#header nav > ul > li a:not(.button) {
color: #000;
display: inline-block;
text-decoration: none;
border: 0;
}
#header nav > ul > li a:not(.button).icon:before {
color: #999;
margin-right: 0.5em;
}
#header nav > ul > li a:hover:not(.active) {
background-color: #266dd3;
}
#header nav > ul > li:first-child {
margin-left: 0;
}
#header nav > ul > li.active a:not(.button) {
background-color: rgba(153, 153, 153, 0.25);
}
#header nav > ul > li .button {
margin: 0 0 0 0.5em;
position: relative;
}
#media screen and (max-width: 736px) {
#header {
height: 2.5em;
line-height: 2.5em;
}
#header h1 {
text-align: center;
position: relative;
left: 0;
top: 0;
height: 2.5em;
line-height: 2.5em;
}
#header h1 a {
font-size: 1em;
}
#header nav {
display: none;
}
}
.header.onload-header-fade-down {
transform: 0.75s ease-in-out;
transition: opacity .75s ease-in-out, transform .75s ease-in-out;
}
So yeah if anyone can help me solve the case of the missing navbar it would be much appreciated. It doesn't appear in the tablet or mobile view on wordpress but it appears in the tablet/mobile view on the inspector btw.
Thanks
You are hiding the header at screen widths smaller than 840px:
#media screen and (max-width: 840px)
#header {
display: none;
}
on line 2906 of your html file.
Actually, something really bad is going on, as you have a duplicate <header id="header"> element.
If you look at your Media query, you're hiding the nav bar in any screen size under 736px.
#media screen and (max-width: 736px) {
#header nav {
display: none;
}
}
If you remove that, you will then see your nav bar. Depending on what the rest of your code looks like, you will either have to >
1) Remove the whole #header nav line from your max-width query
or
2) Change it to display:block.
I am not sure what the rest of your code looks like or what your trying to accomplish, but either of those will work.

Underline hover is underlining extra

Here's the code I have problem with my underline hover effect its exppanding extra how to fix it please help me out ************************
HTML
<div class="nav-wrap">
<ul class="group" id="example-one">
<li>Home</li>
<li><a class="dropbtn">Models</a>
<ul class="dropdown-content">
<li></li>
<li>Audi</li>
<li>Bmw</li>
<li>Mercedes</li>
</ul>
</li>
<li>Offers</li>
<li>Group Sales</li>
<li>Reviews</li>
</ul>
</div>
And also i want my dropdown in the middle of his parent And here its*********
CSS
.nav-wrap {
background: white;
width: 100%;
}
#example-one {
text-align: right;
}
#example-one li {
text-align: left;
position: relative;
display: inline-block;
font-family: 'Montserrat', sans-serif;
top:-20px;
}
#example-one a {
color: #000;
font-weight: bold;
font-size: 14px;
padding: 15px 15px;
text-decoration: none;
position: relative;
color: #000;
}
#example-one a:after {
color: #333;
content: '';
position: absolute;
width: 0;
height: 3px;
display: block;
margin-top: 2px;
right: 0;
background: #000;
transition: width all 1s ease;
-webkit-transition: width 1s ease;
}
#example-one a:hover:after {
width: 100%;
left: 0;
background: #000;
}
.dropdown-content {
display: none;
position: absolute;
top: 30px;
left: 0;
background-color:white;
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
}
#example-one li li {
display: block;
}
#example-one li:hover>ul {
display: block;
}
If I understand your problem correctly, the issue is with the dropdown items not being centered and the dropdown underline being too long. I believe this issue is caused by the padding on the dropdown div.
To resolve this, add some normalised padding to your .dropdown-content class:
.dropdown-content {
padding: 0 20px;
}
let the underline be attached to the text it self not to all the list item so it takes the width of just the text, now it takes the width of the whole cell in the list

Why aren't nav bar buttons centered?

I have the code there
My question is, why aren't the buttons for different pages centered? This is more obvious when the site is minimized.
nav.stroke ul li a,
nav.fill ul li a {
position: relative;
}
nav.stroke ul li a:after,
nav.fill ul li a:after {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after {
width: 100%;
}
nav.fill ul li a {
transition: all 2s;
}
nav.fill ul li a:after {
text-align: left;
content: '.';
margin: 0;
opacity: 0;
}
nav.fill ul li a:hover {
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after {
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
h1,h3 {
text-align: center;
color: white;
}
li{
list-style-position: inside;
display: inline;
padding-left: 12px;
}
a{
padding: .2em .1em;
color:grey;
background-color: ;
}
}
.xy{
margin-top: 75px;
}
h1{
font-size: 45px;
}
h3{
font-size: 23px;
}
body{
background-color: #451255;
}
nav {
width: 70%;
margin: 0 auto;
background: #fff;
padding: 15px;
box-shadow: 0px 5px 0px #dedede;
position: center;
}
nav ul {
list-style: none;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul li a {
display: block;
padding: 15px;
text-decoration: none;
color: #aaa;
font-weight: 800;
text-transform: uppercase;
margin: 0 10px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before {
transition: all .5s;
}
nav ul li a:hover {
color: #555;
}
#-webkit-keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #451255;
}
}
.btns,
.fill{
margin: auto;
position: center;
display: block;
}
So, I have that code, you can see on the link what it looks like. My problem is that it's not centered. And when I minimize it, the fact that it's not centered is more obvious. How could I fix that?
like #junkfoodjunkie already said, it's about basic CSS reset.
why? elements got initial CSS set, this is what's going on:
like you can see, your menu's items (blue part) are already centered but you've got initial -webkit-padding-start: 40px; (green part) and it's do the same as padding-left: 40px;, it takes not less than 40px from your menu so that's why it looks like the menu's items are not centered/stick to the right, so in order to fix it you need to overwrite the value of the <ul> element.
you're also set the <li> elements to padding-left: 12px; so the menu's items will not be centered perfectly. if you're not going to use some CSS reset then add .fill > ul {padding-left: 0;} to your CSS.
You're not resetting or eliminating default behavior. You have no margin or padding defined on the <ul>, and you have not reset the CSS to begin with, so there is a default padding and margin messing with you. Put margin: 0; padding: 0; on your <ul> and it should work.
Or, just do a full brutal reset: https://jsfiddle.net/efv8x1x2/1/
Added
* {
margin: 0;
padding: 0;
}
to the beginning of the stylesheet, and voila, centered.

Making navbar link filled while on current page

I am currently trying to create a navbar that fills when hovered over a link. However, I would also like to have the link filled (or highlighted) while on the relative page. Any help would be much appreciated!
Note: This code has been retrieved from an open source.I am new learner of web technologies and working for a web project.
/*NAVIGATION */
body {
font-family: 'Roboto', sans-serif;
padding: 0;
margin: 0;
}
small {
font-size: 12px;
color: rgba(0, 0, 0, 0.4);
}
h1 {
text-align: center;
padding: 50px 0;
font-weight: 800;
margin: 0;
letter-spacing: -1px;
color: inherit;
font-size: 40px;
}
h2 {
text-align: center;
font-size: 30px;
margin: 0;
font-weight: 300;
color: inherit;
padding: 50px;
}
.center {
text-align: center;
}
section {
height: 100vh;
}
nav {
width: 60%;
margin: 0 auto;
background: #fff;
padding: 10px 0;
box-shadow: 0px 5px 0px #dedede;
}
nav ul {
list-style: none;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul li a {
display: block;
padding: 15px;
text-decoration: none;
color: #aaa;
font-weight: 800;
text-transform: uppercase;
margin: 0 10px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before {
transition: all .5s;
}
nav ul li a:hover {
color: #555;
}
/* stroke */
nav.stroke ul li a,
nav.fill ul li a {
position: relative;
}
nav.stroke ul li a:after,
nav.fill ul li a:after {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after {
width: 100%;
}
nav.fill ul li a {
transition: all 2s;
}
nav.fill ul li a:after {
text-align: left;
content: '.';
margin: 0;
opacity: 0;
}
nav.fill ul li a:hover {
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after {
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
/* Keyframes */
#-webkit-keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #333;
}
}
<section style="background: #2ecc71; color: rgba(0, 0, 0, 0.5);">
<h2>Nav bar test</h2>
<nav class="fill">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Downloads
</li>
<li>More
</li>
<li>Contact
</li>
</ul>
</nav>
</section>
The best practice is just to add an "active" class to the current page button.
<li>Home</li>
And add "a.active" to every "a:hover" that you already have so it has the same css.
nav.fill ul li a:hover,
nav.fill ul li a.active { /* Here */
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after,
nav.fill ul li a.active:after { /* Here */
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
nav.stroke ul li a:hover:after,
nav.stroke ul li a.active:after { /* Here */
width: 100%;
}
Here is an jsfiddle live example: https://jsfiddle.net/884o5sjs/
(To get help faster, remember to create your own jsfiddle next time)
You could add the class="active" to the current page dynamically with php (suggested) or even with jQuery (not suggested), but since it looks like you are using ".html" you will have to add it manually on each page.
Hope this helps.
Looks like you've already achieved your first task of having it highlight when hovered. I would do this in php because that's the language I'm most comfortable, but then you'd also have to run a web server on your computer so hopefully you get some more helpful tips from some of the Jscript pros on here. If you do have to resort to php, one way I commonly do this is by having a variable on the page that lets the header know what page you're on, and then a few if statements that coorespond and apply a .current-page style.
I'm probably doing it the long way, but I just haven't learned Javascript yet.
the if statement would look like this within the li of the ul of the nav... <li <?php if ($title == "Home) { echo "class='current-page'"; } ?>>Home and so on for each element in the ul with the corresponding title, and title declarations in the body of the page.

Need help to understand. I can't totally control the transition property

Here is the deal. I'm trying to create a mobile first navigation bar using css3, html5 and transition properties. I've been successful so far but I am unable to control the transition for when I resize the window (using media queries min-width) from desktop view to mobile view. I've add a Toggle button in the mobile view to create a burger menu that disappears at 600px and vice versa. when the button is unchecked (menu not visible) and I resize the view from desktop to mobile there is a very fast transition that I don't want. I've tried so far so many variants and nothing seems to work. Any suggestion would be greatly appreciated!
* {
margin: 0;
padding: 0;
outline: none;
box-sizing: border-box;
}
body {
background: #eee;
color: #444;
-webkit-font-smoothing: antialiased;
font-family: Arial, sans-serif;
font-weight: 400;
height: auto !important;
height: 100%;
min-height: 100%;
text-rendering: optimizeLegibility;
}
header {
display: block;
background-color: #FFF;
height: inherit;
}
nav {
text-align: center;
line-height: 3.5em;
}
nav ul {
background-color: rgba(255, 255, 255, 0.15);
float: none;
line-height: inherit;
margin: 0;
}
nav ul li {
display: block;
list-style-type: none;
}
nav ul li:hover {
background-color: #ededed;
}
nav ul li a {
text-decoration: none;
color: #313131;
}
nav ul li a:hover {
color: #b9b5b5;
}
#menuToggle {
display: none;
}
.menu {
width: 100%;
position: absolute;
top: 66px;
transition: all 300ms ease-in-out;
}
.menu-icon {
float: right;
color: #2f2f2f;
cursor: pointer;
padding-top: 0.46em;
padding-right: 1em;
padding-left: 1em;
padding-bottom: 0.46em;
text-decoration: none;
font-size: 30px;
}
.menu {
max-height: 0;
transition-property: max-height 0s ease-in-out;
overflow: hidden;
}
#menuToggle:checked ~ header .menu {
max-height: 300px;
transition-property: all 0.6s ease-in-out;
}
#logo {
float: none;
text-align: left;
padding-top: 7px;
padding-left: 2em;
height: inherit;
}
/*------------ MEDIUM BIG SCREEN -----------------------*/
#media screen and (min-width:600px) {
#logo {
float: left;
}
.menu {
position: relative;
top: -70px;
height: 100%;
max-height: 100%;
transition-property: none;
}
.menu-icon {
display: none;
}
header {
height: 70px;
background-color: #FFF;
margin: auto;
width: 100%;
}
nav {
width: 100%;
}
nav ul {
background-color: #FFF;
display: block;
float: right;
padding: 0.55em 2em 0 0;
height: inherit;
}
nav ul li {
display: inline-flex;
}
nav ul li:hover {
background-color: #FFF;
}
nav ul li a {
padding: 0 2em;
}
<!-- === MENUTOGGLE === -->
<input type="checkbox" name="checkbox" id="menuToggle" value="value">
<label for="menuToggle" class="menu-icon">☰</label>
<!-- ==== HEADER ==== -->
<header class="header">
<div id="logo">
<h1><img src="images/logo.png" alt="Hello"></h1>
</div>
<nav class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog </li>
<li>Contact</li>
</ul>
</nav>
</header>
Put everything you only want to happen on the small screen inside:
#media screen and (max-width:599px) {
}
And everything you only want to happen on the large screen inside your:
#media screen and (min-width:600px) {
}