I have been scouring the web on before and after effects and I just haven't.. found anything remotely helpful. It's like the gray area of CSS. I was wondering how I would go about doing an effect like on twitter's homepage: This is on the hover effect. http://imgur.com/a/jBikq. It has a transition too, but I'm not sure how to implement it. Again i'm not even sure if this is using before and after, I imagine it is hover, but any help would be really appreciated.
Here is my code for my navigation:
<div id="navbar3" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div>
You can do it with :after and :before pseudo selector.
Im created an example based on your image, its look like this:
#import url('https://fonts.googleapis.com/css?family=Roboto');
body{
padding: 5%;
}
.exemple {
font-family: 'Roboto', sans-serif;
position: relative;
padding: 2.5% 3.5%;
text-decoration: none;
font-size: 0.9em;
color: #333333;
transition: ease .1s;
-webkit-transition: ease .1s;
}
.exemple:before {
font-family: 'FontAwesome';
content: '\f0e7';
font-size: 1.1em;
margin-right: 10px;
}
.exemple:after {
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 0px;
background: #20abe1;
transition: ease .1s;
-webkit-transition: ease .1s;
}
.exemple:hover {
color: #20abe1;
}
.exemple:hover:after{
height: 4px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
Moments
Working Fiddle
You can definitely use a ::before or you can animate the border/padding and it will create the same grow effect. Working fiddle here: FIDDLE
You haven't provided a much detail on the exact thing you're attempting to replicate. I'm going to assume it's the underline that animates up from the bottom of a navigation item.
To do this you will need to use CSS transition.
A simplified version of what Twitter is doing is below. They set a height on the <a> and <li> and add a border to the <a>. Since they have overflow:hidden; applied to the border of the <li> the border they applied to the <a> is initially hidden.
When the <li> is hovered the height of the <a> is reduced. They use transition on the height to animate the border up into view.
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
li {
float: left;
height: 40px;
overflow: hidden;
}
a {
display: block;
height: 40px;
padding: 0 10px;
line-height: 40px;
text-decoration: none;
overflow: hidden;
border-bottom: 3px solid #0c0;
transition: height 250ms ease-in-out;
}
li:hover a {
height: 37px;
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
Here is another way of animating in the underline with pseudo elements.
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
li {
position: relative;
float: left;
}
a {
display: block;
padding: 0 10px;
line-height: 40px;
text-decoration: none;
}
a:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
display: block;
height: 0;
width: 100%;
text-align: center;
background-color: #0c0;
transition: height 250ms ease-in-out;
}
li:hover a:after {
height: 3px;
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
Related
I have a logo image on the upper left side of the site and want my nav to show on the upper right side of the site. The nav is showing on the right side of the page but instead of being parallel to the logo it is below it even thought the logo is on the left side. Any idea what I am missing in the code below that is preventing the nav from moving up.
#charset 'UTF-8';
html,
html * {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: arial, sans-serif;
<!-- font-size: 1vw;>
background: white;
}
img {
width: 100%;
max-width: 100%;
height: auto;
vertical-align: middle;
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
a, a:visited {
color: inherit;
}
header {
position: fixed;
padding: 1.5em;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
}
.site-logo {
width: 30%;
max-width: 30%;
position: relative;
display: block;
}
.site-logo img {
width: 22em;
}
.logo {
opacity: 1;
}
.site-nav {
position: relative;
float: right;
z-index: 400;
top: 0;
left: 0;
display: block !important;
width: 68%;
padding: .75em 1em 0 0;
opacity: .95;
background: none;
}
.site-nav ul {
list-style-type: none;
margin: 0;
text-align: right;
}
.site-nav ul li {
display: inline-block;
margin-bottom: 0;
margin-left: 1.5em;
}
.site-nav ul li a {
font-size: .85em;
padding-bottom: .5em;
text-decoration: none;
letter-spacing: .15em;
text-transform: uppercase;
color: #000000;
-webkit-transition: color .3s;
transition: color .3s;
}
.site-nav ul li a:hover {
outline: none;
border-bottom: 1px solid black;
}
HTML
<header>
<!-- Logo -->
<a class="site-logo">
<img class="logo" src="images/SBI Logo.png" alt=""/>
</a>
<!-- Navigation Menu -->
<nav class="site-nav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
enter image description here
You are getting bogged down in the style sheet and using EM too, it would be much easier for you to use PIXELS instead of EM to position your elements.
<style>
.mysitelogo
{
margin-top: 16px;
width: 458px;
height: 114px;
}
.mysitenav
{
float: right;
padding: 8px;
opacity: .95;
}
</style>
<header>
<!-- Logo -->
<img class="mysitelogo" src="logo.gif" alt="" />
<!-- Navigation Menu -->
<nav class="mysitenav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
Using the code above you can get the layout you desire, THEN fine tune your layout in the stylesheet.
Some times it is easier to break the bigger problem down into basic parts.
Read this page for better understanding of using EM which is relative to FONT SIZE
https://www.w3schools.com/CSSref/css_units.asp
I created a menu with multiple submenus. I've been searching for ways to make the submenus dropdown in a horizontal fashion from the original menu to the submenu, and then to the final submenu (which I can sometimes get by accident, but then I screw everything up and go back to my original horizontal menu with vertical submenus). I've tried changing them to in-line block, static, and block, but I can't force it to work. Is there an easier way? What am I missing?
/* Navigation Bar Menu */
nav {
color: #F00;
min-width: 100%;
}
nav ul {
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
display: inline-block;
float: none;
white-space: nowrap;
}
nav a {
display: block;
padding: 0 10px;
color: #F00;
font-size: 20px;
line-height: 30px;
text-decoration: none;
}
nav a:hover {
color: #FFF;
background-color: #CCC;
transition: all .3s ease;
}
nav ul ul {
display: none;
position: absolute;
top: 100%;
}
nav ul li:hover>ul {
display: inherit;
transition: all .3s ease;
}
nav ul ul li {
min-width: 170px;
display: list-item;
position: relative;
}
nav ul ul ul {
position: absolute;
top: 0;
left: 100%;
}
<nav>
<ul>
<li>Home</li>
<li>About
<ul>
<li>Our Team</li>
</ul>
</li>
<li>Services
<ul>
<li>Cardiovascular
<ul>
<li>Perfusion</li>
<li>PTCA & IABP</li>
<li>ECMO</li>
<li>TAVR</li>
</ul>
</li>
<li>Blood Management
<ul>
<li>Autotransfusion</li>
<li>Platelet Gel</li>
</ul>
</li>
</ul>
</li>
<li>Products
<ul>
<li>Disposables</li>
<li>Featured Products</li>
</ul>
</li>
<li>Contact
<ul>
<li>Employment Inquiries</li>
<li>Contact</li>
</ul>
</li>
</ul>
</nav>
Sorry if I'm missing something, but is this what you're looking for?
https://codepen.io/will0220/pen/VMMgMb
This
nav ul ul li {
display: list-item;
}
Needs the display property removed, display: list-item forces it into rows. Hope this helps!
I have a standard pure CSS dropdown menu that needs to be supported back to ye olde IE7. My bug is that the submenu will disappear as the user moves their mouse down the links.
GIF illustration
I have been reading about IE7 stacking contexts and it is my understanding that I should be able to set { position: relative; z-index: (something large); } on the parent element of my menu to deal with the disappearing submenu.
This has not worked for me, and I can't find anything in my page content that would have a higher z-index than the menu anyway. (For one thing, nothing actually gets painted over the menu.) Got any clues? Here is my markup (or see Codepen):
<div class="mainmenu">
<div class="row">
<a href="/" class="pull-left">
<img src="logo.png" class="logo">
</a>
<ul class="nav-main">
<li>Item 1</li>
<li>Item 2</li>
<li><a class="dropdown">Item 3 </a>
<ul class="nav-sub">
<li>Sub-Item 1</li>
<li>Sub-Item 2</li>
<li>Sub-Item 3</li>
</ul>
</li>
<li><a class="dropdown">Item 4 </a>
<ul class="nav-sub">
<li>Sub-Item 1</li>
<li>Sub-Item 2</li>
<li>Sub-Item 3</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="content">
<!-- Then some page content -->
</div>
The CSS (colors removed):
.mainmenu {
position: relative;
top: 0;
z-index: 597;
width: 100%;
height: 66px;
margin: 0;
padding: 0 22px;
}
.mainmenu .logo {
height: 39px;
margin: 16.5px 0;
vertical-align: middle;
}
ul.nav-main {
margin: 0;
float: right;
padding: 0 20px;
position: relative;
top: 0;
}
ul.nav-main a,
ul.nav-main li {
-webkit-transition: all 0.1s linear;
-moz-transition: all 0.1s linear;
-o-transition: all 0.1s linear;
transition: all 0.1s linear;
}
ul.nav-main li {
list-style-type: none;
padding: 22px 8px;
float: left;
}
ul.nav-main li a,
ul.nav-main li span {
display: block;
}
ul.nav-main li:hover ul {
visibility: visible;
opacity: 1;
}
ul.nav-main ul.nav-sub {
visibility: hidden;
opacity: 0;
position: absolute;
padding: 0;
margin: 0;
top: 66px;
}
ul.nav-main ul.nav-sub li {
display: block;
float: none;
padding: 0;
outline: 1px solid #aaa;
}
ul.nav-main ul.nav-sub li a,
ul.nav-main ul.nav-sub li span {
display: block;
padding: 11px;
}
Any help would be appreciated.
ul.nav-main ul.nav-sub {
visibility: hidden;
opacity: 0;
position: absolute;
padding: 0;
margin: 0;
top: 100%;
}
it works for me perfectly in IE7
codepen
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.
Every1,
I am building a website for an organization that still only uses IE7. When creating this drop down menu on my laptop, the menu works without a problem. However, when trying it for the first time on a IE7 browser, it does not work.
<!doctype html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="./menu.css">
<link rel="stylesheet" type="text/css" href="./styles.css">
<title>Title</title>
</head>
<body>
<header>
<div id="logo">
<img src="Crest.png">
</div>
<p id="name">Somename</p>
<p id="motto">MyMotto</p>
</header>
<nav id="navigation">
<ul>
<li id="menu">Home</li>
<li id="menu">Pubs
<ul id="subMenu">
<li>Book 1</li>
<li>Book 2</li>
</ul>
</li>
<li id="menu">Links to Website
<ul id="subMenu">
<li>Link 1</li>
<li>Link 2</li>
</ul>
</li>
<li id="menu">Departments</li>
<li id="menu">References
<ul id="subMenu">
<li>Ref 1</li>
<li>Ref 2</li>
</ul>
</li>
<li id="menu">Links
<ul id="subMenu">
<li>More 1</li>
<li>More 2</li>
</ul>
</li>
<li id="menu">Forms
<ul id="subMenu">
<li>Form 1</li>
<li>Form 2</li>
</ul>
</li>
<li id="menu">Orders</li>
<li id="menu">Status</li>
</ul>
</nav>
</body>
Code for the menu.css
/* #navigation */
ul {
list-style:none;
padding:0px;
margin:0px;
}
ul#subMenu a:hover { color: #FF0; font-weight: bold;}
#navigation {
margin-top: 20px;
float: left;
}
#navigation ul, #navigation li {
list-style: none;
padding: 0;
margin: 0;
display: inline;
background-color: #30C;
/* box-shadow: #111 3px 3px 4px; */
}
li#menu { box-shadow: #111 3px 3px 4px; }
ul#subMenu { box-shadow: #111 3px 3px 4px; }
#navigation ul li {
float: left;
position: relative;
}
#navigation ul li a {
display: block;
padding: 3px 20px;
margin: 1px;
font-size: 12px;
white-space: nowrap;
color: #FFF;
text-decoration: none;
font-size: 16px;
}
#navigation ul ul {
position: absolute;
top: -99999px; /* Remove them out of viewport */
left: 0;
opacity: 0; /* Hide sub level, we will use this in transition */
-webkit-transition: opacity .4s ease-in-out;
-moz-transition: opacity .4s ease-in-out;
-o-transition: opacity .4s ease-in-out;
transition: opacity .4s ease-in-out;
z-index: 497;
background: #30C;
padding: 2px;
border: 1px solid #444;
border-top: none;
box-shadow: #111 0 3px 4px;
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
}
#navigation ul ul ul {
position: absolute;
top: -99999px;
left: 100%;
border-radius: 6px;
border: 1px solid #444;
background-color: #FFF;
}
#navigation ul li:hover>ul {
opacity: 1;
position: absolute;
top: 99%;
left: 0;
}
#navigation ul ul li:hover>ul {
opacity: 1;
position: absolute;
top: 0%;
left: 100%;
}
Code for the styles.css
body {
width: 900px;
margin: 0 auto;
padding: 0;
background-color: #006;
}
#font-face {
font-family: Cowboys;
src: url('Bleeding_Cowboys.ttf');
}
#logo {
margin-top: 20px;
padding: 0;
float: left;
}
#name {
float: left;
font-size: 85px;
margin: 0;
margin-top: 20px;
padding: 0;
color: #FC0;
font-family: Cowboys;
position: relative;
left: 40px;
}
#motto {
float: left;
font-size: 25px;
margin: 0;
padding: 0;
position: relative;
left: -460px;
top: 160px;
color: #FC0;
font-family: Cowboys;
font-style: italic;
}
The above code on IE7 does not even display the properties of a horizontal menu, instead it show it as vertical menu displaying all sub-menus and the font-face above also does not work.
What am I doing wrong?
Thanks.
Others have pointed out the <nav> tag not being supported in IE7. However, issues go beyond that. IE7 does not support HTML5 and your page is entirely HTML5 - the Doctype is inappropriate, the header tag is not supported, the nav tag is not supported.
There are javascript lubraries you can include to help push older browser into understanding HTML5.
Modernizer
HTML5 Shiv
In addition, some pre-constructed frameworks, such as HTML5 Boilerplate may help support older browsers as well.
If you are constructing primarily for IE7 you may want to stick to xHTML or HTML4 and CSS2.
ie7 doesn't know what nav is....you should use html5shiv.js to include it in the document, then add nav{display:block} for starters
nav doesnt work for ie7 and below use
<!DOCTYPE html>
at the top of your header area