I'm trying to use hover property for dropdown but I do not understand
how to use lab1, lab 2, lab 3 ,lab4, lab 5 when they are not defined.
I know how to use hover property but for multiple ul and li is little hard for me to get it.
Dropdowns are not coming down. All my other css properties are fine, I just need help in dropdown property. Any idea?
body {
font: 1.2em Verdana, sans-serif;
background-color: antiquewhite;
}
#header,
#footer {
background-color: #aaa;
padding: 0.5em;
}
#content h1 {
text-align: center;
}
#wrapper {
//background-color: hsl(200, 75%, 40%);
}
#content {
border-left: 8em solid hsl(200, 75%, 40%);
padding: 1em;
background-color: hsl(200, 75%, 60%);
box-sizing: border-box;
}
#leftnav {
float: left;
width: 8em;
box-sizing: border-box;
}
#leftnav ul {
list-style-type: none;
padding-left: 0px;
margin-left: 0px;
}
#leftnav li {
color: white;
background-color: hsl(200, 75%, 30%);
padding: 0.2em 0.5em;
border: solid white;
border-width: 1px 0;
}
#leftnav li:last-child {
border-bottom: none;
}
#leftnav li:first-child {
border-top: none;
}
#leftnav li:hover {
text-decoration: red;
color: red;
font-weight: bold;
text-transform: capitalize;
font-size: 20px;
background-color: white;
}
<div id="nav">
<ul>
<li>Lab 1
<ul>
<li> Basic XHTML </li>
</ul>
</li>
<li>Lab 2
<ul>
<li> Nesting Errors - Fixed </li>
<li> Block and Inline Elements </li>
<li> List of Links </li>
<li> Lab Index </li>
</ul>
</li>
<li>Lab 3
<ul>
<li> Merging Table Cells </li>
<li> Common Page Layout </li>
<li> XHTML Vocabulary </li>
<li> Vocabulary with Examples </li>
</ul>
</li>
<li>Lab 4
<ul>
<li> CSS - HTML Selectors </li>
<li> CSS - More Selectors </li>
<li> Table Styling </li>
<li> CS - Descendant Selectors </li>
</ul>
</li>
<li>Lab 5
<ul>
<li> Body Style </li>
<li> Inheriting Colours </li>
<li> Structuring Text </li>
<li> Another Lab Index </li>
</ul>
</li>
<p class="clearboth"></p>
</ul>
</div>
If i understand correctly, you are making a navbar and try to place the dropdown of the child element when people hover the parent element? The idea of ul-li-ul is that when you hover over a li element, the consequence ul will show up, so you don't actually need to define which lab is going to open which one.
#nav li ul{
display: none;
}
#nav li:hover>ul{
display: block;
position: absolute;
margin-left: 50px;
}
<ul id="nav">
<li>Basic XHTML</li>
<li>LAB 2
<ul>
<li> Nesting Errors - Fixed </li>
<li> Block and Inline Elements </li>
<li> List of Links </li>
<li> Lab Index </li>
</ul>
</li>
<li>LAB 3
<ul>
<li> Merging Table Cells </li>
<li> Common Page Layout </li>
<li> XHTML Vocabulary </li>
<li> Vocabulary with Examples </li>
</ul>
</li>
</ul>
Hope this helps.
You may use select tag. Example:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
The <select> element is used to create a drop-down list.
The <option> tags inside the <select> element define the available options in the list.
Code taken at: w3schools
Related
I have a div. And this div contains a very long list. This list becomes scrollable automatically.
This div is then inside another div, which fills out the entire screen.
Scrolling works fine, but it only works when the mouse is over the inner div, the one that actually contains all the data.
But I want scrolling to work, also when the mouse is over the parent div, the one that fills out the entire screen.
How do I do that?
You can see the sample here:
https://openage.org/fs/jsl_forritun/?page=hlutir
It doesn't scroll when the mouse is over the darker part. /:
you have two divs that contains your content body
id= "nhreyfing"
give him this style padding: 0 20vw; background: black
or what so ever padding you wanna give him
id= "content"
give him your rgb(213, 191, 134) background
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #2B2832;
}
.main {
margin: 0 auto;
padding: 40px;
width: 700px;
height: 100vh;
overflow-y: auto;
background: #D5BF86;
}
.main ul {
margin: 0;
padding: 0;
}
.main ul li {
list-style: none;
}
.main ul li:nth-child(n+2) {
margin: 10px 0 0;
}
.main ul li a {
padding: 10px;
display: flex;
color: #000;
background: #C6B076;
text-decoration: none;
}
<div class="main">
<ul>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
</ul>
</div>
Do the following:
remove CSS properties from
BODY element {height:100%}
remove {max-width: 800px} and add CSS to id="initial_screen_base" element:
div#initial_screen_base {
max-width: 100vw;
padding: 0px 20vw;
background-color: rgb(43, 40, 50);
}
if you want it to me maxed always to 800px (for smaller devices it will be full width), make it like this:
div#initial_screen_base {
background-color: rgb(43, 40, 50);
max-width: 100vw;
padding: 0;
padding-right: calc((100% - 800px)/2);
padding-left: calc((100% - 800px)/2);
}
for your id="node":
div#node {
background-color: rgb(213, 191, 134);
}
You should remove you inline CSS and put them in a style TAG inside your HEAD. That way you will fave more clear code for yourself to edit.
I have been tasked with styling a website, where I have encountered a hurdle regarding the horizontal alignment of elements inside list items.
I have replicated the structure of the menu in question with this JSFiddle.
I want to know how I can keep the position of the green divs (as shown from the start) when I expand the menu, using the button in the fiddle. I need them to keep horizontal alignment with the first <a> element in their respective <li> element, when the submenus are displayed.
you can do it like this for example:
<html>
<script>
function clickFunction(){
var elements = document.getElementsByClassName("submenu");
for(var i = 0; i < elements.length; i++){
elements[i].classList.toggle("display-sublist");
}
}
</script>
<style>
ul{
list-style-type: none;
margin: 0px;
padding: 0px;
}
ul li{
width: 100%;
background-color: blue;
}
.submenu{
display: none;
}
.display-sublist{
display: block;
}
ul li a{
width: 95%;
background-color: red;
}
.main-test {
display: inline-block;
float: left;
width: 90%;
}
.cancel-test{
display: inline-block;
background-color: green;
float: right;
width: 10%;
}
.expand-button{
clear: both;
display: block;
}
</style>
<body>
<ul>
<li>
<a class="main-test" href="#">Something</a>
<a class="cancel-test">x</div>
<ul class="submenu">
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
</ul>
</li>
<li>
<a class="main-test"href="#">Something</a>
<a class="cancel-test">x</a>
<ul class="submenu">
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
</ul>
</li>
<li>
Something
</li>
<li>
Something
</li>
</ul>
<button onclick="clickFunction()" class="expand-button">Expand</button>
</body>
</html>
This question already has an answer here:
How can I have perfectly centered navigation bar with equally wide links?
(1 answer)
Closed 6 years ago.
I wrote a navigation bar like this:
.site-nav ul {
margin: 0;
background-color: #09C;
line-height: 52px;
}
.site-nav li {
display: inline-block;
font-size: 14px;
}
.site-nav a {
display: inline-block;
}
<nav class="site-nav">
<ul>
<li>
首页
</li>
<li>
1
</li>
<li>
2
</li>
<li>
3
</li>
</ul>
</nav>
Now I need each <li> tag bisects the width of ul (it's parent). If the count of <li> is known, I can simply give an percentage to <li>,
in this case:
.site-nav li {
width: 25%;
display: inline-block;
font-size: 14px;
}
However, the <li> is dynamically generated ( I use razor), so I don't know how many <li> will generated.
So is there some way to achieve this?
use flexbox, and you can have it dynamic because you are using property flex-grow:1 in child li which will fill the remaining space available
If all items have flex-grow set to 1, the remaining space in the
container will be distributed equally to all children.
Flexbox Tutorial
.site-nav ul {
margin: 0;
background-color: #09C;
line-height: 52px;
display: flex
}
.site-nav li {
flex: 1;
font-size: 14px;
}
<nav class="site-nav">
<ul>
<li>
首页
</li>
<li>
1
</li>
<li>
2
</li>
<li>
3
</li>
</ul>
</nav>
You can play with flexbox. Check the snippet below.
.site-nav ul {
display: flex;
margin: 0;
padding: 0;
background-color: #09C;
line-height: 52px;
list-style: none;
}
.site-nav li {
flex-grow: 1;
flex-basis: 0;
font-size: 14px;
border: 1px solid white;
}
.site-nav a {
display: inline-block;
}
<nav class="site-nav">
2 columns:
<ul>
<li>
首页
</li>
<li>
1
</li>
</ul>
4 columns:
<ul>
<li>
首页
</li>
<li>
1
</li>
<li>
2
</li>
<li>
3
</li>
</ul>
8 columns:
<ul>
<li>
首页
</li>
<li>
1
</li>
<li>
2
</li>
<li>
3
</li>
<li>
首页
</li>
<li>
1
</li>
<li>
2
</li>
<li>
3
</li>
</ul>
</nav>
I am working on a genealogy website where I display a person's descendants in an unordered and indented list below their name.
Is there a way to join the bullets in this list by lines in order to form a family tree that branches downwards, using only HTML?
There is a very handy guide for this. Here is the fiddle:
Fiddle
HTML:
<ul class="tree"> <li>Animals <ul> <li>Birds</li> <li>Mammals <ul> <li>Elephant</li> <li class="last">Mouse</li> </ul> </li> <li class="last">Reptiles</li></ul>
CSS:
ul.tree, ul.tree ul { list-style-type: none; background: #fff url(http://odyniec.net/articles/turning-lists-into-trees/vline.png) repeat-y; margin: 0; padding: 0; } ul.tree ul { margin-left: 10px; } ul.tree li { margin: 0; padding: 0 12px; line-height: 20px; background: url(http://odyniec.net/articles/turning-lists-into-trees/node.png) no-repeat; color: #369; font-weight: bold; } ul.tree li.last {
background: #fff url(http://odyniec.net/articles/turning-lists-into-trees/lastnode.png) no-repeat;
}
Source:
http://odyniec.net/articles/turning-lists-into-trees/
<ul>
<li>John Doe
<ul>
<li>John Doe's Descendant A</li>
<li>John Doe's Descendant B</li>
</ul>
</li>
<li>Jane Somebody
<ul>
<li>Jane Somebody's Descendant A</li>
<li>Jane Somebody's Descendant B</li>
</ul>
</li>
</ul>
Edit: Or Something a little more involved.
https://jsfiddle.net/hm2uq1zs/
Or:
https://jsfiddle.net/hm2uq1zs/1/
I have the following code to show a division on hover. It is initially hidden and i'm trying to show one division on hover of another element.
.topNav {
padding: 1px 15%;
background: #006cb4;
color: white;
}
.mainMenu {
list-style-type: none;
}
.mainMenu li {
display: inline-block;
padding: 3px 15px;
font-size: 20px;
}
.mainMenu li a {
text-decoration: none;
color: white;
}
#item1 {
display: block;
}
#item1:hover #item1detail {
background: #444;
visibility: visible;
}
#item1detail {
position: absolute;
top: 152px;
left: 250px;
background: #ccc;
width: 750px;
height: 400px;
border: solid 1px black;
border-radius: 0 0 10px 10px;
visibility: hidden;
}
<div class="topNav">
<ul class="mainMenu">
<li><a id="item1" href=""> item 1</a>
</li>
<li> item 3
</li>
<li> item 4
</li>
<li> item 5
</li>
<li> item 6
</li>
<li> item 7
</li>
<li> item 8
</li>
<li> item 9
</li>
</ul>
<div id="item1detail">
Some random content
</div>
</div>
on hover of the list item item1 i want to show the division itemdetail. The above code is not working. What am i doing wrong?
As I see it the only solution to display the given div without touching the HTML would be Javascript... As the others suggested already...
BUT... there's a solution with one slight change to your HTML and CSS each.
The main problem is this CSS-selector:
#item1:hover #item1detail
which would translate to "id item1detail INSIDE of an hovered id item1".
You can fix this by placing the div inside of the li and change the selector to:
#item1:hover + #item1detail
Since the div is positioned absolute anyway it doesn't make a visual difference... at least for your snippet...
Updated version of your snippet:
.topNav
{
padding: 1px 15%;
background: #006cb4;
color: white;
}
.mainMenu
{
list-style-type: none;
}
.mainMenu li
{
display: inline-block;
padding: 3px 15px;
font-size: 20px;
}
.mainMenu li a
{
text-decoration: none;
color: white;
}
#item1
{
display: block;
}
#item1:hover + #item1detail
{
background: #444;
visibility: visible;
}
#item1detail
{
position: absolute;
top: 152px;
left: 250px;background: #ccc;
width: 750px;
height: 400px;
border:solid 1px black;
border-radius: 0 0 10px 10px;
visibility: hidden;
}
<div class="topNav">
<ul class="mainMenu">
<li >
<a id="item1" href=""> item 1</a>
<div id="item1detail">
Some random content
</div>
</li>
<li> item 3</li>
<li> item 4</li>
<li> item 5</li>
<li> item 6</li>
<li> item 7</li>
<li> item 8</li>
<li> item 9</li>
</ul>
</div>
You'll have to use javascript
<script>
function myFunction() {
if (document.getElementById("item1detail").hidden==false){
document.getElementById("item1detail").hidden = true;
}else{
document.getElementById("item1detail").hidden = false;
}
}
</script>
and
<div class="topNav">
<ul class="mainMenu">
<li><a id="item1" onhover="myFunction()" href=""> item 1</a>
</li>
<li> item 3
</li>
<li> item 4
</li>
<li> item 5
</li>
<li> item 6
</li>
<li> item 7
</li>
<li> item 8
</li>
<li> item 9
</li>
</ul>
<div id="item1detail">
Some random content
</div>
</div>
I would do that using jQuery.
$('#item1').hover(function(){
$('#item1detail').show();
}, function(){
$('#item1detail').hide();
});
The reason your CSS isn't working is because you're using this selector:
#item1:hover #item1detail
Which selects the element with id #item1detail occurring within the element with id #item1, if the #item1 element is hovered.
In your current markup, #item1detail is outside #item1, and so does not match the selector. Moving #item1detail should get you the behavior you want. (And there will probably be some layout work to do from that point.)
The #item1detail element is not a sibling of the #item1 element, so that is why the #item1:hover #item1detail CSS rule does not apply as you expect it to.
I believe if this is to work with CSS only (not JavaScript), then you will have to make #item1detail a sibling of #item1.