I have a little problem with floating.
I need to display my links side by side with 20px margin, but it does not work.
CSS
ul li{
float:left;
display: inline-block;
position:relative;
padding:0 20px;
}
.link {
font-family: Tahoma;
font-size:18px;
overflow: hidden;
padding: 2px 0;
position: absolute;
cursor:pointer;
}
.link a{
text-decoration:none;
color:gray;
-webkit-transition: color 0.4s ease;
}
.link span {
position: inherit;
left:-100%;
bottom: 1px;
height: 1px;
width:100%;
background: #fb6f5e;
-webkit-transition:all 0.4s;
}
.link a:hover{
color:#fb6f5e;
}
.link:hover span {
overflow:hidden;
position: inherit;
bottom: 1px;
left:100%;
height: 1px;
width:100%;
background: #fb6f5ee;
-webkit-transition:all 0.4s;
}
HTML
<ul>
<li><div class="link">Start<span></span></div></li>
<li><div class="link">About<span></span></div></li>
<li><div class="link">Other<span></span></div></li>
<li><div class="link">Contact<span></span></div></li>
</ul>
http://jsfiddle.net/SD58Z/727/
This should do the trick:
Demo
Your link was set to position absolute so it was outside the flow of elements. Meaning all elements ended on top of each other.
You were also having some unclosed div tags and other html errors.
I moved some things around in the html to make it work. I do think this can be optimized. The reason why the underline hover effect did not work was because of my changes in the html structure (which I think is what you intended in the first place).
css
ul{
padding-left:0px;
}
ul li{
float:left;
display: block;
margin-left:20px;
position:relative;
color:inherit;
}
ul li:first-child{
margin-left:0px;
}
.link {
font-family: Tahoma;
font-size:18px;
overflow:hidden;
cursor:pointer;
}
.link a{
text-decoration:none;
color:gray;
-webkit-transition: color 0.4s ease;
position:relative;
overflow:hidden;
}
.link a:hover{
color:#fb6f5e;
}
.link span {
position: absolute;
left:-100%;
bottom: 1px;
height: 1px;
width:100%;
background: #fb6f5e;
-webkit-transition:all 0.4s;
}
.link:hover span {
bottom: 1px;
left:0%;
height: 1px;
width:100%;
background: #fb6f5ee;
-webkit-transition:all 0.4s;
}
Html:
<ul>
<li>
<div class="link">
<a href="#">Start
<span></span>
</a>
</div>
</li>
<li>
<div class="link">
<a href="#">About
<span></span>
</a>
</div>
</li>
<li>
<div class="link">
<a href="#">Other
<span></span>
</a>
</div>
</li>
<li>
<div class="link">
<a href="#">Contact
<span></span>
</a>
</div>
</li>
</ul>
You have a ton of syntax issues
extra </div> tags
Improper tag order: <a><div></a></div> should be <a><div></div></a>
Incorrect Hex code for background color on <span> in CSS
You are trying to float items and also absolute position them. Pick one or the other.
Using this CSS (i deleted 2 lines of code) it works fine.
JSFIDDLE: http://jsfiddle.net/SD58Z/725/
ul li{
float:left;
display: inline-block;
padding:0 20px;
}
.link {
font-family: Tahoma;
font-size:18px;
overflow: hidden;
padding: 2px 0;
cursor:pointer;
}
.link a{
text-decoration:none;
color:gray;
-webkit-transition: color 0.4s ease;
}
.link span {
position: inherit;
left:-100%;
bottom: 1px;
height: 1px;
width:100%;
background: #fb6f5e;
-webkit-transition:all 0.4s;
}
.link a:hover{
color:#fb6f5e;
}
.link:hover span {
overflow:hidden;
position: inherit;
bottom: 1px;
left:100%;
height: 1px;
width:100%;
background: #fb6f5ee;
-webkit-transition:all 0.4s;
}
With your HTML fixed: http://jsfiddle.net/SD58Z/732/
I just played with your code for a minute and fixed the HTML. There seems to be some useless CSS but this gets you going.
HTML
<ul class="nav">
<li><div class="link">Start<span></span></div></li>
<li><div class="link">About<span></span></div></li>
<li><div class="link">Other<span></span></div></li>
<li><div class="link">Contact<span></span></div></li>
</ul>
CSS
#nav {
width: 100%;
display: block;
}
ul li{
float:left;
display: inline-block;
padding:0 20px;
}
.link {
font-family: Tahoma;
font-size:18px;
overflow: hidden;
padding: 2px 0;
cursor:pointer;
}
.link a{
text-decoration:none;
color:gray;
-webkit-transition: color 0.4s ease;
}
.link span {
position: inherit;
left:-100%;
bottom: 1px;
height: 1px;
width:100%;
background: #fb6f5e;
-webkit-transition:all 0.4s;
}
.link a:hover{
color:#fb6f5e;
}
.link:hover span {
overflow:hidden;
position: inherit;
bottom: 1px;
left:100%;
height: 1px;
width:100%;
background: #fb6f5ee;
-webkit-transition:all 0.4s;
}
Related
I've been working on a navigation bar. I've got it styled the way I like, but for some reason am having issues getting submenus to work.
The code looks like:
<div id="head">
<input id="toggle" type="checkbox">
<label for="toggle" class="icon">
<div><!-- --></div>
<div><!-- --></div>
<div><!-- --></div>
</label>
<div id="nav">
<div>
<ul>
<li class="page_item page-item-8">Home</li>
<li class="page_item page-item-10 page_item_has_children">About
<ul class="children">
<li class="page_item page-item-22 page_item_has_children">Once More
<ul class="children">
<li class="page_item page-item-23 page_item_has_children">Another Sub Page
<ul class="children">
<li class="page_item page-item-25">Final Link</li>
<li class="page_item page-item-24">Something Else</li>
</ul>
</li>
</ul>
</li>
<li class="page_item page-item-21">Another Page</li>
<li class="page_item page-item-20">Subpage</li>
</ul>
</li>
<li class="page_item page-item-13 current_page_item">Shop</li>
<li class="page_item page-item-9">FAQ</li>
<li class="page_item page-item-11">Contact</li>
</ul>
</div>
</div>
</div>
The CSS looks like:
/* Toggle */
#toggle {
display: none;
}
/* Nav */
#nav li.current_page_item a {
background: #d2b48c;
border-radius: 40px;
color: #260f03;
}
#nav li a {
border-bottom: 1px solid transparent;
border-top: 1px solid transparent;
color: #fff;
display: inline-block;
font-family: 'Lato', sans-serif;
font-size: 14px;
letter-spacing: 4px;
margin: 20px;
padding: 10px 10px 10px 15px;
text-decoration: none;
text-transform: uppercase;
}
/* Media */
#media screen and (max-width: 600px) {
/* Icon */
.icon {
background: #260f03;
margin: 0 auto;
padding: 20px 20px 30px;
position: absolute;
width: 100%;
z-index: 500;
}
.icon div {
background: #d2b48c;
border-radius: 3px;
height: 2px;
margin: 10px auto 0;
position: relative;
transition: all 0.3s ease-in-out;
width: 3em;
}
/* Toggle */
#toggle:checked + .icon div:nth-child(1) {
margin-top: 25px;
transform: rotate(-45deg);
}
#toggle:checked + .icon div:nth-child(2) {
margin-top: -2px;
transform: rotate(45deg);
}
#toggle:checked + .icon div:nth-child(3) {
opacity: 0;
transform: rotate(45deg);
}
#toggle:checked + .icon + #nav {
top: 0;
transform: scale(1);
}
/* Nav */
#nav {
background: rgba(38, 15, 3, 0.95);
bottom: 0;
height: 100%;
left: 0;
overflow: hidden;
position: fixed;
right: 0;
top: -100%;
transform: scale(0);
transition: all 0.3s ease-in-out;
z-index: 200;
}
#nav div {
height: 100%;
overflow: hidden;
overflow-y: auto;
position: relative;
}
#nav ul {
padding-top: 90px;
text-align: center;
}
#nav li a:before {
background: #fff;
content: '';
height: 0;
left: -0.5em;
position: absolute;
transition: all 0.2s ease-in-out;
width: 0.25em;
}
#nav li a:hover:before {
height: 100%;
}
}
#media screen and (min-width: 601px) {
/* HIDE the dropdown */
#nav li ul { display: none; }
/* DISPLAY the dropdown */
#nav li:hover > ul {
display: block;
position: absolute;
}
/* Nav */
#nav ul {
background: #260f03;
font-size: 0;
text-align: center;
}
#nav li {
display: inline;
}
#nav li a:hover {
border-bottom: 1px solid #d2b48c;
border-top: 1px solid #d2b48c;
}
}
JS Fiddle (with submenus):https://jsfiddle.net/2v8zhL3e/1/
JS Fiddle (without submenus): https://jsfiddle.net/b0mj7gp4/
I've found a bunch of tutorials on how to do this, but they are all using a float on the li.
I did have a go at it...
I hid the dropdown: #nav li ul { display: none; }
Then I showed it on hover:
#nav li:hover > ul {
display: block;
position: absolute;
}
Which kind of works...but the links show to the left of the main navigation item, I'd like to just tweak this so the links are stacked and show centered under their corresponding header.
I feel like I'm close, can anyone point me in the right direction?
Thanks,
Josh
You can add display: flex to the li:hover ul, then make the flex-direction: column and make the non-hover event position: absolute, left: 0. This creates an issue with the ul child element floating to the far left. So to fix this issue, you need to style its parent to have a relative position. The following should do the trick.
#nav li {
position: relative;
}
#nav li ul {
left: 0;
position: absolute;
}
#nav li:hover > ul {
display: flex;
flex-direction: column;
}
You haven't position: relative in li.
And, it would be better to use position: absolute without hover, in default.
#nav li {
position: relative;
}
#nav li > ul {
position: absolute;
display: none;
}
#nav li:hover > ul {
display: block;
}
How can I get this navigation bar to center?
The class menu I suppose is built in with bootstrap.min.css.
#header {
position: fixed;
width: 100%;
z-index: 999;
}
#header .header-content {
margin: 0px auto;
max-width: 1170px;
padding: 60px 0;
width: 100%;
-moz-transition: padding 0.4s;
-o-transition: padding 0.4s;
-webkit-transition: padding 0.4s;
transition: padding 0.4s;
}
.navigation {
float: right;
}
.navigation li {
display: inline-block;
}
.navigation a {
color: white;
font-size: 15px;
font-weight: bold; /* Normal - Bold - 400 */
margin-left: 30px;
letter-spacing: 4px;
text-transform: uppercase;
}
.navigation a:hover, .navigation a.active {
color: white;
}
<header id="header">
<div class="menu">
<div class="header-content clearfix">
<nav class="navigation" role="navigation">
<ul>
<li><a data-scroll href="#sec1">Inicio</a></li>
<li><a data-scroll href="#sec2">UEFA</a></li>
<li><a data-scroll href="#sec4">Equipo</a></li>
<li><a data-scroll href="#sec3">Contacto</a></li>
</ul>
</nav>
Menu<span></span>
</div>
</div>
</header>
If you remove the float: right from .navigation and you set text-align: center to that div you can center it.
https://codepen.io/anon/pen/BmBPej
I'm trying to achieve this
social icons hover effect
The dark background should moves down and fill the box on mouse over. This works perfectly when I use no background for the parent container but the hover effect goes behind the parent container when a background image is used.
Screenshot: not showing when bg image set for parent container
and I can see the effect when an opacity value is set for the parent container.
I've tried using negative z-index for the parent but not working for some reason.
My code
.hero {
background: url('http://lorempixel.com/output/abstract-q-g-640-480-3.jpg') no-repeat;
background-size: cover;
height: 550px;
padding: 40px 10px;
/*opacity :0.5; Works in Background*/
}
.social-icons {
}
.social-icons li {
display: inline-block;
font-weight: bold;
text-transform: uppercase;
color: #fff;
padding: 60px 5px 5px 60px;
text-decoration: none;
position: relative;
border: 3px solid #000;
overflow: hidden;
transition: all .5s linear;
}
.social-icons li:hover {
color: #000;
}
.social-icons li:hover:before {
left: -55px;
}
.social-icons li:before {
content: "";
position: absolute;
top: 0;
left: -280px;
background: #000;
height: 100%;
width: 250px;
transform: skew(-50deg);
z-index: -1;
transition: all .5s linear;
}
.social-icons li a {
color: #000000;
display:block;
}
.social-icons li:hover a {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<section class="hero">
<div class="container">
<div class="row">
<div class="social-icons">
<ul>
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-google-plus"></i></li>
<li><i class="fa fa-youtube-play"></i></li>
</ul>
</div>
</div>
</div>
</section>
Do like this, give the anchor a a position, i.e. position: relative and remove the z-index.
I also adjusted your li:before/li:hover:before rules a little, so the transition work both ways.
.hero {
background: url('http://lorempixel.com/output/abstract-q-g-640-480-3.jpg') no-repeat;
background-size: cover;
height: 550px;
padding: 40px 10px;
/*opacity :0.5; Works in Background*/
}
.social-icons {
}
.social-icons li {
display: inline-block;
font-weight: bold;
text-transform: uppercase;
color: #fff;
padding: 60px 5px 5px 60px;
position: relative;
border: 3px solid #000;
overflow: hidden;
}
.social-icons li:hover {
color: #000;
}
.social-icons li:before {
content: "";
position: absolute;
top: 0;
left: 280px;
background: #000;
height: 100%;
transform: skew(-50deg);
width: 250px;
transition: left .2s linear;
}
.social-icons li:hover:before {
left: -20px;
transition: left .2s linear;
}
.social-icons li a {
position: relative;
color: #000000;
display:block;
}
.social-icons li:hover a {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<section class="hero">
<div class="container">
<div class="row">
<div class="social-icons">
<ul>
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-google-plus"></i></li>
<li><i class="fa fa-youtube-play"></i></li>
</ul>
</div>
</div>
</div>
</section>
Right now the parent menu has an opacity shift on hover, this is being transferred to the sub menu (current & previous) as well. I want the sub menu to have a clear background so that the opacity band of the parent is the only thing that is visible. Is there a way to use an li class for the submenu that makes it exempt from the li class that is governing the parent. I've been trying different things but can't seem to make it work properly.
Demo
HTML
<div>
<ul id="mainmenu">
<li class="liHome">
<a class="maintextcolour" href="#item-x1y1" id="Home" rel=
"none">INFO</a>
</li>
<li class="liServices">
<a class="maintextcolour" href="#item-x1y2" id="Services" rel=
"SubMenuY2">EXHIBITIONS</a>
<ul class="submenu" id="SubMenuY2">
<li class="sub1">
<a class="maintextcolour" href="#">CURRENT</a>
</li>
<li class="sub1">
<a class="maintextcolour" href="#">PREVIOUS</a>
</li>
</ul>
</li>
<li id="liEnvironment">
<a class="maintextcolour" href="#item-x1y3" id="Environment"
rel="none">CV</a>
</li>
<li id="liCareer">
<a class="maintextcolour" href="#item-x1y4" id="Career" rel=
"none">NEWS</a>
</li>
<li id="liContact">
<a class="maintextcolour" href="#item-x1y5" id="Contact" rel=
"none">MORE</a>
</li>
</ul>
</div>
CSS:
#charset UTF-8;
/* CSS Document */
body {
background-color: #666;
background-size: 100%;
background-repeat: no-repeat;
}
#mainmenu {
margin: 0;
padding: 0;
list-style-type: none;
position: relative;
}
#mainmenu li {
clear: left;
position: relative;
}
#mainmenu a {
display: block;
overflow: hidden;
float: left;
width: 100%;
position: relative;
opacity: 1;
-webkit-transition: all .4s ease-in-out;
padding-left: 20px;
}
#mainmenu li:hover a {
background-position: 0 0;
background-color: clear;
background-color: rgba(255,255,255,0.5);
width: 100%;
opacity: 0;
-webkit-transition: none;
}
#mainmenu li.active a {
background-position: 0 0;
background-color: clear;
width: 100%;
}
.submenu {
list-style-type: none;
float: left;
display: none;
position: absolute;
left: 135px;
top: 0;
width: auto;
}
#mainmenu li a:hover + .submenu,.submenu:hover {
display: block;
}
.submenu li {
display: inline-block;
clear: none !important;
}
.submenu li a {
float: right;
margin-left: 10px;
}
.maintextcolour {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #FFF;
text-decoration: none;
}
.maintextcolour:hover {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #0FF;
text-decoration: none;
}
.headertext {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #FFF;
text-decoration: none;
}
Here is the updated Fiddle link. I have just added color to the following css:
#mainmenu > li:hover > a {
background-position: 0 0;
background-color:clear;
color:#0fffff;
background-color:rgba(255,255,255,0.5);
width:100%;
\
opacity: 0;
-webkit-transition: none;
}
Hope you want this.
I'm playing around with a pure CSS accordion http://reversl.net/accordion/ I can get the basic functionality to work (headings 2 & 3 both toggle) But I can't get heading 1 to toggle if I add the same UL to it. Because Heading 1 is styled differently the problem (I think) lies within naming/targeting it's + div ?
Please note: I removed the UL from Heading 1 for the sake of the demo because it was preventing Headings 2 & 3 from toggling.
You made several mistakes. Too many to count:
Here is a working example: Try and see, what I changed
http://jsfiddle.net/HerrSerker/ASqE9/
HTML
<div id="wrap">
<div class="accordion">
<div id="two" class="section">
<h4>
Heading 2
</h4>
<div class="sub_section">
<ul class="list">
<li>Sample Text 1</li>
<li class="last">Sample Text 2</li>
</ul>
</div>
</div><!--#two-->
<div id="four" class="section progress">
<h4>
Heading 4 (With Progress Bar)
</h4>
<div class="metrics">
<div class="meter">
<span style="width: 75%"></span>
</div><!--.meter-->
</div><!--.metrics-->
<div class="sub_section">
<ul class="list">
<li>Sample Text 1</li>
<li class="last">Sample Text 2</li>
</ul>
</div><!--.sub_section-->
</div><!--#one-->
</div><!--accordian-->
</div>
CSS
#wrap {
width: 320px;
background: #f0f0f0;
margin: auto;
}
.accordion {
clear: both;
padding: 0;
margin: 0 auto;
}
.accordion h4 {
margin: 0;
}
.accordion h4 a {
padding: 1em;
color: #999;
display: block;
font-weight: normal;
text-decoration: none;
}
.accordion h4 a:hover {
text-decoration: none;
background: #111;
}
.accordion .section {
background: #222;
border-bottom: 1px solid #000;
}
.accordion .sub_section {
border-bottom: none;
background: #f0f0f0;
}
.list {
padding: 0;
margin: 0;
}
.list li {
background: url('http://www.placehold.it/40x40') no-repeat;
color: #999;
list-style: none;
padding: .7em .7em .7em 4em;
border-bottom: 1px solid #fff;
}
.list .last {
border-bottom: none;
}
.accordion .sub_section {
height: 0;
overflow: hidden;
-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
}
.accordion :target h4 a {
text-decoration: none;
font-weight: bold;
}
.accordion :target .sub_section {
height: 80px;
}
.accordion .section.large:target h4 + div {
overflow: auto;
}
.accordion p {
color: #646464;
}
.accordion .progress .meter {
width: 90%;
height: 2px;
position: relative;
background: #555;
margin: -.9em auto .5em auto;
padding: 1px;
}
.meter > span {
height: 2px;
display: block;
background-color: #f0f0f0;
position: relative;
overflow: hidden;
}
This is because the class "progress" assigned to the div id="one" that keeps constant the size of the div with the content.