First time user here.
I have created a vertical menu and i want it to expand (on hover) to the right into a DIV to show an image. The problem is that when the menu expands, the top of the DIV is aligned with the top of the menu element taht is on hover and i want the top of the DIV to align to the top of the first menu element no matter wich element is on hover.
Here's the code i have so far...
<nav>
<ul>
<li id="menu-1">menu-1
<div class="nav-expand">
<img src="img/1.png">
</div>
</li>
<li id="menu-2">menu-2
<div class="nav-expand">
<img src="img/2.png">
</div>
</li>
<li id="menu-3">menu-3
<div class="nav-expand">
<img src="img/3.png">
</div>
</li>
</ul>
</nav>
</body>
and the CSS
nav {
float:left;
width:192px;
}
nav li {
position:relative;
display:block;
width:176px;
height:29px;
margin-bottom:1px;
background:#EEE;
}
nav li:last-child {
height:30px;
}
nav li:hover {
background:#09B2B3;
width:192px;
-webkit-transition:all .3s ease;
-moz-transition:all .3s ease;
-o-transition:all .3s ease;
transition:all .2s ease;
}
.nav-expand {
display:none;
background:#FFF;
border:2px solid #09B2B3;
position:absolute;
left:192px;
top:0;
z-index:1001;
width:556px;
height:356px;
overflow:hidden;
}
#navigation .nav-expand a {
margin-left:0;
display:block;
width:560px;
height:360px;
}
.nav-expand {
width:556px;
height:356px;
}
nav li:hover > .nav-expand {
display:block;
}
I realized that i could use a different class for every element of the menu and use an absolute position, but was wondering if there's a better way to do it.
I think you can remove the 'position: relative' from your .nav li and add it to .nav ul.
.nav > ul{
position: relative;
}
There are better ways of doing this then the way you have approached.
Actually, menu-1, 2, 3 are all positioned relative and the nav-expand is positioned absolute.
Here's the working code
CSS:
nav {
float:left;
width:192px;
}
nav li {
display:block;
width:176px;
height:29px;
margin-bottom:1px;
background:#EEE;
}
nav li:last-child {
height:30px;
}
nav li:hover {
background:#09B2B3;
width:192px;
-webkit-transition:all .3s ease;
-moz-transition:all .3s ease;
-o-transition:all .3s ease;
transition:all .2s ease;
}
.nav-expand {
background:#FFF;
border:2px solid #09B2B3;
position:absolute;
left:240px;
top:24px;
z-index:1001;
width:556px;
height:356px;
overflow:hidden;
display:none;
}
#navigation .nav-expand a {
margin-left:0;
display:block;
width:560px;
height:360px;
}
.nav-expand {
width:556px;
height:356px;
}
nav li:hover > .nav-expand {
display:block;
}
Related
Good afternoon,
I'm trying to update BESIX Group Structure with an accordion (made with css only) with checkboxes.
My issue is: I don't find the reason when I click on a tab, the content goes over the footer and the rest of the content..
Could you help me?
Link: https://www.besix.com/en/about/2019-group-structure
Thanks,
Kind regards,
I tried a lot of differents codes on Codepen, like this one: https://codepen.io/vinsongrant/pen/qbGKed -> Same issue
or this one https://codepen.io/geoffgraham/pen/wvlgs, it's not working at all on our Sitecore environment.
.accordion {
position:relative;
font-family:Oxygen, sans-serif;
margin:0 auto;
font-size:14px;
border-radius:10px;
width:100%;
padding:10px;
background:#fff;
}
.accordion ul {
list-style:none;
margin:0;
padding:0;
}
.accordion li {
margin:0;
padding:0;
}
.accordion [type=radio], .accordion [type=checkbox] {
display:none;
}
.accordion label {
display:block;
font-size:16px;
line-height:16px;
background:#0099da;
color:#fff;
cursor:pointer;
text-transform:uppercase;
-webkit-transition: all .2s ease-out;
-moz-transition: all .2s ease-out;
}
.accordion ul li label:hover, .accordion [type=radio]:checked ~ label, .accordion [type=checkbox]:checked ~ label {
background:#21409a;
color:#FFF;
text-shadow:1px 1px 1px rgba(0,0,0,0.5)
}
.accordion .contentaccordion {
padding:0 10px;
overflow:hidden;
border:1px solid #fff; /* Make the border match the background so it fades in nicely */
-webkit-transition: all .5s ease-out;
-moz-transition: all .5s ease-out;
max-height:2000px;
background:#fff;
position:relative;
z-index:99;
}
The problem is not in the accordion. There is an inline style, hardcoded or added by JavaScript.
You need to remove it in order to push the content instead to go over it.
<div class="col-md-4 col-sm-6 matchHeight" style="height: 362px">
CSS animation, help requred, On hover, line should turn red start from left to right. When remove mouse it should reverse.
https://i.stack.imgur.com/dct34.png
You can try this:
ul {
margin:0px;
padding:0px;
list-style:none;
}
ul li {
display:block;
}
ul li a {
text-decoration:none;
padding:10px;
position:relative;
transition:all 0.3s linear
}
ul li a:hover {
text-decoration:none;
}
ul li a:after {
content:'';
display:block;
position:absolute;
left:0px;
bottom:0px;
width:0px;
height:1px;
background:tomato;
transition:all 0.3s linear
}
ul li a:hover:after {
width:100%;
}
<ul>
<li>Home</li>
</ul>
I have a -90deg menu bar, the clickable buttons are also -90deg.. I am wondering if there is anyway I can add a dropdown menu to one of my buttons , test5/nth-child(5) is the one I would like to add a dropdown menu to, if possible I would appreciate it, if its possible to do the dropdown at -90deg that would be great, if not i can deal with horizontal that will also work great , Thanks Again
https://jsfiddle.net/nyjhfr8g/2/
CSS -
body {
font-family:Verdana,Geneva,sans-serif;
color:#FFF;
font-size:12px;
font-family:Trebuchet MS,Arial,Helvetica;
text-align:center;
background:url() no-repeat center 0,#000 url() left top;
background-size:1670px 950px;
}
p {
margin-bottom:10px;
line-height:21px;
}
a {
color:#F09;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
#right_menu {
position:fixed;
font-size:15px;
top:0;
right:0;
background-color:#FF00FF;
width:50px;
height:100%;
}
#right_menu a {
text-align:center;
display:block;
padding:10px;
height:15%;
width:50px;
margin-bottom:0;
text-transform:uppercase;
position:relative;
}
#right_menu a:nth-child(1) {
background-color:#FF00FF;
color:#FFF;
}
#right_menu a:nth-child(1) span {
display:block;
position:absolute;
top:40px;
left:-40px;
width:130px;
color:#FFF;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
transition:left .3s ease;
}
#right_menu a:nth-child(1):hover span {
left:-45px;
}
#right_menu a:nth-child(2) {
background-color:#FF00FF;
color:#FFF;
}
#right_menu a:nth-child(2) span {
display:block;
position:absolute;
top:20px;
left:-40px;
width:130px;
color:#FFF;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
transition:left .3s ease;
}
#right_menu a:nth-child(2):hover span {
left:-45px;
}
#right_menu a:nth-child(3) {
background-color:#FF00FF;
color:#FFF;
}
#right_menu a:nth-child(3) span {
display:block;
position:absolute;
top:20px;
left:-40px;
width:130px;
color:#FFF;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
transition:left .3s ease;
}
#right_menu a:nth-child(3):hover span {
left:-45px;
}
#right_menu a:nth-child(4) {
background-color:#FF00FF;
color:#FFF;
}
#right_menu a:nth-child(4) span {
display:block;
position:absolute;
top:20px;
left:-40px;
width:130px;
color:#FFF;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
transition:left .3s ease;
}
#right_menu a:nth-child(4):hover span {
left:-45px;
}
#right_menu a:nth-child(5) {
background-color:#FF00FF;
color:#FFF;
}
#right_menu a:nth-child(5) span {
display:block;
position:absolute;
top:20px;
left:-40px;
width:130px;
color:#FFF;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
transition:left .3s ease;
}
#right_menu a:nth-child(5):hover span {
left:-45px;
}
#right_menu a:nth-child(6) {
background-color:#FF00FF;
color:#FFF;
}
#right_menu a:nth-child(6) span {
display:block;
position:absolute;
top:20px;
left:-40px;
width:130px;
color:#FFF;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
transition:left .3s ease;
}
#right_menu a:nth-child(6):hover span {
left:-45px;
}
HTML -
<div id="right_menu">
<span>testing</span>
<span>testing</span>
<span>testing</span>
<span>testing</span>
<span>Drop MENU</span>
<span>testing</span>
</div>
OK...not perfect but I think I have it down enough so you can tweak to suit your requirements.
The first thing is to use a wrapper to hold the menu..in this case, I've used a nav. What this allows us to do is build the menu as normal but transform the wrapper nav to position the whole thing as we want.
So.
This is our structure :
<nav>
<ul id="right_menu">
<li>Item 1
</li>
<li>Item 2
</li>
<li>Item 3
</li>
<li>Item 4
<ul class="sub_menu">
<li>Sub-item 1
</li>
<li>Sub-item 2
</li>
<li>Sub-item 3
</li>
</ul>
</li>
<li>Item 5
</li>
</ul>
</nav>
Then we position the nav so that it's fixed to the top / right but we then rotate it 90 degrees (actually -90 degrees). To adjust the point at which the nav rotates we use transform-origin and a small translateX equal to the height of the nav
nav {
height: 50px;
line-height: 50px;
background: #FF00FF;
position: fixed;
top:50;
right:0;
width: 100vh; /* I'm always the height (after rotation) of the viewport */
transform-origin:top right;
transform:translateX(-50px) rotate(-90deg);
}
So, now we have the nav in the right place but the menu itself would have the wrong order.
We solve that by floating the list-items to the right and so they are now reverse and the first one is now at the top of the rotated menu.
#right_menu > li {
float: right;
text-transform:uppercase;
position: relative;
color:white;
list-style:none;
}
OK...first level done.
Second level is another ul but we position it absolutely
.sub_menu {
display: none;
position: absolute;
top:-100%; /* now to the "left" of the parent */
left:50%;
transform:translateX(-50%); /* center it over the parent */
width: auto;
white-space: nowrap; /* allows the sub menu to be wider than parent */
}
Final Result Codepen
Note: I've restricted myself to the positioning...I'm not sure everything else is there yet but I think the basics are there.
I'm newbie in html and css and I have to build a dropdown menu. I've found many examples in here.
As I can't use JS, I would like to, whenever in a subpage, have the options be highlighted and keep the box open. So far, I can highlight the options easily but the block keep closing (and don't show up open when open the page).
The code is in here and the idea is to keep the submenu inside Menu 3 open (as if you were in Link 4 page).
Does anyone have any idea on how to solve this? Cheers!
Code:
HTML:
<ul id="nav">
<li> Menu 1</li>
<li>Menu 2
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</li>
<li>Menu 3
<ul>
<li>Link 3</li>
<li><a style="background:#d4d5d8;" href="#">Link 4</a></li>
<li>Link 5</li>
</ul>
</li>
<li>Menu 4</li>
</ul>
CSS:
nav {
border:3px solid #3e4547;
box-shadow:2px 2px 8px #000000;
border-radius:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
#nav, #nav ul {
list-style:none;
padding:0;
width:200px;
}
#nav ul {
position:relative;
z-index:-1;
}
#nav li {
position:relative;
z-index:100;
}
#nav ul li {
margin-top:-23px;
-moz-transition: 0.4s linear 0.4s;
-ms-transition: 0.4s linear 0.4s;
-o-transition: 0.4s linear 0.4s;
-webkit-transition: 0.4s linear 0.4s;
transition: 0.4s linear 0.4s;
}
#nav li a {
background-color:#d4d5d8;
color:#000;
display:block;
font-size:12px;
font-weight:bold;
line-height:28px;
outline:0;
padding-left:15px;
text-decoration:none;
}
#nav li a.sub {
background:#d4d5d8;
}
#nav li a + img {
cursor:pointer;
display:none;
height:28px;
left:0;
position:absolute;
top:0;
width:200px;
}
#nav li a img {
border-width:0px;
height:24px;
line-height:28px;
margin-right:8px;
vertical-align:middle;
width:24px;
}
#nav li a:hover {
background-color:#bcbdc1;
}
#nav ul li a {
background-color:#eee;
border-bottom:1px solid #ccc;
color:#000;
font-size:11px;
line-height:22px;
}
#nav ul li a:hover {
background-color:#ddd;
color:#444;
}
#nav ul li a img {
border-width:0px;
height:16px;
line-height:22px;
margin-right:5px;
vertical-align:middle;
width:16px;
}
#nav a.sub:focus {
background:#bcbdc1;
outline:0;
}
#nav a:focus ~ ul li {
margin-top:0;
-moz-transition: 0.4s linear;
-ms-transition: 0.4s linear;
-o-transition: 0.4s linears;
-webkit-transition: 0.4s linears;
transition: 0.4s linear;
}
#nav a:focus + img, #nav a:active + img {
display:block;
}
#nav a.sub:active {
background:#bcbdc1;
outline:0;
}
#nav a:active ~ ul li {
margin-top:0;
}
#nav ul:hover li {
margin-top:0;
}
#nav a.subactive {
background:#bcbdc1;
outline:0;
}
The key part here seem to be with this class I created but not sure what put inside.
#nav a.subactive {
background:#bcbdc1;
outline:0;
}
Normally I find adding things like
#nav ul ul{
display: block !important;
}
or
div.container {
height: auto !important;
opacity: 1 !important;
}
would work, however it would appear that because focus is lost, it closes. I did have luck with the div.container but it only remained open for a short period longer than normal before closing again. Hopefully this helps if even just a tad.
!important is used to over-ride the inline styles that are applied with js so you can probably get away without using that since you are avoiding js.
How to modify this code to display list in horizontal line menu
Currently this code displays in vertical
I want it in horizonyal line form
how make it display list in horizontal line form?
<html><head><style>
.metromenu {
display:block;;
position:relative;
width:40%;
margin:0 auto;
z-index:1;
}
.metromenu, .sub-metromenu {
list-style:none;
}
.metromenu li {
display:inline-block;
float:left;
margin-right:2px;
margin-top:2px;
}
.metromenu a{
display:block;
position:relative;
width:120px;
height:32px;
text-decoration:none;
font-family:'arial';
text-align:center;
letter-spacing:2px;
line-height:26px;
color:#fff;
padding:6px 20px 0 20px;
background-color: hsl(200,70%,50%);
-webkit-transition:all 0.2s ease-out;
-moz-transition:all 0.2s ease-out;
-o-transition:all 0.2s ease-out;
}
.metromenu a:hover {
background-color: hsl(200,80%,65%);
}
.metromenu span {
display:inline-block;;
position:absolute;
top:18px;
right:10px;
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 6px solid #fff;
}
.metromenu li:hover > a{ /* activates link when mouse over sub-metromenu */
background-color: hsl(200,80%,65%);
}
/*sub-metromenu trigger*/
.metromenu li a:hover ~ ul{
opacity:1;
visibility:visible;
}
.sub-metromenu {
opacity:0;
visibility:hidden;
position:absolute;
z-index:10;
-webkit-transition:all 0.2s ease-out;
-moz-transition:all 0.2s ease-out;
-o-transition:all 0.2s ease-out;
}
.sub-metromenu:hover {
opacity:1;
visibility:visible;
}
.sub-metromenu li a{
background-color: hsl(250,70%,60%);
}
.sub-metromenu li:first-child a{
height:72px;
}
.sub-metromenu li a:hover{
background-color: hsl(250,80%,70%);
}
.metromenu .orange {
background-color: hsl(20,70%,60%);
}
.metromenu .orange:hover {
background-color: hsl(20,80%,70%);
}
.metromenu .green {
background-color: hsl(110,60%,60%);
}
.metromenu .green:hover {
background-color: hsl(110,70%,70%);
}
</style>
</head>
<body>
<div>
<ul class="metromenu">
<li>Web Tools</li>
<li>Smartphones<span></span>
<ul class="sub-metromenu">
<li>Latest Smartphones</li>
<li>Windows</li>
<li>Android</li>
</ul>
</li>
<li>Others</li>
</ul>
</div> </body> </html>
I took code from here http://codepen.io/maxim/pen/DrvLx
Try this
.metromenu {
display: block;
margin: 0 auto;
position: relative;
width: 100%;
z-index: 1;
}
I changed the width from 40% to 100%. Here is the fiddle. Let me know if this was helpful or if you have any queries.
Edit I [sub menu fix]: Also set the width for sub-menu or they will go vertical.
.sub-metromenu {
opacity:0;
visibility:hidden;
position:absolute;
z-index:10;
-webkit-transition:all 0.2s ease-out;
-moz-transition:all 0.2s ease-out;
-o-transition:all 0.2s ease-out;
width: 10%;
}
Updated fiddle