Is it possible to style a nested ul>li into a treeview like this plugin does?
http://www.easyjstree.com/
I was originally using this plugin, but I am in a situation where I can't use JavaScript/jQuery, but has to be done in CSS. Is this even doable for the following HTML?
<div id="navigator">
<ul>
<li class="isFolder isExpanded">
XYZ CORP HR TIME SELF SERVICE
<ul>
<li class="isFolder isExpanded">
Time
<ul>
<li>Create Timecard</li>
<li>Recent Timecards</li>
<li>Templates</li>
<li>Timecard Search</li>
</ul>
</li>
</ul>
</li>
<li class="isFolder isExpanded">
XYZ CORP EXP ENTRY
<ul>
<li>Expense Home</li>
</ul>
</li>
<li class="isFolder isExpanded">
XYZ HR EMP SELF SERVICE
<ul>
<li>Accommodation Request</li>
<li>Additional Personal Information</li>
<li>All Actions Awaiting Your Attention</li>
<li>Appraisals</li>
</ul>
</li>
</ul>
</div>
Any help or guide would be much much appreciated!!
Not too hard to do without animations, thanks to the + selector. Unfortunately needs to use ids on the checkboxes for the labels to work. Parent selector when.
If you do want to animate it later, you'll wanna hide via max-height:0; rather than display:none;, and animate the max-height. Downside, that'll impose a max-height. If you wanna fake that animation, stick with display:none; and animate a vertical padding instead, letting the user's eye do the work. Y'know. Standard animation tricks.
ul.asTree {
list-style-type:none;
padding:0;
margin:0;
text-indent:1em;
}
ul.asTree ul{
display:none;
list-style-type:none;
}
ul.asTree li{/*lets us position the label's ::before*/
position:relative;
}
ul.asTree label{
cursor:pointer;
}
ul.asTree label:hover{
box-shadow: 0 0 5px 0 rgba(128,155,200,0.5) inset;
}
ul.asTree label::before{
content:"\25B7";
position:absolute;
left:-1em;
top:-2px;
}
ul.asTree input:checked + label::before{
content:"\25E2";
}
ul.asTree input:checked + label + ul{
display:block;
}
<ul class="asTree">
<li>item 1</li>
<li>item 2</li>
<li>
<input type="checkbox" hidden id="treeExp_3" />
<label for="treeExp_3">item 3</label>
<ul>
<li>item 3.1</li>
<li>
<input type="checkbox" hidden id="treeExp_3_2" />
<label for="treeExp_3_2">item 3.2</label>
<ul>
<li>item 3.2.1</li>
<li>item 3.2.2</li>
</ul>
</li>
<li>item 3.3</li>
</ul>
</li>
<li>
<input type="checkbox" hidden id="treeExp_4" />
<label for="treeExp_4">item 4</label>
<ul>
<li>item 4.1</li>
<li>item 4.2</li>
</ul>
</li>
</ul>
Alternately available on Dabblet
Related
Really simple guys: making a collapsible list in html and css and trying to move the checkbox that controls the drop down to the FRONT of the text, as well as get rid of the dot to list the items. Right now the checkbox is placed at the end of the text. I tried to simply switch the order of the html but that screws up the drop down action.
Here is the fiddle: https://jsfiddle.net/gyetxsLu/
HTML:
<div class="CHECKBOXMENU">
<ul class="collapsibleList">
<li>
<label for="mylist-node1">Click to open list 1</label>
<input type="checkbox" id="mylist-node1" />
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>
<label for="mylist-node2">Click to open list 2 with subfolders</label>
<input type="checkbox" id="mylist-node2" />
<ul>
<li>
<label for="mylist-node3">Click to expand</label>
<input type="checkbox" id="mylist-node3" />
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
</ul>
</div>
CSS:
.collapsibleList li > input + * {
display: none;
}
.collapsibleList li > input:checked + * {
display: block;
}
.collapsibleList label {
cursor: pointer;
}
No need to restructure the HTML. float: left the required checkboxes and remove the bullets using list-style-type: none
ul.collapsibleList,
ul.collapsibleList ul {
list-style-type: none;
}
#mylist-node1,
#mylist-node2,
#mylist-node3 {
float: left;
margin-right: 5px;
}
JSfiddle
I try to make simple css-dropdownmenu.
My goal is to create a transition in which a dot transforms into a square if you hover over the main menu elements. With dot i mean a very small circle which cant be seen until hovered and then transforms into a square.
My menu is already able to transform the square into a circle with differant color but I cant think of a way to do it vice versa, especially because the circle first has to be 'hidden' until hovered.
Here is what i have so far:http://jsfiddle.net/eaqw4m38/3/
HTML:
Test
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<ul id="nav">
<li>Home</li>
<li>Menu 1
<span id="s1"></span>
<ul class="subs">
<li>Header a
<ul>
<li>Submenu I</li>
<li>Submenu II</li>
<li>Submenu III</li>
</ul>
</li>
<li>Header b
<ul>
<li>Submenu I</li>
<li>Submenu II</li>
<li>Submenu III</li>
</ul>
</li>
</ul>
</li>
<li>Menu 2
<span id="s2"></span>
<ul class="subs">
<li>Header c
<ul>
<li>Submenu I</li>
<li>Submenu II</li>
<li>Submenu III</li>
</ul>
</li>
<li>Header d
<ul>
<li>Submenu I</li>
<li>Submenu II</li>
<li>Submenu III</li>
</ul>
</li>
</ul>
</li>
<li>Menu 3</li>
<li>Menu 4</li>
<li>Menu 5</li>
<li>Google</li>
</ul>
</div>
</body>
I couldnt find anything via the search that fit my question.
Thanks in advance for your answers :)
Paul
EDIT: I now know how to add such a circle and make it transparent but how do i add it to the transition?
The problem is that i have to objects: 1. the square of the menuelement
2. the circle
How do I anymate the circle when the square is hovered and moreover i have to keep the font on top of the circle
Jsfiddle: http://jsfiddle.net/u2ykjdbo/
Just apply the border radius to elements at the start (when they are not hovered), and then apply the background and new color when the element is hovered while changing the border-radius to 0. As the color changes, you will see the transition from circle to square.
Code (unchanged selectors omitted):
#nav > li > a {
color: #333333;
display: block;
font-size: 1.3em;
line-height: 49px;
padding: 0 15px;
text-transform: uppercase;
border-radius: 50%;
}
#nav > li:hover > a, #nav > a:hover {
background-color: #EC7970;
color: #000000;
border-radius: 0;
}
I currently have a side menu. I'd like it if the user hovers over the Manage Contracts button the sub menu then appears. I've created two ul's - the primary menu and a sub menu ul. The reason being because I don't want the sub menu inheriting the styles from the primary menu if that makes sense? However at the moment I can't get the the menu to appear when the mouse is over the Manage Contract button. Any ideas?
the html:
<div id="navbar-side">
<div id="profile-image">
</div>
<div id="menu-search">
<input type="text" name="search" id="search" placeholder="Search..." />
</div>
<ul id="side-menu">
<li>Dashboard</li>
<li>Manage Contracts</li>
<li>Manage Duplicates</li>
<li>PPM Manager</li>
<li>Service User Search</li>
<li>My Subscriptions</li>
<li>Help Centre</li>
</ul>
<ul id="contracts-menu">
<li>General</li>
<li>Settings</li>
<li>Communication</li>
<li>Contract Details</li>
<li>Retail Setup</li>
</ul>
</div>
the css:
#side-menu
{
width:100%;
position:relative;
}
#side-menu li
{
display:block;
border-bottom:solid 1px black;
}
#side-menu a
{
display:block;
border-top:solid 1px white;
padding:18px 0;
}
#side-menu a:hover
{
background-color:Silver;
}
#contracts-menu
{
display:none;
width:200px;
height:300px;
background-color:Aqua;
margin-left:228px;
position:absolute;
top:87px;
}
#contracts-menu li
{
display:block;
}
#contracts-menu a
{
display:block;
}
a#contracts:hover + #navbar-side ul#contracts-menu
{
display:block;
}
That's because a#contracts and div#navbar-side are not siblings!
You can't use + and/or ~ selectors on non-sibling elements.
On the other hand, there's no parent selector in CSS (yet).
You could use JavaScript to achieve this or change your markup structure, as follows:
<li>Manage Contracts
<ul id="contracts-menu">
<li>General</li>
<li>Settings</li>
<li>Communication</li>
<li>Contract Details</li>
<li>Retail Setup</li>
</ul>
</li>
CSS:
a#contracts:hover + ul#contracts-menu {
display:block;
}
JSBin Demo.
Update
But in this case, There's no need to set id attriute on each link/item.
You could nest the sub-menus in each list item and display them as follows:
#side-menu li:hover > ul { /* Select the ul children inside each list-item */
display:block;
}
JSBin Demo #2
If you don't want to use javascript, you could put the ul#contracts-menu inside the list-item that contains the #contracts anchor:
<div id="navbar-side">
<div id="profile-image">
</div>
<div id="menu-search">
<input type="text" name="search" id="search" placeholder="Search..." />
</div>
<ul id="side-menu">
<li>Dashboard</li>
<li id="contracts">
Manage Contracts
<ul id="contracts-menu">
<li>General</li>
<li>Settings</li>
<li>Communication</li>
<li>Contract Details</li>
<li>Retail Setup</li>
</ul>
</li>
<li>Manage Duplicates</li>
<li>PPM Manager</li>
<li>Service User Search</li>
<li>My Subscriptions</li>
<li>Help Centre</li>
</ul>
</div>
Add the id to the list item (instead of the anchor) and then add:
#side-menu li.contracts:hover #contracts-menu { display:block; }
See: http://jsfiddle.net/FmR3f/
List:
<ul>
<li>
Item 1
<ul>
<li>
Item 1-1
<ul>
<li>Item 1-1-1</li>
<li>
Item 1-1-2
<ul>
<li><a href="#">Item 1-1-2-1</li>
</ul>
</li>
</ul>
</li>
<li>Item 1-2</li>
<li>Item 1-2</li>
</ul>
</li>
<li>Item 2</li>
</ul>
Here's some relevant CSS
#nav ul ul {
display: none;
}
#nav ul li:hover > ul {
display: block;
}
The first one will hide every drop down item. The second will match any ul that is a children of the parent #nav ul li:hover, if so display:block and the drop down is visible.
Now because when hovering a item, the items within will simply be listed below, this is not what I am looking to achieve. I want to move the Item 1-1-1 and Item 1-1-2 to be on the right of Item 1-1, the Item 1-1-1 needs to be on the right, Item 1-1-2 will be below it (acting as a drop-down list). I am not sure how I select that element.
Example: http://line25.com/wp-content/uploads/2012/css-menu/demo/index.html
Here's what I got so far:
http://jsfiddle.net/Gq8C2/
I tried with first-child, such as:
#nav ul li:hover > ul li:first-child {
display: block;
}
I also tried using position absolute and relative, It almost gave me the result I wanted, but I wasn't able to grab the first item...
There must be a better way of doing this...
How do I select it? And how do I make a similar behavior to that I've been describing above?
Why don't you just use the css/html of the page you linked to instead of trying to reinvent it?
HTML:
<nav>
<ul>
<li>Home</li>
<li>Tutorials
<ul>
<li>Photoshop</li>
<li>Illustrator</li>
<li>Web Design
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
</ul>
</li>
<li>Articles
<ul>
<li>Web Design</li>
<li>User Experience</li>
</ul>
</li>
<li>Inspiration</li>
</ul>
</nav>
CSS
Review this Fiddle http://jsfiddle.net/Gq8C2/10/
I use position:absolute for the sub-sub menu :
#nav ul li ul li ul {
position:absolute;
top:0;
left:100%;
}
In order to upgrade your code you can assign a class for each level of the menu like
<ul class="Third_level">
How can I use CSS selectors to apply a style only to the inner item in a list. Example:
HTML fragment:
<ul class="list">
<li>Item 1</li>
<li>
<ul class="list">
<li>Subitem 1</li>
<li>Subitem 2</li>
<li>
<ul class="list">
<li>Subitem 1.1</li>
</ul>
</li>
</ul>
</li>
</ul>
CSS fragment:
ul.list {
border: 1px solid red;
}
What I need is to have a border only arround the "Subitem 1.1" string. The list is generated and it's not possible to add an extra class or id and as the list has no fixed depth it's not an option to specify an "ul > ul > ul.list" or similar selector.
I believe you cannot do this with only CSS if it is not possible to use an Id or unique class. In this case I think jQuery is the way to go:
$("li").children().eq( $("li").children().length - 1 ).
css('border', '1px solid red');
The idea is to use eq() to pinpoint the deepest child.
Hope this helps
it's not an option to specify an "ul > ul > ul.list" or similar selector.
Why not? This, or adding a class, is the solution.
You've basically specified a requirement to identify an element, then rejected all the approaches that you could use to do so.
<html>
<head>
<style type="text/css">
li.list {
border: 1px solid red;
}
</style>
</head>
<body>
<ul >
<li>Item 1</li>
<li>
<ul >
<li>Subitem 1</li>
<li>Subitem 2</li>
<li>
<ul >
<li class="list">Subitem 1.1</li>
</ul>
</li>
</ul>
</li>
</ul>
</body>
</html>
I Hope This ma help you..
JoseSantos is correct in that it can't be done with pure CSS. Here's how I'd do it in jQuery:
$("ul").each(function(){
if ($(this).find("ul").length == 0)
$(this).addClass("list");
});