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>
Related
Right now whenever you hover one of the <a> elements a div transitions from left to right under the hovered element, however, when I stop hovering it disappears instantly instead of hovering back. How can I make it so it hovers back to it's original position?
What I have so far is this:
*, *:after, *:before {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-decoration: none;
list-style-type: none;
color: rgba(0, 0, 0, 0.8);
}
.links {
display: flex;
font-size: 1.1em;
font-weight: 500;
text-align: center;
}
.links a {
display: flex;
justify-content: center;
align-items: center;
margin: 0px 30px;
padding: 10px 0 10px 0;
position: relative;
}
.links a:after{
content: '';
position: absolute;
width: 0;
height: 4px;
display: block;
margin-top: 25px;
right: 0;
background: #fff;
transition: width .2s ease;
-webkit-transition: width .3s ease;
}
.links a:hover:after{
width: 100%;
left: 0;
background: rgba(0, 0, 0, 0.8);
}
<div class='links'>
<a href=''>
<p>AAAAAAAAAAAAAAAA</p>
</a>
<a href=''>
<p>AAAAAAAAAAAAAAAA</p>
</a>
<a href="">
<p>AAAAAAAAAAAAAAAA</p>
</a>
</div>
Here is a solution, try this.
.footer_menu {
padding: 30px 0 0;
}
.footer_menu ul {
padding: 0;
text-align: left;
margin-bottom: 0;
list-style: none;
}
.footer_menu ul.bottom-menu {
margin-bottom: 20px;
}
.footer_menu ul li {
margin-bottom: 10px;
list-style: none;
}
.footer_menu ul li a {
text-decoration: none;
color: #666666;
padding-bottom: 3px;
position: relative;
-webkit-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.footer_menu ul li a::before {
content: '';
position: absolute;
bottom: -3px;
left: 0;
right: 100%;
height: 2px;
background: #e5e5e5;
-webkit-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
visibility: hidden;
}
.footer_menu ul li a:hover {
color: #000000;
}
.footer_menu ul li a:hover::before {
left: 0;
right: 0;
background: red;
visibility: visible;
}
<div class="footer_menu">
<ul>
<li>test test</li>
<li>test test</li>
</ul>
<div>
You cas use ease-in by default and on :hover ease-out
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/
I have a task to create a drop-down menu and i create it with using absolute and negative value but i can change my mind i want to create a drop-down without using absolute there is any possibility to create and how can do it kindly help in this query
.mainmenu {
position: relative;
cursor: pointer;
display: inline-block;
padding: 15px;
-webkit-transition: all .5s;
}
.submenu {
position: absolute;
height: 0px;
opacity: 0;
-webkit-transition: all .5s;
}
.mainmenu:hover {
border: 1px solid #000;
-webkit-transition: all .5s;
}
.mainmenu:hover .submenu {
border: 1px solid #000;
padding: 50px;
height: auto;
top: 100%;
left: -1px;
opacity: 1;
-webkit-transition: all .5s;
}
.mainmenu:hover .hide_line {
height: 5px;
width: 100%;
position: absolute;
top: 100%;
right: 0px;
background: #fff;
z-index: 1000;
}
<div class="mainmenu">
Menu
<div class="hide_line">
</div>
<div class="submenu">
submenu
</div>
</div>
You can use list for this purpose
.mainmenu a{
text-decoration:none;
color:#000000;
}
.mainmenu {
position: relative;
cursor: pointer;
display: inline-block;
padding: 15px;
-webkit-transition: all .5s;
list-style:none;
}
.mainmenu > li{
padding-left:0px;
margin-left:0px;
}
.submenu {
opacity:0;
list-style:none;
}
.mainmenu:hover .submenu {
border: 1px solid #000;
height: auto;
opacity: 1;
-webkit-transition: all .5s;
}
.submenu li{
padding-left:0px;
margin-left:0px;
}
<ul class="mainmenu">
<li><a href='#'>Main Menu</a>
<ul class="submenu">
<li><a href='#'>Sub menu</a></li>
</ul>
</li>
</ul>
I hope you can do rest of the formatting
I am having a ton of trouble. I am trying to create a drop down menu from 'about' and have not been able to center the menu correctly. It is always right of the menu. I believe it to have to do with the size of 'about'.
How can I fix this?
.nav-main {
position: absolute;
top: 0;
height: 65px;
width: 100%;
text-align: center;
}
.nav-main ul {
position: relative;
margin: 0 auto;
padding: 0;
list-style: none;
font-size: 22px;
line-height: 100%;
font-family: 'Futura W01 Bold', sans-serif;
text-align: center;
text-transform: uppercase;
display: inline-block;
width: 90%;
height: inherit;
}
.nav-top {
position: relative;
margin: 0;
padding: 0 66px 0 50px;
float: none;
display: inline-block;
list-style: none;
height: inherit;
background: transparent url(../images/nav-divide.png) no-repeat right center;
}
.nav-top:first-child {
padding-left: 0;
}
.nav-top:last-child {
background-image: none;
padding-right: 0;
}
.nav-top > a {
position: relative;
display: block;
margin: 0;
color: #6f6f6f;
text-decoration: none;
padding-top: 20px;
padding-bottom: 5px;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.nav-top a:hover,
.nav-top.active a {
color: #454545;
border-bottom: 4px solid #00e9d9;
text-decoration: none;
}
.nav-top ul {
display: none;
position: absolute;
}
.nav-top:hover ul {
display: inline;
}
.nav-top li {
float: center;
background-color: #e9e9e9;
}
.nav-top li > a {
position: relative;
display: inline;
margin: 0;
color: #6f6f6f;
text-decoration: none;
padding-top: 20px;
padding-bottom: 5px;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
<nav class="nav-main" role="navigation">
<ul>
<li class="nav-top">Welcome</li>
<li class="nav-top">About
<ul>
<li>Services</li>
<li>Clients</li>
<li>Press</li>
<li>Leadership</li>
<li>Twitter</li>
</ul>
</li>
<li class="nav-top">Contact</li>
</ul>
<span class="nav-arrow"></span>
</nav>
Andrews:
To solve you problem, you need to indicate the position of your nested list because you are setting it up as "position: absolute" without coordinates.
Add a "left value" to your UL CSS class in order to solve this issue:
.nav-top ul {
display: none;
position: absolute;
left: 0;
}
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;
}