Move menu items to left when search box expands - html

I have a search box which expands to the left when click on it. But the links next to the search box should also move to left when the search box will expand.
This is the code I am working on
JsFiddle example
<nav class="header-menu">
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li class="search-wrap">
<input class="search" type="search" placeholder="Search"></li>
</ul>
</nav>
.header-menu ul li {
display: inline-block;
vertical-align: middle;
}
.search-wrap {
width: 175px;
position: relative;
height: 27px;
vertical-align: middle;
display: inline-block;
}
.search {
border: 1px solid #ccc;
padding: 5px 7px;
margin-left: 15px;
width: 175px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
transition: all .5s ease;
position: absolute;
right: 0;
top: 0;
}
.search:focus {
width: 225px;
}
Currently on clicking the search box it will expand to the left but menu items are not moving to left.
How can I fix it. Any help or suggestion would be appreciated .
Thanks in advance

You need to use the text-align : right for parent UL
.header-menu ul {
text-align:right;
}
.header-menu ul li {
display: inline-block;
vertical-align: middle;
}
.search-wrap {
width: 175px;
position: relative;
height: 27px;
vertical-align: middle;
display: inline-block;
border: 1px solid #ccc;
margin-left: 15px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
transition: all .5s ease;
}
.search {
border: none;
padding: 5px 7px;
width: 100%;
}
.search-wrap:focus-within {
width: 225px;
}
If you need some absolute positioning then you can use positioning for nav element and not the li or inner elements.
see this fiddle
https://jsfiddle.net/qz1m5hub/

Related

Vertical Align Before Pseudo List Item

So I made a custom before pseudo line and I'm trying to figure out how to vertically align it center to my list items. How does one do that? I tried absolute positioning but it stacks all of them and places them in the middle rather than them being on each list item.
.menu {
background: #ececec;
width: 200px;
margin-top: 40px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 20px;
transition: 0.5s all ease-in-out;
}
.menu li {
padding: 10px 0;
cursor: pointer;
}
.menu ul {
position: relative;
}
.menu li:before {
content: '';
height: 30px;
width: 3px;
background-color: #FE715D;
left: -10px;
position: absolute;
border-radius: 20px;
opacity: 0;
transition: 0.5s all ease-in-out;
}
.menu li:hover:before {
transition: 0.5s all ease-in-out;
opacity: 1;
}
<div class="menu">
<ul>
<li class="lifirst">About Me</li>
<li class="limenu">My Skills<li class="limenu">Portfolio</li>
<li class="limenu">Contact</li>
</ul>
</div>
To prevent the stacking of the pseudo elements, you have to set a position for their corresponding parent.
absolute
The element is removed from the normal document flow; no space is created for the element in the page layout. Instead, it is positioned relative to its closest positioned ancestor if any
—position on MDN
In other words: If you add position: relative; to your <li> elements, every pseudo elements position is depending on its corresponding list item:
.menu {
background: #ececec;
width: 200px;
margin-top: 40px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 20px;
transition: 0.5s all ease-in-out;
}
.menu li {
padding: 10px 0;
cursor: pointer;
position: relative;
}
.menu ul {
position: relative;
}
.menu li:before {
content: '';
height: 30px;
width: 3px;
background-color: #FE715D;
left: -40px;
top: 7px;
position: absolute;
border-radius: 20px;
opacity: 0;
transition: 0.5s all ease-in-out;
}
.menu li:hover:before {
transition: 0.5s all ease-in-out;
opacity: 1;
}
<div class="menu">
<ul>
<li class="lifirst">About Me</li>
<li class="limenu">My Skills</l<li class="limenu">Portfolio</li>
<li class="limenu">Contact</li>
</ul>
</div>

Space on the right end of menu bar

I'm new to HTML and CSS, and this is my first project.
I have this "space" near the end of the navbar and it forces the next link to break into a new line. Also, I cannot find a solution that removes the gap between the background image and the navbar no matter the screen size.
I'm not able to pinpoint what is causing these problems, and I'm sure it's just some petty mistake.
navbar http://prntscr.com/g0xi6z
.topnavhome nav {
position: relative;
display: block;
margin: 0px;
background-color: #333333;
overflow: hidden;
text-align: justify;
font-size: 0px;
min-width: 500px;
width: 100%;
}
.topnavhome:after {
content: '';
display: inline-block;
width: 100%;
}
.topnavhome .li {
display: inline-block;
}
.topnavhome nav li a {
float: left;
display: block;
padding: 12px;
width: 180px;
margin-bottom: -1.5px;
color: #f2f2f2;
border-left: solid 3px #333333;
text-align: center;
text-decoration: none;
font-family: 'Lato', sans-serif;
font-size: 20px;
-webkit-transition: background .3s linear;
-moz-transition: background .3s linear;
-ms-transition: background .3s linear;
-o-transition: background .3s linear;
transition: background .3s linear;
}
.topnavhome nav a:hover {
background-color: #046A78;
color: white;
border-left: solid 3px #79CBD6;
-moz-transition: background-color 0.01s;
-webkit-transition: background-color 0.01s;
-o-transition: background-color 0.01s;
transition: background-color 0.01s;
}
<ul class="topnavhome" id="myTopnav">
<nav>
<li>Home</li>
<li>Network Security</li>
<li>Passwords</li>
<li>Firewalls</li>
<li>Encryption</li>
<li>Biometric Devices</li>
<li>References</li>
</nav>
</ul>
Fix Error:
* {
box-sizing: border-box;
}
More css for setting nav use :
.topnavhome {
padding: 0;
}
And define height for nav and a element.
body, ul {
margin:0;
}
* {
box-sizing: border-box;
}
.topnavhome {
padding: 0;
}
.topnavhome nav {
position: relative;
display: block;
margin: 0px;
background-color: #333333;
overflow: hidden;
text-align: justify;
font-size: 0px;
min-width: 500px;
width: 100%;
height: 90px;
}
.topnavhome:after {
content: '';
display: inline-block;
width: 100%;
}
.topnavhome li {
display: inline-block;
}
.topnavhome nav li a {
float: left;
display: block;
padding: 12px;
width: 180px;
margin-bottom: -1.5px;
color: #f2f2f2;
border-left: solid 3px #333333;
text-align: center;
text-decoration: none;
font-family: 'Lato', sans-serif;
font-size: 20px;
-webkit-transition: background .3s linear;
-moz-transition: background .3s linear;
-ms-transition: background .3s linear;
-o-transition: background .3s linear;
transition: background .3s linear;
height: 90px;
}
.topnavhome nav a:hover {
background-color: #046A78;
color: white;
border-left: solid 3px #79CBD6;
-moz-transition: background-color 0.01s;
-webkit-transition: background-color 0.01s;
-o-transition: background-color 0.01s;
transition: background-color 0.01s;
}
<ul class="topnavhome" id="myTopnav">
<nav>
<li>Home</li>
<li>Network Security</li>
<li>Passwords</li>
<li>Firewalls</li>
<li>Encryption</li>
<li>Biometric Devices</li>
<li>References</li>
</nav>
</ul>
About a "space" near the end of the navbar which forces the next link to break into a new line, you have this problem cause there is not enough place to fit in, you need to use "#media queries", so that when you would reduce width it would fit nicely. For example on my screen I do not have such problem
Here are a link for good examples of using #media-query
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
And next, you have your <ul> height greater than <nav> in it. And the reason why expanding height of nav wouldn't help is that you have content after your <ul>, which is taking a gap place after nav.
just delete that line:
.topnavhome:after {
content: ''; <------- delete this one
display: inline-block;
width: 100%;
}
you have fixed width of 180px to .topnavhome nav li a which making the li to stack down as they doesn't fit in the container width.
Try using flex which will equally divide the width to li
nav { display: flex;}
nav li { flex: 1;}
Please try below code.
Here your css is not working well it's due to all li element's are not fitting in container due to this reason displaying in new line.
Just add below classes.if it's already their then update the properties.
ul#myTopnav {
-webkit-padding-start: 5px;
}
Here i have only made changes in width & padding.
.topnavhome nav li a {
padding: 12px 6px 12px 6px;
width: 172px;
}
One more thing is used #media query if it's not fitting in small screen or larger screen.
Hope this helps.

CSS Hover on list item seems to be affecting all list items within ul

I'm having an issue on my menu items.
I have my menu items styled so whenever I hover over a list item, it dims the hovered item.
However, whenever I hover on one list item, it seems to be affecting and dimming all list items.
I narrowed down the problem. It works perfectly fine when my menu-bar-container div is positioned relative. However, I want this menu-bar-container div to be fixed.
Anyone know what seems to be the issue? Appreciate the help in advance.
Here is the HTML:
<div id="menu-bar-container">
<h1> GENE WONG OFFICIAL PAGE </h1>
<div class="clear"> </div>
<div id="menu-bar-2">
<ul>
<li class="fade">HOME</li>
<li class="fade">NEWS</li>
<li class="fade">BIOGRAPHY</li>
<li class="fade">MEDIA</li>
<li class="fade">PROJECTS</li>
<li class="fade active">GEAR</li>
<li class="fade">CONTACT</li>
</ul>
</div>
</div>
and here's the CSS:
#menu-bar-container {
background: url(images/hp/header-bg.png);
min-width: 100%;
height: 110px;
margin: 0 auto;
text-align: center;
border-bottom: 1px solid #2F2F2F;
position: fixed;
z-index: 10;
}
#menu-bar-2 {
display: inline-block;
margin: 0 auto;
height: 32px;
max-width: 100%;
}
#menu-bar-2 ul {
list-style-type: none;
overflow: auto;
margin: 0;
padding: 0;
padding-top: 4px;
height: 30px;
}
#menu-bar-2 li {
float:left;
}
#menu-bar-2 li a {
display: block;
text-decoration: none;
padding: 0px 10px;
font-size: 15px;
top: 10px;
color: white;
}
#menu-bar-2 li.active a {
color:#E20000;
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: .7;
}

Adding a margin messing up display of drop-down menu

The issue I'm having is that when I add a margin to my hover over drop down navmenu it messes up all the content which was meant to drop down and clusters it all up nearly just above it. Although before adding a margin the navigation menu worked perfectly fine, and yes removing the margin fixes the issue but I need to add a margin.
Here is my CSS, let me know if you need the HTML also. (Note, I am doing this on Notepad++ as HTML >4<)
#navmenu a {
text-decleration: none;
display: block;
width: 124px;
height: 27px;
line-height: 25px;
background-color: ;
border: 1px solid #CCC;
border-radius: 5px;
font-family: Magneto;
font-size: 20px;
color: ffffff;
transition: ease-in all 400ms;
-moz-transition: ease-in all 300ms;
-webkit-transition: ease-in all 300ms;
-o-transition: ease-in all 300ms;
margin: -40px;
}
#navmenucontainer {
margin: 15px;
margin-left: 10px;
width: 230px;
height: auto;
float: left;
}
Here is the Relevent HTML:
<div id="navmenucontainer">
<ul id="navmenu">
<li>
Menu
<ul>
<li>Education
</li>
<li>Hobbies
</li>
<li>Interests
</li>
</ul>
</li>
</ul>
</div>
demo - http://jsfiddle.net/victor_007/fajLeLsy/
it looks like you want to do something like this
don't give -margin for a
#navmenu a {
text-decleration: none;
display: block;
width: 124px;
height: 27px;
line-height: 25px;
background-color: ;
border: 1px solid #CCC;
border-radius: 5px;
font-family: Magneto;
font-size: 20px;
color: ffffff;
}
#navmenucontainer {
margin: 15px;
width: 230px;
height: auto;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
ul li:hover ul {
opacity: 1;
visibility: visible;
}
ul li ul {
opacity: 0;
visibility: hidden;
transition: ease-in all 400ms;
-moz-transition: ease-in all 300ms;
-webkit-transition: ease-in all 300ms;
-o-transition: ease-in all 300ms;
}
<div id="navmenucontainer">
<ul id="navmenu">
<li> Menu
<ul>
<li>Education
</li>
<li>Hobbies
</li>
<li>Interests
</li>
</ul>
</li>
</ul>
</div>

How to make CSS Dropdown menu slidedown

I created a CSS menu with dropdown and I hide the sub menu and display it when you hover over the menu item and I was wondering if it is possible with CSS with some type of CSS transition to make it instead slide down. You cake take a look at a mock up of the menu here.
#main-nav {
position: relative;
}
#main-nav>ul>li {
width: 12.5%;
float: left;
text-align: center;
line-height: .9em;
font-weight: bold;
background: #ccc;
}
#main-nav>ul>li>a {
display: block;
color: #333;
line-height: 12px;
font-size: 14px;
padding: 22px 0;
text-decoration: none;
}
.nav-dropdown {
margin: -5px auto;
position: absolute;
left: -999em;
/* Hides the drop down */
text-align: left;
padding: 0;
border-top: 0;
width: 500px;
background: #333;
color: #f2f2f2;
border-bottom: 10px solid #25272a;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
#main-nav li:hover .nav-dropdown {
left: 0;
top: auto;
z-index: 11;
}
<div id="main-nav">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3
<!-- Start Blog Drop Down-->
<div class="nav-dropdown">
<p>have this item slide down from CSS</p>
</div>
<!-- /.nav-dropdown -->
</li>
</ul>
</div>
Yes you can, but you need to use the max-height property as described here or you can just use a fixed height as described in the previous answer.
CSS
.nav-dropdown {
margin: 0 auto;
height: 0; /* Hides the drop down */
overflow: hidden;
text-align:left;
padding: 0;
border-top: 0;
width: 500px;
background:#333;
color: #f2f2f2;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
border-bottom: 0;
max-height:0px;
}
#main-nav li:hover .nav-dropdown {
height:auto;
z-index: 11;
max-height:200px;
transition-property: all;
transition-duration: 1s;
border-bottom: 10px solid #25272a;
}
http://jsfiddle.net/L8WVP/7/
This might also be of your interest.
That should help you. Just give the div tag which should slide in the hight 0 at first and make the css transition.
-webkit-transition: height 0.5s ease-in;
-moz-transition: height 0.5s ease-in;
-o-transition: height 0.5s ease-in;
-ms-transition: height 0.5s ease-in;
transition: height 0.5s ease-in;
Then you add at the hover section the hight of the div.
#main-nav li:hover .nav-dropdown {
left: 0;
top: auto;
z-index: 11;
height:200px;
}
And you are done.
Hope I helped you.
http://jsfiddle.net/L8WVP/6/
<ul class="navigation">
<li>Home</li>
<li class="menu">
Services
<ul class="submenu">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul>
ul {
padding: 0;
margin: 0;
list-style: none;
}
ul li a {
text-decoration: none;
color: #e74c3c;
font-family: Tahoma, Arial;
}
.navigation {
background-color: a#e74c3c;
width: 75%;
margin: 20px auto;
min-height: 50px;
}
.navigation > li {
float: left;
padding: 0 20px;
}
.navigation > li > a {
line-height: 50px;
color: #FFF;
}
.navigation .menu {
position: relative
}
.navigation .menu .submenu {
position: absolute;
width: 200px;
-webkit-box-shadow: 0px 1px 1px #CCC;
box-shadow: 0px 1px 1px #CCC;
display: none;
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
}
.navigation .menu:hover .submenu {
display: block
}
.navigation .menu .submenu:before {
content: "";
position: absolute;
display: block;
border-width: 0 6px 6px 6px;
border-style: solid;
border-color: #FFF transparent;
top: -6px;
left: 5px
}
.navigation .menu .submenu li {
padding: 5px 10px;
-webkit-transition: all .5s ease-in-out;
-moz-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
}
.navigation .menu .submenu li:hover {
background-color: #e74c3c;
}
.navigation .menu .submenu li:hover a {
color: #FFF;
padding: 0 11px;
}