Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Here is my CodePen: http://codepen.io/ScottBeeson/pen/rxquJ
So basically when you hover over an entity, a menu slides up. I'm trying to create a submenu for each menu item that basically mirrors the menu functionality, but slides down from the bottom of the menu. Here is an image of what it should look like:
And here is my current HTML:
<div class="entity">
<span class="menu"><div>A</div><div>B</div><div>C</div></span>
</div>
I can think of a couple ways to do this with JQuery, but I'm wondering if it's possible to do with CSS. Obviously, populating the menu will be via javascript, but I'm trying to use CSS as much as possible. So to put it in question form: If I put a static div with a class of "submenu" inside my entity, is there any way with CSS/LESS to trigger it when I hover over a div inside the menu?
I don't use LESS, so I can't help you with that.
However, I made you this code, which displays the menu on hover, and the submenu when you hover the menu items. You could set up the structure for a entity like this:
<div class="entity">
<ul>
<li>A
<ul>
<li>1</li>
<li>2</li>
</ul>
</li>
<li>B
<ul>
<li>1</li>
<li>2</li>
</ul>
</li>
<li>C</li>
</ul>
</div>
And combine it with this CSS:
.entity {
margin: 5px;
position: relative;
display: inline-block;
width: 260px;
height: 200px;
background-color: lightblue;
}
.entity ul {
display: none;
list-style: none;
margin: 0;
padding: 0;
position: absolute;
width: 100%;
background-color: rgb(0,0,0); /*fallback*/
background-color: rgba(0,0,0,.5);
bottom: 0px;
}
.entity li:hover {
background: black;
color: white;
}
.entity:hover > ul { /* only display direct ul child of .entity */
display: block;
}
.entity li {
display: inline-block;
padding: 10px;
}
.entity li > ul {
background: black;
}
.entity li:hover > ul {
display: block;
left: 0;
bottom: -100%;
}
I hope you can add the smooth effects yourself. Good luck.
Ow, and a DEMO
[EDIT]
Made a (bit sloppy though) animation using transitions, check the updated Fiddle.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have used the < div > tag to create a navigation menu bar but it only displays in a vertical fashion. However, I then changed the < div > tag into a < nav > tag, but still receive the same results in a vertical orientation.
On the ul add display: flex;
nav {
padding: 0;
width: 100%;
background: #262626;
overflow: hidden;
}
li a {
color: white !important;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {
background-color: gray;
}
li {
list-style: none;
}
ul {
display: flex;
}
<nav>
<ul>
<li>HOME</li>
<li>SERVICES</li>
<li>ABOUT US</li>
<li>CONTACT</li>
<li>NEWS</li>
<li>FAQ</li>
</ul>
</nav>
I'm trying to make a drop down menu but the hover is not producing the desired display effect. I just want the drop down menu to display when the mouse hovers over the list element. I'm new to HTML and CSS, so I can't pinpoint my error.
The relevant HTML:
#strip{
width: 950px;
height: 28px;
background-color: #2c276d;
font-size: 10pt;
}
.strip{
margin:0;
padding: 0;
}
.strip li{
list-style-type: none;
float: left;
}
.strip li a {
color: white;
text-decoration: none;
display: block;
text-align: center;
width:140px;
height:23px;
padding-top:5px;
border-right: 1px solid #FFFFFF;
}
.strip li.shrt a{
width: 145px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropcmpy {
display: none;
position: absolute;
background-color: #2c276d;
font-size: 10pt;
width: 145px;
}
.dropcmpy a {
color: white;
display: block;
text-decoration: none;
padding: 5px;
border-top: 1px solid #FFFFFF;
}
.strip li a:hover{
background-color: #28A2D5;
}
li.shrt:hover .dropcmpy {
display: block;
}
<div id="main">
<div id="strip">
<ul class="strip">
<li class="shrt">Com</li>
</ul>
</div>
<div class="dropcmpy">
Key
Ad
Fac
Car
FAQ
</div>
</div>
No matter how I format that last piece of CSS, it doesn't produce a drop down menu, unless I do
#main:hover .dropcmpy {
display: block;
}
or give the first div a class, and then use that. Otherwise the dropdown menu will not appear. This presents the issue that the entire strip will then produce the menu, while I want only the shrt to.
As john stated, selector .class1 .class2 is targeting an element with class="class2" that is a child of an element with class="class1".
which means you need to put the dropdown menu INSIDE the element, thats supposed to show the dropdown when hovered.
Usuall way is using another list inside the button, for example
<div id="main">
<div id="strip">
<ul class="strip">
<li class="shrt">
Com
<ul class="dropcmpy">
<li>Key</li>
<li>Ad</li>
<li>Fac</li>
<li>Car</li>
<li>FAQ</li>
</ul>
</li>
</ul>
</div>
</div>
and css
.dropcmpy {display: none;}
.shrt:hover .dropcmpy {display: block;}
That should do it, hope it was helpful :).
In order to show an object on hover with css, that object must be the sibling or child of the thing being hovered (As there are no parent selectors). This is not the case in your code.
So you have a few options:
Make div.dropcmpy a child of li.shrt. (As in Teuta Koraqi's answer)
Hack. Use an empty pseudo element (.dropcmpy::before) and absolutely position it over li.shrt, then use that as the hover element.
Use javascript
I don't know what the structure of your page is so can't say which of these would be best for you. The first is certainly the cleanest if you can manage it.
The problem is with inheritance. The last block that you are trying to use is looking for a .dropcmpy element that is a child of .shrt (which obviously doesn't exist). The reason the alternative works is because .dropcmpy is a child of #main.
I don't see any issue with using #main as the hover listener, since everything related to the dropdown is contained in it anyways.
After a reminder from #JohnCH, I realized you could do a sibling selector like this to get the functionality I think you want.
#strip:hover+.dropcmpy {
display: block;
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to format a navigation and its drop down in HTML and CSS.
DEMO
I have two problems.
First, on the right of the navigation there is space. But it should go all to the right like on the left side.
Second, I can't get the drop down items to fit below each other.
Could u tell me where the problems of the right space and the drop down items are?
/* Navi*/
nav ul {
margin-top: 0;
background-color: #FFF;
list-style: none;
padding: 0;
margin-left:0;
}
nav ul li {
display: block;
float:left;
background-color: #1C1C1C;
width: 33%;
text-align:center;
}
nav a {
display: list-item;
color: #FFF;
font-size: 23px;
line-height: auto;
text-decoration: none;
letter-spacing: 4px;
}
/* Dropdowns verstecken */
nav ul ul {
display: none;
position:fixed;
}
/* DropDowns */
nav ul ul li {
width: auto;
display: block;
float:left;
/*Üposition:relative;*/
padding-left:0;
margin-left:0;
}
/* DropDowns anzeigen */
nav ul li:hover > ul {
display: inherit;
}
/* Highliting wenn angezeigt */
nav a:hover {
background-color: #000000;
border-bottom: solid;
border-bottom-color: #8E96C0;
}
#kopfzeile {
position: fixed;
width: 1000px;
height: 60px;
background-color: #fa8072;
font-family: Quicksand;
opacity: 0.95;
margin:auto;
}
a {
color: #FFF;
}
<div id="kopfzeile">
<nav>
<ul>
<li>| HTML+ |
<!-- Erstes Drop Down -->
<ul>
<li>Was ist HTML?
</li>
<li>Befehlsübersicht
</li>
<li>Beispiele
</li>
</ul>
</li>
<li>| CSS+ |
<!-- Zweites Drop Down -->
<ul>
<li>Was ist CSS?
</li>
<li>Befehlsübersicht
</li>
<li>Beispiele
</li>
</ul>
</li>
<li>| PHP+ |
<!-- Drittes Drop Down -->
<ul>
<li>Was ist PHP
</li>
<li>Befehlsübersicht
</li>
<li>Beispiele
</li>
</ul>
</li>
</ul>
</nav>
</div>
Have a nice day,
Olker
There are several changes you need to make this happen.
Note: Before staring i guess you might have body{margin:0px;}. If not add it, but only if you want nav bar to leave no space.
1) Giving(adding) your nav width:100%; & margin:0px;. Along with the reason that your nav does not touches the right side is you need to give width:100%; to your #kopfzeile.
nav {
margin:0px;
width:100%;
}
#kopfzeile {
width: 100%; /* CHANGED */
}
2) Now remove float:left; by giving float:none; to your nav ul ul li{...}, to make them stack vertically. Along with that if you want text on left side also add left-align:left;
nav ul ul li
{
float:none;
text-align:left; /* Only if you want text left aligned*/
}
Updated Below:
3) For finishing to the li width's. You have width:33%; which is not actual dividing the 100% So you need to make it width:33.33%;
nav ul li {
display: block;
float:left;
background-color: #1C1C1C;
width: 33.33%; /* JUST CHANGED THIS ONE */
text-align:center;
}
JsFiddle : Updated
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to create a horizontal list that isn't precisely aligned, exactly like this: http://i.imgur.com/G8xWymZ.png (horizontal and scattered)
Here's what I've got so far:
HTML
<nav>
<ul id="menu">
<li>Random</li>
<li>Stand</li>
<li><a href="#>NAN</a></li>
<li>Tap</li>
<li>Mart</li>
<li>Dom</li>
</ul>
</nav>
CSS
nav {
position: relative;
top: 25px;
left: 290px;
}
nav ul
{
margin: 0;
padding: 0;
list-style-type: none;
underline: none;
}
nav ul li { display: inline; margin: 0px 20px 0px 0px;}
nav ul li a { color: red; font-size: 14px; text-decoration: none;}
As you can see, although the list is horizontal it is not 'unordered'/scattered as in the image. Any suggestions?
You can position the <li>-elements manually with position: relative and the position properties top, right, bottom, left. I have written a little example for you here: https://jsfiddle.net/c5bw1dbe/
I hope this helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need to align my submenu to the left with some margin and remove the border from the right side... but if I remove it, the border in the menu is also removed and I don't want this...
<nav>
<ul class="fancyNav">
<li id="quemsomos" class="menlog"><img src="imgs/Logo.png" width="37" height="45" />
</li>
<li id="quemsomos"><font face="din" size="4">QUEM SOMOS</font>
<!--start of sub menu-->
<ul>
<li>link the zone 1
</li>
<li>link2
</li>
<li>l for example
</li>
</ul>
<!--end of sub menu-->
http://jsfiddle.net/RHCn7/2/
DEMO
#quemsomos ul {
padding: 0;
margin-left: 5px;
}
#quemsomos ul li {
border: none;
}
EDIT(answer to the request in the comment):
DEMO
#quemsomos ul li {
border: none;
width: 100%;
text-align: left;
}
Add padding
ul li ul {
display: block;
border: 0;
position: absolute;
background-color: #D5D5D7;
opacity: 1;
padding: 8px;
}
Check this : http://jsfiddle.net/RHCn7/6/