I'm trying to achieve similar behaviour like as shown in this gif.
I tried to add a class after mouseleave via jQuery, I also tried the background as a linear gradient, unfortunately I can't figure out how to make the effect after moving the mouse. Thanks a lot for any advice.
HTML:
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="./eshop.html">E-shop</a>
</li>
</ul>
SCSS:
.nav-item {
display: flex;
flex-direction: row;
transform: skewX(-25deg);
border-right: 1px solid #9e8451;
margin: 0 0.5rem;
.nav-link {
font-weight: 500;
color: #c09f62 !important;
font-size: 1.15rem;
text-transform: uppercase;
transform: skewX(25deg);
padding: 1.25rem 1.85rem !important;
transition: 0s text-shadow;
}
&::after {
content: "";
width: 100%;
background: #312612;
transition: all 1s linear;
position: absolute;
right: -200%;
top: 0;
height: 100%;
display: block;
z-index: -1;
}
&.active,
&:hover {
font-weight: bold;
&::after {
right: 0;
}
.nav-link {
color: #f8d696 !important;
text-shadow: 0 0 15px #f2c87b;
transition-delay: 1.15s;
font-weight: bold;
}
}
}
Set your .nav-item z-index less than your ::after pseudo element and increase the z-index on .nav-item on hover or active.
Here it is how you can achieve this.
.nav-item {
display: flex;
flex-direction: row;
transform: skewX(-25deg);
border-right: 1px solid #9e8451;
margin: 0 0.5rem;
.nav-link {
font-weight: 500;
color: #c09f62 !important;
font-size: 1.15rem;
text-transform: uppercase;
transform: skewX(25deg);
padding: 1.25rem 1.85rem !important;
transition: 0s text-shadow;
z-index:0;
}
&::after {
content: "";
width: 100%;
background: #312612;
opacity:.5;
transition: all 1s linear;
position: absolute;
right: -200%;
top: 0;
height: 100%;
display: block;
z-index: 1;
}
&.active,
&:hover {
font-weight: bold;
&::after {
right: 0;
}
.nav-link {
color: #f8d696 !important;
text-shadow: 0 0 15px #f2c87b;
transition-delay: 1.15s;
font-weight: bold;
z-index:2;
}
}
}
Related
As far as I know, child divs normally inherit parent's style. However this isn't the case when I am trying to copy the parent's height. Any clarification on how this works would be very appreciated
Parent Div
Child Div
I've tried switching to position:relative and display:inline but am yet to find anything that modifies the child div's height relative to the parent.
// Plot our graphs
var data = [
{
z: [[1, 20, 30], [20, 1, 60], [30, 60, 1]],
type: 'heatmap'
}
];
Plotly.newPlot('chart_div', data);
/*//////////////////////////////////////////////////////////////////
[ FONT ]*/
#font-face {
font-family: Ubuntu-Regular;
src: url('../fonts/ubuntu_regular-webfont.woff') format('woff');
}
#font-face {
font-family: Ubuntu-Bold;
src: url('../fonts/ubuntu-bold-webfont.woff') format('woff');
}
#font-face {
font-family: Montserrat-Regular;
src: url('../fonts/montserrat-regular-webfont.woff') format('woff');
}
#font-face {
font-family: FontAwesome;
src: url('../fonts/fontawesome-webfont.woff') format('woff');
}
#font-face {
font-family: Material-Design-Iconic-Font;
src: url('../fonts/Material-Design-Iconic-Font.woff') format('woff');
}
fontawesome-webfont.woff
/*//////////////////////////////////////////////////////////////////
[ RESTYLE TAG ]*/
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body, html {
height: 100%;
font-family: Ubuntu-Regular, sans-serif;
}
/*---------------------------------------------*/
a {
font-family: Ubuntu-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
transition: all 0.4s;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
}
a:focus {
outline: none !important;
}
a:hover {
text-decoration: none;
color: #403866;
}
/*---------------------------------------------*/
h1,h2,h3,h4,h5,h6 {
margin: 0px;
}
p {
font-family: Ubuntu-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
}
ul, li {
margin: 0px;
list-style-type: none;
}
/*---------------------------------------------*/
input {
outline: none;
border: none;
}
textarea {
outline: none;
border: none;
}
textarea:focus, input:focus {
border-color: transparent !important;
}
input::-webkit-input-placeholder { color: #8f8fa1;}
input:-moz-placeholder { color: #8f8fa1;}
input::-moz-placeholder { color: #8f8fa1;}
input:-ms-input-placeholder { color: #8f8fa1;}
textarea::-webkit-input-placeholder { color: #8f8fa1;}
textarea:-moz-placeholder { color: #8f8fa1;}
textarea::-moz-placeholder { color: #8f8fa1;}
textarea:-ms-input-placeholder { color: #8f8fa1;}
label {
display: block;
margin: 0;
}
/*---------------------------------------------*/
button {
outline: none !important;
border: none;
background: transparent;
}
button:hover {
cursor: pointer;
}
iframe {
border: none !important;
}
/*//////////////////////////////////////////////////////////////////
[ Utility ]*/
.txt1 {
font-family: Ubuntu-Regular;
font-size: 16px;
color: #827ffe;
line-height: 1.4;
}
.app-explanation {
font-family: Ubuntu-Regular;
font-size: 13px;
color: #403866;
line-height: 1.4;
text-align: center;
font-style: italic;
width: 100%;
}
/*//////////////////////////////////////////////////////////////////
[ login ]*/
.limiter {
width: 100%;
margin: 0 auto;
}
.container-login100 {
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 15px;
position: relative;
background-position: center;
background-size: cover;
background-repeat: no-repeat;;
}
.wrap-login100 {
width: 390px;;
background: #fff;
border-radius: 10px;
position: relative;
}
.wrap-data100 {
width: 90%;
background: #fff;
border-radius: 10px;
position: relative;
}
/*==================================================================
[ Form ]*/
.login100-form {
width: 100%;
}
.login100-form-title {
font-family: Ubuntu-Bold;
font-size: 30px;
color: #403866;
line-height: 1.2;
text-transform: uppercase;
text-align: center;
width: 100%;
display: block;
}
/*------------------------------------------------------------------
[ Input ]*/
.wrap-input100 {
width: 100%;
position: relative;
background-color: #e6e6e6;
border: 1px solid transparent;
border-radius: 3px;
}
/*---------------------------------------------*/
.input100 {
font-family: Ubuntu-Bold;
color: #403866;
line-height: 1.2;
font-size: 18px;
display: block;
width: 100%;
background: transparent;
height: 62px;
padding: 0 20px 0 38px;
}
/*------------------------------------------------------------------
[ Focus Input ]*/
.focus-input100 {
position: absolute;
display: block;
width: calc(100% + 2px);
height: calc(100% + 2px);
top: -1px;
left: -1px;
pointer-events: none;
border: 1px solid #827ffe;
border-radius: 3px;
visibility: hidden;
opacity: 0;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
transition: all 0.4s;
-webkit-transform: scaleX(1.1) scaleY(1.3);
-moz-transform: scaleX(1.1) scaleY(1.3);
-ms-transform: scaleX(1.1) scaleY(1.3);
-o-transform: scaleX(1.1) scaleY(1.3);
transform: scaleX(1.1) scaleY(1.3);
}
.input100:focus + .focus-input100 {
visibility: visible;
opacity: 1;
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
}
.eff-focus-selection {
visibility: visible;
opacity: 1;
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
}
/*==================================================================
[ Restyle Checkbox ]*/
.input-checkbox100 {
display: none;
}
.label-checkbox100 {
font-family: Ubuntu-Regular;
font-size: 16px;
color: #999999;
line-height: 1.2;
display: block;
position: relative;
padding-left: 26px;
cursor: pointer;
}
.label-checkbox100::before {
content: "\f00c";
font-family: FontAwesome;
font-size: 13px;
color: transparent;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
width: 18px;
height: 18px;
border-radius: 3px;
background: #fff;
border: 2px solid #827ffe;
left: 0;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
}
.input-checkbox100:checked + .label-checkbox100::before {
color: #827ffe;
}
/*------------------------------------------------------------------
[ Button ]*/
.container-login100-form-btn {
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
}
.login100-form-btn {
font-family: Ubuntu-Bold;
font-size: 16px;
color: #fff;
line-height: 1.2;
text-transform: uppercase;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
justify-content: center;
align-items: center;
padding: 0 20px;
width: 100%;
height: 62px;
background-color: #827ffe;
border-radius: 3px;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
transition: all 0.4s;
}
.login100-form-btn:hover {
background-color: #403866;
}
/*------------------------------------------------------------------
[ Alert validate ]*/
.validate-input {
position: relative;
}
.alert-validate::before {
content: attr(data-validate);
position: absolute;
max-width: 70%;
background-color: #fff;
border: 1px solid #c80000;
border-radius: 3px;
padding: 4px 25px 5px 10px;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
right: 12px;
pointer-events: none;
font-family: Ubuntu-Regular;
color: #c80000;
font-size: 14px;
line-height: 1.4;
text-align: left;
visibility: hidden;
opacity: 0;
-webkit-transition: opacity 0.4s;
-o-transition: opacity 0.4s;
-moz-transition: opacity 0.4s;
transition: opacity 0.4s;
}
.alert-validate::after {
content: "\f12a";
font-family: FontAwesome;
display: block;
position: absolute;
color: #c80000;
font-size: 18px;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
right: 18px;
}
.alert-validate:hover:before {
visibility: visible;
opacity: 1;
}
#media (max-width: 992px) {
.alert-validate::before {
visibility: visible;
opacity: 1;
}
}
/*==================================================================
[ Restyle Select2 ]*/
.select2-container {
display: block;
max-width: 100% !important;
width: auto !important;
}
.select2-container .select2-selection--single {
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
align-items: center;
background-color: rgba(171, 171, 189, 0.233);
border: none;
height: 40px;
outline: none;
position: relative;
left: -40px;
}
/*------------------------------------------------------------------
[ in select ]*/
.select2-container .select2-selection--single .select2-selection__rendered {
font-family: Ubuntu-Bold;
font-size: 18px;
color: #555555;
line-height: 1.2;
padding-left: 0px ;
background-color: transparent;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 100%;
top: 50%;
transform: translateY(-50%);
right: 0px;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
align-items: center;
justify-content: flex-end;
}
.select2-selection__arrow b {
display: none;
font-family: Material-Design-Iconic-Font !important;
font-size: 18px;
color: #555555;
}
.select2-selection__arrow {
content: '\f312';
font-family: Material-Design-Iconic-Font !important;
font-size: 18px;
color: #555555;
}
/*------------------------------------------------------------------
[ Dropdown option ]*/
.select2-container--open .select2-dropdown {
z-index: 1251;
width: calc(100% + 2px);
border: 0px solid transparent;
border-radius: 10px;
overflow: hidden;
background-color: rgba(171, 171, 189, 0.233);
left: -40px;
box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-o-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
-ms-box-shadow: 0 3px 10px 0px rgba(0, 0, 0, 0.2);
}
#media (max-width: 576px) {
.select2-container--open .select2-dropdown {
left: -12px;
}
}
.select2-dropdown--above {top: -38px;}
.select2-dropdown--below {top: 10px;}
.select2-container .select2-results__option[aria-selected] {
padding-top: 10px;
padding-bottom: 10px;
padding-left: 24px;
}
#media (max-width: 576px) {
.select2-container .select2-results__option[aria-selected] {
padding-left: 12px;
}
}
.select2-container .select2-results__option[aria-selected="true"] {
background: #403866;
color: white;
}
.select2-container .select2-results__option--highlighted[aria-selected] {
background: #827ffe;
color: white;
}
.select2-results__options {
font-family: Ubuntu-Bold;
font-size: 14px;
color: #555555;
line-height: 1.2;
}
.select2-search--dropdown .select2-search__field {
border: 1px solid #aaa;
outline: none;
font-family: Ubuntu-Bold;
font-size: 15px;
color: #333333;
line-height: 1.2;
}
.wrap-input100 .dropDownSelect2 .select2-container--open {
width: 100% !important;
}
.wrap-input100 .dropDownSelect2 .select2-dropdown {
width: calc(100% + 2px) !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blackfynn Exporter</title>
<meta charset="UTF-8">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico" />
<!--===============================================================================================-->
<script src="build/build.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id='half-height' style="height: 40% !important">
<div id='blackfynn-panel' style="position: relative">
<div class="container-login100 datasetUI" id="dataset_div">
<div class="wrap-data100 p-t-50 p-b-90 datasetUI">
<form class="contact100-form validate-form">
<span class="login100-form-title p-b-51">
Data Viewer
</span>
<div class=" input100 wrap-input100 input100-select bg1 datasetUI">
<span class="label-input100"></span>
<div id="channel_div">
<select class="js-select2" name="service" id="select_channel">
<option>Channel Selection</option>
</select>
<div class="dropDownSelect2"></div>
</div>
</div>
</form>
<div class="datasetUI" id="chart_div"></div>
<br>
<div id="exportURL">
</div>
</div>
</div>
</div>
</div>
<!--===============================================================================================-->
<!--===============================================================================================-->
</body>
</html>
A child element does not inherit the height of its parent.
Reference: MDN
You can however set its value to height:inherit; CodePen Example
You could also use height: 100% or max-height: 100%
In any situation you have to think what you want to do with the content if it is too much to fit in that set height: overflow: hidden; overflow-y:hidden; overflow-y: scroll.
I have created a option button for my project. The code is given below.I am trying to make proper alignment of .dotlist is moving on right side. It should me on left portion of dot button.
What will be the solution for making perfect dot dropdown button thus the list appear properly.
$('.dottbtn').on('click', function(e) {
e.stopPropagation();
$('.dotmenu').toggleClass('dotopened');
});
$(document).on('click', function() {
$('.dotmenu').removeClass('dotopened');
});
body {
margin: 0;
background: tomato;
font-family: 'Open Sans', sans-serif;
}
.dotted {
display: inline-block;
vertical-align: top;
float: right;
}
.dottbtn {
cursor: pointer;
margin-top: 5px;
width: 40px;
height: 20px;
z-index: 80;
position: relative;
align-items: flex-end;
}
.dottbtn {
background: url('https://image.flaticon.com/icons/svg/483/483345.svg');
background-size: 17px 17px;
height: 17px;
width: 17px;
}
.dotmenu {
width: 150px;
border-radius: 10px;
margin-top: 20px;
display: inline-block;
float: right;
background: #fff;
position: absolute;
box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.15);
z-index: 90;
visibility: hidden;
opacity: 0;
-webkit-transition: all 300ms ease;
transition: all 300ms ease;
}
.dotmenu.dotopened {
visibility: visible;
opacity: 1;
}
.dotmenu::before {
content: '';
position: absolute;
top: -5px;
right: 7px;
width: 15px;
height: 15px;
background: #fff;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
.dotmenu ul {
list-style: none;
margin: 0;
padding: 0;
}
.dotmenu ul.dot-list {
text-align: left;
font-weight: 100;
width: 100%;
margin: auto;
padding-top: 10px;
padding-bottom: 10px;
}
.dotmenu ul.dot-list li a {
text-decoration: none;
padding-left: 20px;
padding-top: 5px;
color: #343434;
font-weight: 600;
display: block;
line-height: 27px;
-webkit-transition: all 200ms ease;
transition: all 200ms ease;
}
.dotmenu ul.dot-list li a:hover {
color: tomato;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dotted">
<div class="dottbtn"></div>
<div class="dotmenu">
<ul class="dot-list">
<li>Home</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
Please help me to overcome from it.
Add right: 15px to .dottbtn and right: 10px to .dotmenu :
$('.dottbtn').on('click', function(e) {
e.stopPropagation();
$('.dotmenu').toggleClass('dotopened');
});
$(document).on('click', function() {
$('.dotmenu').removeClass('dotopened');
});
body {
margin: 0;
background: tomato;
font-family: 'Open Sans', sans-serif;
}
.dotted {
display: inline-block;
vertical-align: top;
float: right;
}
.dottbtn {
cursor: pointer;
margin-top: 5px;
width: 40px;
height: 20px;
z-index: 80;
position: relative;
align-items: flex-end;
}
.dottbtn {
background: url('https://image.flaticon.com/icons/svg/483/483345.svg');
background-size: 17px 17px;
height: 17px;
width: 17px;
right: 15px;
}
.dotmenu {
width: 150px;
border-radius: 10px;
margin-top: 20px;
display: inline-block;
float: right;
background: #fff;
position: absolute;
box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.15);
z-index: 90;
visibility: hidden;
opacity: 0;
-webkit-transition: all 300ms ease;
transition: all 300ms ease;
right: 10px;
}
.dotmenu.dotopened {
visibility: visible;
opacity: 1;
}
.dotmenu::before {
content: '';
position: absolute;
top: -5px;
right: 7px;
width: 15px;
height: 15px;
background: #fff;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
.dotmenu ul {
list-style: none;
margin: 0;
padding: 0;
}
.dotmenu ul.dot-list {
text-align: left;
font-weight: 100;
width: 100%;
margin: auto;
padding-top: 10px;
padding-bottom: 10px;
}
.dotmenu ul.dot-list li a {
text-decoration: none;
padding-left: 20px;
padding-top: 5px;
color: #343434;
font-weight: 600;
display: block;
line-height: 27px;
-webkit-transition: all 200ms ease;
transition: all 200ms ease;
}
.dotmenu ul.dot-list li a:hover {
color: tomato;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dotted">
<div class="dottbtn"></div>
<div class="dotmenu">
<ul class="dot-list">
<li>Home</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
Adding right:0; to your .dotmenu will fix it.
$('.dottbtn').on('click', function(e) {
e.stopPropagation();
$('.dotmenu').toggleClass('dotopened');
});
$(document).on('click', function() {
$('.dotmenu').removeClass('dotopened');
});
body {
margin: 0;
background: tomato;
font-family: 'Open Sans', sans-serif;
}
.dotted {
display: inline-block;
vertical-align: top;
float: right;
}
.dottbtn {
cursor: pointer;
margin-top: 5px;
width: 40px;
height: 20px;
z-index: 80;
position: relative;
align-items: flex-end;
}
.dottbtn {
background: url('https://image.flaticon.com/icons/svg/483/483345.svg');
background-size: 17px 17px;
height: 17px;
width: 17px;
}
.dotmenu {
width: 150px;
border-radius: 10px;
margin-top: 20px;
display: inline-block;
float: right;
background: #fff;
position: absolute;
box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.15);
z-index: 90;
visibility: hidden;
opacity: 0;
-webkit-transition: all 300ms ease;
transition: all 300ms ease;
right: 0;
}
.dotmenu.dotopened {
visibility: visible;
opacity: 1;
}
.dotmenu::before {
content: '';
position: absolute;
top: -5px;
right: 7px;
width: 15px;
height: 15px;
background: #fff;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
.dotmenu ul {
list-style: none;
margin: 0;
padding: 0;
}
.dotmenu ul.dot-list {
text-align: left;
font-weight: 100;
width: 100%;
margin: auto;
padding-top: 10px;
padding-bottom: 10px;
}
.dotmenu ul.dot-list li a {
text-decoration: none;
padding-left: 20px;
padding-top: 5px;
color: #343434;
font-weight: 600;
display: block;
line-height: 27px;
-webkit-transition: all 200ms ease;
transition: all 200ms ease;
}
.dotmenu ul.dot-list li a:hover {
color: tomato;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dotted">
<div class="dottbtn"></div>
<div class="dotmenu">
<ul class="dot-list">
<li>Home</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
Hey I'm having some issues with my mega menu. Im trying to mimic Newegg's style. I want a small sub menu to show up on hover. Here is my codepen: https://codepen.io/iamgonge/pen/vxEEeN
I'm trying to make the sub menu line up with the caret in each menu link. right now it stays in the same spot,When I change it from Absolute it pushes everything down on hover.
/* Body */
body {
margin: 0px;
padding: 0px;
font-family: Helvetica;
background-color: #fff;
}
header {
min-height: 450px;
}
header.dd-blue {
background-color: #fff;
}
/* Nav */
nav {
position: relative;
}
header.dd-blue nav {
background-color: #4F96BA;
}
ul.main-nav {
list-style-type: none;
padding: 0px;
font-size: 0px;
max-width: 1000px;
margin: 0 auto;
}
ul.main-nav h2 {
font-size: .9em;
font-weight: 300;
}
ul.main-nav>li {
display: inline-block;
padding: 0;
}
ul.main-nav>li>a {
display: block;
padding: 20px 30px;
position: relative;
color: #fff;
font-size: 15px;
font-weight: 400;
box-sizing: border-box;
}
ul.main-nav>li:hover {
background-color: #f9f9f9;
}
ul.main-nav>li:hover>a {
color: #333;
font-weight: 400;
}
ul.main-nav>li ul.sub-menu-lists {
margin: 0px;
padding: 1px;
list-style-type: none;
display: block;
}
ul.main-nav>li ul.sub-menu-lists>li {
padding: 0 0px;
margin-top: 2px;
}
ul.main-nav>li ul.sub-menu-lists>li>a {
font-size: .84em;
font-weight: 500;
}
.sub-menu-head {
margin: 10px 0;
border-bottom: 1px solid #4F96BA;
width: 100%;
}
#media only screen and (min-width: 769px) {
/* Desktop */
ul.main-nav {
display: block;
position: relative;
}
.sub-menu-block {
padding: 15px;
}
/* Sub-menu */
ul.main-nav>li>div.sub-menu-block {
visibility: hidden;
background-color: #f9f9f9;
position: absolute;
margin-top: 0px;
width: 100%;
color: #333;
left: 0;
box-sizing: border-box;
z-index: 3;
font-size: 16px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
opacity: 0;
/*CSS animation applied for sub menu : Slide from Top */
-webkit-transition: all 0.4s ease 0s;
-o-transition: all 0.4s ease 0s;
transition: all 0.4s ease 0s;
-webkit-transform: rotateX(90deg);
-moz-transform: rotateX(90deg);
-ms-transform: rotateX(90deg);
transform: rotateX(90deg);
-webkit-transform-origin: top center;
-ms-transform-origin: top center;
transform-origin: top center;
}
ul.main-nav>li:hover>div.sub-menu-block {
background-color: #fff;
visibility: visible;
opacity: 1;
-webkit-transform: rotateX(0deg);
-moz-transform: rotateX(0deg);
-ms-transform: rotateX(0deg);
transform: rotateX(0deg);
}
ul.main-nav>li>div.sub-menu-block>* {
-webkit-transition-property: opacity;
-moz-transition-property: opacity;
-o-transition-property: opacity;
transition-property: opacity;
-webkit-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-o-transition-duration: 0.4s;
transition-duration: 0.4s;
opacity: 0;
}
ul.main-nav>li:hover>div.sub-menu-block>* {
opacity: 1;
}
.sub-menu-head {
font-size: 20px;
}
header.dd-blue ul.main-nav>li>a {
border-right: 1px solid #666;
}
/* List Separator: Inner Border */
ul.main-nav>li>a:after {
content: '';
width: 1px;
height: 62px;
position: absolute;
right: 0px;
top: 0px;
z-index: 2;
}
header.dd-blue ul.main-nav>li>a:after {
background-color: #999;
}
/* Drop Down/Up Arrow for Mega Menu */
ul.main-nav>li>a.mega-menu>span {
display: block;
vertical-align: middle;
}
ul.main-nav>li>a.mega-menu>span:after {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #fff;
content: '';
background-color: transparent;
display: inline-block;
margin-left: 10px;
vertical-align: middle;
}
ul.main-nav>li:hover>a.mega-menu span:after {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 0px solid transparent;
border-bottom: 5px solid #666;
}
}
.sub-menu-lists li {
line-height: 1;
}
/* 5 Columns */
.col-xs-15, .col-sm-15, .col-md-15, .col-lg-15 {
position: relative;
min-height: 1px;
padding-right: 10px;
padding-left: 10px;
}
.col-xs-15 {
width: 20%;
float: left;
}
#media (min-width: 768px) {
.col-sm-15 {
width: 20%;
float: left;
}
}
#media (min-width: 992px) {
.col-md-15 {
width: 20%;
float: left;
}
}
#media (min-width: 1200px) {
.col-lg-15 {
width: 20%;
float: left;
}
}
/* end 5 columns */
#rds-font {
font-size: 15px;
}
a, a:active, a:visited, a:link {
color: #599ab9;
text-decoration: none;
}
a:hover {
color: black;
}
#left-border {
border-left: 1px solid #666;
}
/* Hover dropdown */
.dropdown ul.dropdown-menu {
margin-top: 0;
}
.hover_drop_down:hover ul.dropdown-menu {
margin-top: 2px;
}
.hover_drop_down:hover ul.dropdown-menu {
display: inline-block;
position: absolute;
top: 25px;
left: 90%;
z-index: 1;
}
.dropdown-menu>li>a {
display: block;
margin: 10px: padding-bottom: 10px;
font-size: 13px;
font-weight: 500;
line-height: 1;
color: #599ab9;
}
<header class="dd-blue">
<nav role="navigation">
<ul class="main-nav">
<li class="top-level-link">
<a class="mega-menu" id="left-border"><span>Main 1</span></a>
<div class="sub-menu-block">
<div class="row">
<div class="col-xs-15">
<h2 class="sub-menu-head">Header 1</h2>
<ul class="sub-menu-lists">
<li class="hover_drop_down">
Item with sub-menu<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Item X</li>
</ul>
</li>
<li class="hover_drop_down">
Item with sub-menu<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Item X</li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!--end of sub-menu-block -->
</li>
</ul>
</nav>
</header>
Set position: absolute; display: inline-block; and remove any left and top values so that the element will display where it is in the DOM.
/* Body */
body {
margin: 0px;
padding: 0px;
font-family: Helvetica;
background-color: #fff;
}
header {
min-height: 450px;
}
header.dd-blue {
background-color: #fff;
}
/* Nav */
nav {
position: relative;
}
header.dd-blue nav {
background-color: #4F96BA;
}
ul.main-nav {
list-style-type: none;
padding: 0px;
font-size: 0px;
max-width: 1000px;
margin: 0 auto;
}
ul.main-nav h2 {
font-size: .9em;
font-weight: 300;
}
ul.main-nav>li {
display: inline-block;
padding: 0;
}
ul.main-nav>li>a {
display: block;
padding: 20px 30px;
position: relative;
color: #fff;
font-size: 15px;
font-weight: 400;
box-sizing: border-box;
}
ul.main-nav>li:hover {
background-color: #f9f9f9;
}
ul.main-nav>li:hover>a {
color: #333;
font-weight: 400;
}
ul.main-nav>li ul.sub-menu-lists {
margin: 0px;
padding: 1px;
list-style-type: none;
display: block;
}
ul.main-nav>li ul.sub-menu-lists>li {
padding: 0 0px;
margin-top: 2px;
}
ul.main-nav>li ul.sub-menu-lists>li>a {
font-size: .84em;
font-weight: 500;
}
.sub-menu-head {
margin: 10px 0;
border-bottom: 1px solid #4F96BA;
width: 100%;
}
#media only screen and (min-width: 769px) {
/* Desktop */
ul.main-nav {
display: block;
position: relative;
}
.sub-menu-block {
padding: 15px;
}
/* Sub-menu */
ul.main-nav>li>div.sub-menu-block {
visibility: hidden;
background-color: #f9f9f9;
position: absolute;
margin-top: 0px;
width: 100%;
color: #333;
left: 0;
box-sizing: border-box;
z-index: 3;
font-size: 16px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
opacity: 0;
/*CSS animation applied for sub menu : Slide from Top */
-webkit-transition: all 0.4s ease 0s;
-o-transition: all 0.4s ease 0s;
transition: all 0.4s ease 0s;
-webkit-transform: rotateX(90deg);
-moz-transform: rotateX(90deg);
-ms-transform: rotateX(90deg);
transform: rotateX(90deg);
-webkit-transform-origin: top center;
-ms-transform-origin: top center;
transform-origin: top center;
}
ul.main-nav>li:hover>div.sub-menu-block {
background-color: #fff;
visibility: visible;
opacity: 1;
-webkit-transform: rotateX(0deg);
-moz-transform: rotateX(0deg);
-ms-transform: rotateX(0deg);
transform: rotateX(0deg);
}
ul.main-nav>li>div.sub-menu-block>* {
-webkit-transition-property: opacity;
-moz-transition-property: opacity;
-o-transition-property: opacity;
transition-property: opacity;
-webkit-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-o-transition-duration: 0.4s;
transition-duration: 0.4s;
opacity: 0;
}
ul.main-nav>li:hover>div.sub-menu-block>* {
opacity: 1;
}
.sub-menu-head {
font-size: 20px;
}
header.dd-blue ul.main-nav>li>a {
border-right: 1px solid #666;
}
/* List Separator: Inner Border */
ul.main-nav>li>a:after {
content: '';
width: 1px;
height: 62px;
position: absolute;
right: 0px;
top: 0px;
z-index: 2;
}
header.dd-blue ul.main-nav>li>a:after {
background-color: #999;
}
/* Drop Down/Up Arrow for Mega Menu */
ul.main-nav>li>a.mega-menu>span {
display: block;
vertical-align: middle;
}
ul.main-nav>li>a.mega-menu>span:after {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #fff;
content: '';
background-color: transparent;
display: inline-block;
margin-left: 10px;
vertical-align: middle;
}
ul.main-nav>li:hover>a.mega-menu span:after {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 0px solid transparent;
border-bottom: 5px solid #666;
}
}
.sub-menu-lists li {
line-height: 1;
}
/* 5 Columns */
.col-xs-15, .col-sm-15, .col-md-15, .col-lg-15 {
position: relative;
min-height: 1px;
padding-right: 10px;
padding-left: 10px;
}
.col-xs-15 {
width: 20%;
float: left;
}
#media (min-width: 768px) {
.col-sm-15 {
width: 20%;
float: left;
}
}
#media (min-width: 992px) {
.col-md-15 {
width: 20%;
float: left;
}
}
#media (min-width: 1200px) {
.col-lg-15 {
width: 20%;
float: left;
}
}
/* end 5 columns */
#rds-font {
font-size: 15px;
}
a, a:active, a:visited, a:link {
color: #599ab9;
text-decoration: none;
}
a:hover {
color: black;
}
#left-border {
border-left: 1px solid #666;
}
/* Hover dropdown */
.dropdown ul.dropdown-menu {
margin-top: 0;
}
.hover_drop_down:hover ul.dropdown-menu {
position: absolute;
display: inline-block;
z-index: 1;
left: auto;
top: auto;
}
.caret-right {
display: inline-block;
width: 0;
height: 0;
margin-left: 2px;
vertical-align: middle;
border-left: 5px solid;
border-left-color:#1c2b36;
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
}
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<header class="dd-blue">
<nav role="navigation">
<ul class="main-nav">
<li class="top-level-link">
<a class="mega-menu" id="left-border"><span>Main 1</span></a>
<div class="sub-menu-block">
<div class="row">
<div class="col-xs-15">
<h2 class="sub-menu-head">Header 1</h2>
<ul class="sub-menu-lists">
<li class="hover_drop_down">
Item with sub-menu<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Item X</li>
</ul>
</li>
<li class="hover_drop_down">
Item with sub-menu<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Item X</li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!--end of sub-menu-block -->
</li>
</ul>
</nav>
</header>
I have a pre-existing responsive menu but I need to add a sub-navigation for each menu choice. How can I do this with CSS?
The important code, I think, is in the section primary navigation.
Thank you in advance for everyone that can help me to understand how sub-menus work.
/**
/* 06. =header styles
/* =================================================================== */
html,
body {
height: 100%;
}
body {
background: #0F1215;
font: 16px/30px "merriweather-regular", serif;
font-weight: normal;
color: #575859;
}
header {
height: 66px;
width: 100%;
position: fixed;
left: 0;
top: 0;
z-index: 600;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-webkit-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
header.opaque {
background: black;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
/* header logo */
header .logo {
background: #fdc501;
float: left;
width: auto;
margin-left: 15px;
margin-right: 30px;
z-index: 600;
/* add position relative since z-index only applies to
elements that have been given an explicit position */
position: relative;
}
header .logo a {
display: block;
margin: 0;
padding: 0;
border: none;
font: 0/0 a;
text-shadow: none;
color: transparent;
width: 114px;
height: 66px;
background: url("../images/logoK#2x.png") no-repeat center;
background-size: 61px 14px;
}
/* header social */
header .header-social {
font-size: 20px;
font-weight: normal;
line-height: 66px;
margin-top: 0;
margin-left: 30px;
padding-left: 36px;
border-left: 1px solid rgba(150, 150, 150, 0.2);
float: left;
position: relative;
top: -1px;
}
header .header-social li {
display: inline-block;
margin-right: 15px;
}
header .header-social li a {
color: #FFFFFF;
}
header .header-social li a:hover {
color: #fdc501;
}
/* media queries:
/* header/header components */
#media only screen and (max-width:880px) {
header .header-social {
display: none;
}
}
#media only screen and (max-width:768px) {
header {
background: black;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
header .row {
width: 100%;
}
header .logo {
margin-left: -30px;
}
}
/* primary navigation
--------------------------------------------------------------------- */
#nav-wrap,
#nav-wrap ul,
#nav-wrap li,
#nav-wrap a {
margin: 0;
padding: 0;
}
/* nav-wrap */
#nav-wrap {
font: 13px "raleway-heavy", sans-serif;
text-transform: uppercase;
letter-spacing: 1.5px;
float: left;
}
/* hide toggle button */
#nav-wrap > a {
display: none;
}
ul#nav {
min-height: 66px;
display: inline-block;
width: auto;
/* left align the menu */
text-align: left;
}
ul#nav li {
position: relative;
list-style: none;
display: inline-block;
height: 66px;
}
/* Links */
ul#nav li a {
/* 14px padding top + 14px padding bottom + 38px line-height = 66px */
display: block;
padding: 14px 12px;
line-height: 38px;
text-decoration: none;
text-align: left;
color: #FFFFFF;
position: relative;
-moz-transition: color 0.2s ease-in-out;
-o-transition: color 0.2s ease-in-out;
-webkit-transition: color 0.2s ease-in-out;
-ms-transition: color 0.2s ease-in-out;
transition: color 0.2s ease-in-out;
}
ul#nav li a:hover {
color: #fdc501;
}
ul#nav li a:active {
background-color: transparent !important;
}
ul#nav li.current a {
color: #fdc501;
}
ul#nav li.current a:after {
position: absolute;
left: 50%;
bottom: 0;
width: 40px;
height: 2px;
margin-left: -23px;
background-color: white;
content: '\0020';
display: block;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
/* mobile navigation
--------------------------------------------------------------------- */
#media only screen and (max-width:768px) {
#nav-wrap {
z-index: 700;
display: block;
width: 100%;
float: none;
position: absolute;
top: 0;
right: 0;
}
/* mobile-btn and toggle-btn */
#nav-wrap > a {
border: none;
color: #FFFFFF;
height: 40px;
min-width: 40px;
font-size: 12px;
text-align: left;
float: right;
display: block;
padding: 0;
position: relative;
top: 13px;
right: 20px;
}
#nav-wrap > a:hover .menu-icon {
background: #FFFFFF;
}
#nav-wrap .menu-icon {
display: inline-block;
width: 24px;
height: 3px;
margin-top: -3px;
position: absolute;
right: 8px;
top: 50%;
bottom: auto;
left: auto;
background: #fdc501;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
font: 0/0 a;
text-shadow: none;
color: transparent;
}
#nav-wrap .menu-icon:before,
#nav-wrap .menu-icon:after {
content: '';
width: 100%;
height: 100%;
position: absolute;
background-color: inherit;
left: 0;
}
#nav-wrap .menu-icon:before {
bottom: 8px;
}
#nav-wrap .menu-icon:after {
top: 8px;
}
/* dropdown nav */
#nav-wrap ul#nav {
background: #1c212a;
padding: 54px 45px 60px 45px;
margin: 0;
height: auto;
display: none;
clear: both;
width: 100%;
float: none;
position: absolute;
top: 66px;
right: 0;
}
#nav-wrap ul#nav > li {
display: block;
float: none;
height: auto;
text-align: left;
border-bottom: 1px dotted rgba(200, 200, 200, 0.1);
padding: 6px 0;
}
#nav-wrap ul#nav > li:first-child {
border-top: 1px dotted rgba(200, 200, 200, 0.1);
}
#nav-wrap ul#nav li a {
display: block;
width: auto;
padding: 0;
color: #cacbcb;
padding: 12px 0;
line-height: 16px;
border: none;
}
#nav-wrap ul#nav li a:hover {
color: #FFFFFF;
}
#nav-wrap ul#nav li.current > a {
background: none;
color: #fdc501;
}
#nav-wrap ul#nav li.current > a:after {
display: none;
}
#nav-wrap a.mobile-btn {
display: none;
}
.js #nav-wrap a#toggle-btn {
display: block;
}
/* if js is disabled */
.no-js #nav-wrap:not(:target) > a:first-of-type,
.no-js #nav-wrap:target > a:last-of-type {
display: block;
}
.no-js #nav-wrap:target ul#nav {
display: block;
}
}
/* make sure the menu is visible on larger screens
--------------------------------------------------------------------- */
#media only screen and (min-width:769px) {
#nav-wrap ul#nav {
display: block !important;
}
}
<header id="main-header">
<div class="row">
<div class="logo">
SAT | Aloia Evelina
</div>
<nav id="nav-wrap">
<a class="mobile-btn" href="#nav-wrap" title="Show navigation">
<span class="menu-icon">Menu</span>
</a>
<a class="mobile-btn" href="#" title="Hide navigation">
<span class="menu-icon">Menu</span>
</a>
<ul id="nav" class="nav">
<li><a class="smoothscroll" href="#hero">Home.</a></li>
<li class="current"><a class="smoothscroll" href="#portfolio">Works.</a></li>
<li><a class="smoothscroll" href="#services">Services.</a></li>
<li><a class="smoothscroll" href="#about">About.</a></li>
<li><a class="smoothscroll" href="#contact">Contact.</a></li>
</ul> <!-- end #nav -->
</nav> <!-- end #nav-wrap -->
<ul class="header-social">
<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>
</ul>
</div>
</header> <!-- end header -->
<ul id="nav" class="nav">
<li><a class="smoothscroll" href="#hero">Home.</a>
<ul>
<li>#item1</li>
<li>#item1</li>
</ul>
</li>
<li class="current"><a class="smoothscroll" href="#portfolio">Works.</a>
<ul>
<li>#item1</li>
<li>#item1</li>
</ul>
</li>
<li><a class="smoothscroll" href="#services">Services.</a>
<ul>
<li>#item1</li>
<li>#item1</li>
</ul>
</li>
<li><a class="smoothscroll" href="#about">About.</a>
<ul>
<li>#item1</li>
<li>#item1</li>
</ul>
</li>
<li><a class="smoothscroll" href="#contact">Contact.</a>
<ul>
<li>#item1</li>
<li>#item1</li>
</ul>
</li> </ul>
in your html file you code should look something like this.
and then for more details on how you can style your code you can visit the site https://css-tricks.com/targetting-menu-elements-submenus-navigation-bar/
It provides some tricks in which you can style your menu as well as I how the html file should look like. I find it very much helpfull.
The problem in my code is that it is not rotating the :before ( { ) and :after ( } ) elements.
It rotates only if I set position: absolute on them, which disturbs their position and makes it difficult to bring back in wanted position
Can someone explain why this is happening?
Update: this code is working fine in chrome and IE 11 but not firefox. with firefox above problem
/* you should start reading from here..... */
a:before{
opacity: 0;
content: '{';
font-size: 40px;
line-height: 1;
transition: opacity 0.3s, transform 0.4s;
}
a:after{
opacity: 0;
content: '}';
font-size: 40px;
line-height: 1;
transition: opacity 0.3s, transform 0.4s;
}
a:hover:after{
opacity: 1;
transform: rotateX(1turn);
}
a:hover:before{
opacity: 1;
transform: rotateX(1turn);
}
/* no need to read after this */
a{
text-decoration: none;
color: black;
transition: color 0.3s;
position: relative;
}
a:hover{
color: red;
}
body{
margin: 0;
padding: 0;
font-size: 25px;
color: black;
font-weight: 700;
line-height: 1;
}
.nav{
display: block;
margin: 100px auto;
width: 80%;
text-align: center;
}
ul{
list-style: none;
display: inline-block;
padding: 0;
margin: 0;
border-top: 2px solid black;
border-bottom: 2px solid black;
}
li{
float: left;
margin: 0 20px;
padding: 15px 10px;
}
li a{
margin: 0;
padding: 0;
}
ul:after{
content: '';
display: table;
clear: both;
}
<div class="nav">
<ul>
<li>HELLO</li>
<li>HELLO</li>
<li>HELLO</li>
<li>HELLO</li>
<li>HELLO</li>
</ul>
</div>
giving the :before and :after element display: inline-block; does the trick.