I have a checkbox and label in my header im using for a side menu.
However, its not working and the selector of being checked isn't working.
See here: https://jsfiddle.net/jpjL3hhp/
That should when clicked show a side bar.
However, it works here when my header isn't involved in the code: https://jsfiddle.net/jpjL3hhp/1/
What is causing the problem?
Working code:
<input type="checkbox" id="menu_collapse_icon">
<label for="menu_collapse_icon" class="menu_collapse_icon_label">Show Menu</label>
<div class="side-navigation">
<ul>
<li>
Login
</li>
</ul>
</div>
Not working:
<header>
<input type="checkbox" id="menu_collapse_icon">
<label for="menu_collapse_icon" class="menu_collapse_icon_label">Show Menu</label>
<div class="side-navigation">
<ul>
<li>
Login
</li>
</ul>
</div>
</header>
This is used for the check:
#menu_collapse_icon:checked ~ .side-navigation {
margin-right: 0;
}
The problem is your HTML structure.
You are using #menu_collapse_icon:checked ~ .side-navigation as the selector.
In the non-working example where you integrated with all the header it doesn't work because your .side-navigation isn't being selected since its not in the same level as #menu_collapse_icon.
So if you place the .side-navigation in the same level as #menu_collapse_icon it will work.
Like this:
.side-navigation {
right: 0;
height: 100%;
background-color: white;
width: 200px;
margin-top: 106px;
margin-right: -200px;
transition: margin-right 0.5s ease;
position: fixed;
}
#menu_collapse_icon:checked ~ .side-navigation {
margin-right: 0;
}
header {
position: fixed;
height: 100px;
background-color: blue;
width: 100%;
}
header nav ul li {
float: left;
}
<header>
<div class="max-container">
<input type="checkbox" id="menu_collapse_icon">
<label for="menu_collapse_icon" class="menu_collapse_icon_label">
Show Menu
</label>
<div class="side-navigation">
<ul>
<li> Login
</li>
<li> Jobs
</li>
<li> Employers
</li>
</ul>
</div>
</div>
</header>
Related
I put together a treeview control with HTML and CSS, that can display the nodes as an Org chart or a classic treeview list.
In the CodePen, each node has a set width: 100px.
How can I fit the content of the div (using display: inline-block for example), but keep the layout of the chart as it is?
The layout of the tree as you see it is exactly as I want it, apart from the set width. When I tried to replace width: 100px with display: inline-block, the layout changes completely and whatever I tried only made it worse.
As for the layout:
org-view: If a node is directly within a red rectangle box, is children should
be displayed horizontally (eg: A, F, M and N are horizontally
displayed under Root Node). The parent node is centered in the middle of its first and last child (Root Node is centered in the middle of A and N)
list-view: If a node is directly within a green rectangle box, its children will appear below, vertically.
HTML:
<head>
<meta charset="UTF-8" />
<title>Hierarchy Chart</title>
</head>
<link rel="stylesheet" href="hierarchy-chart.css">
<body>
<div class="wbs">
<ol class="org-view">
<li>
<div class="node" for="node-1">1. Root node</div>
<input type="checkbox" checked id="node-1" />
<ol class="list-view">
<li>
<div class="node" for="node-1-1">AAAA</div>
<input type="checkbox" checked id="node-1-1" />
<ol class="list-view">
<li>
<div class="node">BBBB</div>
</li>
</ol>
<ol class="org-view">
<li>
<div class="node" for="node-1-1-2">CCCC</div>
<input type="checkbox" checked id="node-1-1-2" />
<ol class="list-view">
<li>
<div class="node">DDDD</div>
</li>
</ol>
<ol class="list-view">
<li>
<div class="node">EEEE</div>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<ol class="org-view">
<li>
<div class="node" for="node-1-2">FFFF</div>
<input type="checkbox" checked id="node-1-2" />
<ol class="list-view">
<li>
<div class="node" for="node-1-2-1">GGGG</div>
<input type="checkbox" checked id="node-1-2-1" />
<ol>
<li>
<div class="node">HHHH</div>
</li>
<li>
<div class="node">IIII</div>
</li>
</ol>
</li>
</ol>
<ol class="list-view">
<li>
<div class="node" for="node-1-2-2">JJJJ</div>
<input type="checkbox" checked id="node-1-2-2" />
<ol>
<li>
<div class="node">KKKK</div>
</li>
<li>
<div class="node">LLLL</div>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<ol class="list-view">
<li>
<div class="node">MMMM</div>
</li>
</ol>
<ol class="list-view">
<li>
<div class="node">NNNN</div>
</li>
</ol>
</li>
</ol>
</div>
</body>
</html>
CSS
body {background-color: white;}
.wbs {
display: grid;
border: 4px solid #eee;
position: relative;
}
.wbs ol {
list-style-type: none;
padding-left: 10px;
}
.org-view {
border: 1px dashed red;
margin: auto;
}
.org-view >li > .node:first-child {
margin-left: auto;
margin-right: auto;
}
.list-view {
border: 1px dashed lightgreen;
vertical-align: top;
}
/* Tree view collapsible functionalities */
.wbs input {
//display: none;
}
.wbs input ~ ol {
display: none;
}
.org-view >li > .node:first-child {
margin-left: auto;
margin-right: auto;
}
.org-view > li > input:checked ~ ol {
display: inline-block;
}
.org-view .list-view input:checked ~ ol {
display: block;
}
.org-view .org-view input:checked ~ ol {
display: inline-block;
}
.node {
margin-top: 10px;
}
.node {
color: blue;
position: relative;
background-color: white;
border-radius: 3px;
border: 2px solid #4285F4;
//display: inline-block;
width: 100px;
padding: 4px;
vertical-align: top;
}
To me it seems fine.
If you want the nodes to cause a line break, you could wrap them within a <div> element, so they would have a block element breaking the lines.
Also, you might wanna center them.
Here's a fork of your CodePen: https://codepen.io/anon/pen/jYdEro?editors=1100#
Had only the first nodes. I'm too lazy to actually do the entire thing - but you'll get the point :)
Some explanation:
Added a new wrapper element for each node element named node-wrapper. The default display for <div> elements is block so that takes care of the line breaks. The styles for that element:
.node-wrapper {
text-align: center;
}
Since the node element is inline-block, we can center it by using text-align on the parent element.
I have been searching for a way to change the background image of my banner when I hover my menu bar.
here you have my html
<div id="container">
<header>
<nav>
<ul>
<li>
home
</li>
<li>
bedrijf
</li>
<li>
diensten
</li>
<li>
foto's
</li>
<li>contacteer ons</li>
</ul>
</nav>
</header>
So what i wanna do is when I hover over one of my buttons the background of header should change to a picture I pick for this page.
I hope this is possible it would be great.
You could do that in jQuery:
$("li > a").hover(function(){
$("header").css("background-image", "img.jpg");
});
This code says if you hover over an element with a-Tag which is in a li-Tag then it changes the background-image of the header to img.jpg.
Now if you want that the background-image changes back if you don't hover then add this code too:
$("li > a").mouseleave(function(){
$("header").css("background-image", "none");
});
You could use pseudo elements (:before) on the LI's when you hover over them.
It's a bit hacky, but does work and without javascript too.
working demo here:
http://jsfiddle.net/ezjjyptk/
Here is a solution I've come up with. Basically, add an empty, absolutely positioned div inside each <li> element, and move it up from behind the header on hover.
JSFiddle
<div id="container">
<header>
<nav>
<ul>
<li>
home
<div style="background:green">
</div>
</li>
<li>
bedrijf
<div style="background:yellow">
</div>
</li>
<li>
diensten
</li>
<li>
foto's
</li>
<li>contacteer ons</li>
</ul>
</nav>
</header>
header {
position: relative;
width: 100%;
background: red;
}
ul li a {
position: relative;
z-index: 3;
}
ul li:hover div {
z-index: 1;
}
ul li div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
I wouldn't say it's impossible without javascript, but I certainly wouldn't call this code pretty
.fixed {
position: absolute;
top: 50px;
left: 0;
opacity: 0;
transition: opacity .5s ease-in-out;
}
li {
display: inline-block;
}
.show1:hover + #header1 {
opacity: 1;
}
.show2:hover + #header2 {
opacity: 1;
}
.show3:hover + #header3 {
opacity: 1;
}
.show4:hover + #header4 {
opacity: 1;
}
<li>
<a class="show1" href="index.html">Show 1</a>
<img class="fixed" id="header1" src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Color_blocks.svg/800px-Color_blocks.svg.png" />
</li>
<li>
<a class="show2" href="bedrijf.html">Show 2</a>
<img class="fixed" id="header2" src="http://static1.squarespace.com/static/534d1b21e4b077040469bae0/t/5362730de4b04c365eb65a37/1398960956409/The+two+colour+shirt" />
</li>
<li>
<a class="show3" href="diensten.html">Show 3</a>
<img class="fixed" id="header3" src="http://i1.wp.com/makeapowerfulpoint.com/wp-content/uploads/2015/03/Drunk-Tank-Pink.png" />
</li>
<li>
<a class="show4" href="pictures.html">Show 4</a>
<img class="fixed" id="header4" src="http://3.bp.blogspot.com/-YFX5nFtmjiA/T7co_rB3keI/AAAAAAAAI0c/EkNV9tX3xt8/s920/color%2Bwheel%2Bstar%2Bblock%2Blogo%2Bv1.jpg" />
</li>
I'm trying to make my site mobile friendly by creating a collapsible menu when a device that is 480px or smaller is used. I found a great demo and it works perfectly: How To Create A Responsive Navigation Menu Using Only CSS
I want to customize the menu and put it in a Header div tag. You can go to the link above to see the full code for this. It DOES work, however, if I insert the HTML code into a div tag, it stops working! I can put the entire amount of code into a div tag, but that defeats the purpose of using straight HTML and CSS ONLY to create this collapsible menu!
I want to set this up as a two-column website when it is viewed on a laptop or PC with the menu on the left. I have that working just fine, but as soon as I change the menu to use the collapsible menu inside the header div, it stops working!
So my code is as follows:
<div id="header">
<div class="topcenter">
<p>Consultants and Suppliers of <br />Affordable, Natural, Quality,
<br />Sustainable Power Solutions!</p>
</div>
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
</div>
<div class="wrapper">
<div id="left">
<ul id="menu">
<li><a href="#" title="Power" >Power Up Belize</a></li>
<li>Services</li>
<li>Experience</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
And the CSS is almost exactly the same as in the example - I've proven that it works when the label and input box are NOT inside the header div tag, but it ALSO breaks as soon as I put the menu HTML inside the wrapper div! What gives? How come I can't get the input box to work correctly inside a div tag?
Any help on this would be greatly appreciated! Thanks in advance!
Here is my updated code (and it still doesn't work :-( )
#media screen and (max-width : 480px)
{
/*Change Header imge and font size for Mobile */
#header
{
position: relative;
top: .25em;
text-align: center;
font-size: 90%;
font-weight: Bold;
padding-bottom: 2.5em;
background-image: url('../images/PUBLogoSm.png');
background-repeat: no-repeat;
background-position: center top;
width: 100%;
height: 130px;
display: inline-block;
}
.topcenter
{
position: relative;
top: 6em;
text-align: center;
color: #017f02;
width: 99%;
font-weight: bold;
text-decoration: none;
padding-bottom:1em;
}
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
#show-menu, #menu {
display: none;
}
#show-menu:checked ~ #menu {
display: block;
}
}
<div id="header">
<div class="topcenter">
<p>Consultants and Suppliers of <br />
Affordable, Natural, Quality,<br />Sustainable Power Solutions!</p>
</div>
<label for="show-menu" class="show-menu">Show Menu</label>
</div>
<div class="wrapper">
<div id="left">
<ul id="menu">
<li><a href="#" title="Power" >Power Up Belize</a></li>
<li>Services</li>
<li>Experience</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
</div>
You can move <input type="checkbox" ... right before <ul id="menu">. That way, the general sibling selector ~ or next sibling selector + will start to work again.
#show-menu, #menu {
display: none;
}
#show-menu:checked ~ #menu {
display: block;
}
<div id="header">
<label for="show-menu" class="show-menu">Show Menu</label>
</div>
<div class="wrapper">
<input type="checkbox" id="show-menu" role="button"/>
<ul id="menu">
<li>Power Up Belize</li>
<li>Services</li>
<li>Experience</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
Edit: JsFiddle example with media query implemented.
I may seem really silly or outright wrong in the way I code. However, when I create a drop down menu in CSS the new li elements get pushed to the other side of the page and not in the container box. How would I fix this?
Here is the code:
<nav>
<div class="wrapper">
<div class="brand">
<img class="UKLogo" src="images/logo.png" alt="">
</div> <!-- brand -->
<div class="navigation">
<ul class="nav-ul">
<li> HOME </li>
<li> ABOUT </li>
<a href="#">
<li class="course-li">
COURSES
<ul class="drop-down">
<li class="list-item"> Driver CPC </li>
<li> First Aid </li>
<li> Other </li>
</ul>
</li>
<li> CONTACT </li>
<!-- <li> TESTOMONIALS </li> -->
<!-- <li> FAQs </li> -->
</ul>
</div> <!-- Navigation -->
</div> <!-- Wrapper -->
</nav>
nav {
margin: 0px;
padding: 0px;
height: 75px;
background-color: #FFF;
}
.brand {
margin: auto;
width: 960px;
}
.company-name {
padding: 0px;
margin: 0px;
}
.UKLogo {
padding: 0px;
margin: 0px;
position: relative;
top: 11px;
}
.navigation ul li {
display: inline-block;
margin: 10px;
position: relative;
left: 380px;
top: -46px;
}
.navigation ul a {
color: black;
margin-left: 40px;
text-decoration: none;
font-family: Lato;
font-weight: 300;
}
.navigation ul a:hover {
color: #169ec5;
font-weight: 300;
}
.course-li:hover .drop-down {
left: 0px;
}
.drop-down {
position: absolute;
left: -5px;
z-index: 1;
background-color: white;
left: -9999px;
}
Thank you ever so much for looking and helping. Always open to criticism whether its the way I code or anything else.
Here is a JSFiddle https://jsfiddle.net/vj41qLts/
Many Thanks!
You need to declare a position in the parent, for the child to reside in. An element with position: absolute; will position itself to the first parent with position: relative;. If there is no parent with position: relative;, it will use the browser window instead.
See fix example here: https://jsfiddle.net/vj41qLts/1/
I think there are two thing you need to change:
ul li will select everything li in the navigation even the dropdown, ul>li will only select the immediate child, instead of running down the nested elements.
you need to add position:relative; in your dropdown's parent.
One of the first issues I see is the fact that your markup for your main links isn't setup correctly. Following a structure more link the below should give make it work the way you want it to:
<nav>
<ul>
<li><a href="#">Home<a></li>
<li><a href="#">About<a></li>
<li>
<a href="#">Courses<a>
<div>
<ul>
<li>A link</li>
<li>A link</li>
</ul>
</div>
</li>
</ul>
</nav>
Then use CSS or JS to control showing and hiding the dropdown of links.
I have got a menu list:
<ul>
<li class="marked">First item</li>
<li>Second much longer than first item</li>
</ul>
I would like to have an image marker on top of item.marked which width will be 100% of text width. The image must stretch so it will be completely visible. Height is constant.
Can this be done with CSS and IE compatibility?
<style type="text/css">
.selected {
background:url("example.png") no-repeat 0 100%;
}
</style>
Solutions for changing background of list item (can be adapted to change an image):
1. CSS-only, persistent, works for current versions of browsers (doesn't work for IE8 and older) - DEMO.
HTML:
<ul>
<li>
<input type="radio" name="s" id="o1" checked>
<label for="o1">First item</label>
</li>
<li>
<input type="radio" name="s" id="o2">
<label for="o2">Second much longer than first item</label>
</li>
</ul>
Relevant CSS:
ul input[type=radio] {
display: none;
}
input[type=radio]:checked + label {
background: lightblue;
}
If you want to have an image (with img tag) above the selected items, then you can adapt it like in this demo.
HTML:
<ul>
<li>
<input type="radio" name="s" id="o1" checked>
<label for="o1">First item
<img src="http://upload.wikimedia.org/wikipedia/commons/5/5b/Supernumerary_rainbow_03_contrast.jpg">
</label>
</li>
<li>
<input type="radio" name="s" id="o2">
<label for="o2">Second much longer than first item
<img src="http://upload.wikimedia.org/wikipedia/commons/5/5b/Supernumerary_rainbow_03_contrast.jpg">
</label>
</li>
</ul>
And add the following CSS:
label img {
top: 0;
width: 100%;
height: 100%;
display: none;
position: absolute;
}
input[type=radio]:checked + label img {
display: block;
}
If you don't want to do it with an img tag, then you can use a background-image on a pseudo-element and set the background-size to 100% 100%, like in this demo. The HTML is the same as in the first demo and you need to also have this in the CSS:
label {
position: relative;
}
input[type=radio]:checked + label:after {
top: 0;
right: 0;
bottom: 0;
left: 0;
position: absolute;
background: url(http://upload.wikimedia.org/wikipedia/commons/5/5b/Supernumerary_rainbow_03_contrast.jpg);
background-size: 100% 100%;
content: '';
}
2. CSS-only, not persistent (list item does not stay selected when you click somewhere else on the page), works for IE8 (and also IE7, but you have to hover off the text to see the change) - DEMO.
HTML:
<ul>
<li>First item</li>
<li>Second much longer than first item</li>
</ul>
Relevant CSS:
a:active, a:focus {
outline: none;
background: lightblue;
}