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
Related
I have an unordered list with bullets, but the first li I want without a bullet
I can't figure out how I can just one item without a bullet
<ul>
<li class="no_bullet"> item 0 </li>
<li>item 1 </li>
<li>item 2 </li>
<li>item 3 </li>
</ul>
you can do like this:
using first-child/first-of-type, no need for extra markup (using class)
li:first-child {
list-style: none
}
<ul>
<li>item 0 </li>
<li>item 1 </li>
<li>item 2 </li>
<li>item 3 </li>
</ul>
if you need to remove the bullet from just this specific list, then set a class to ul and do it like this:
.list-no-bullet li:first-child {
list-style: none
}
<ul class="list-no-bullet">
<li>item 0 </li>
<li>item 1 </li>
<li>item 2 </li>
<li>item 3 </li>
</ul>
You can do this with the list-style property
li:first-child {
list-style: none;
}
<ul>
<li>item 0</li>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
You can also replace first-child with nth-child(index), if you want to select a specific item that isn't first or last, e.g.
li:nth-child(3) {
list-style: none;
}
To remove a bullet you would use list-style: none. There are a number of other valid styles you could also use including roman numerals, images and positioning of the bullet: MDN
.no_bullet {
list-style: none;
}
<ul>
<li class="no_bullet"> item 0 </li>
<li>item 1 </li>
<li>item 2 </li>
<li>item 3 </li>
</ul>
This question already has answers here:
css how to only make bold fonts for first <ul> set
(4 answers)
Closed 6 years ago.
How to set bold style with CSS only to the "titles" in this code?
Live example: jsbin.com/xofudovoda/
.container > ol {
font-weight: bold;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
You can set bold on first level <ol>, and reset it on the second level <ol>s.
.container ol {
font-weight: bold;
}
.container ol ol {
font-weight: normal;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
ol li { font-weight: 700 }
ol li ol li {font-weight: 300 }
You can use the following CSS:
.container ol li {
font-weight: bold;
}
.container ol li ol li{
font-weight: normal;
}
li
{
font-weight:normal;
}
.container > ol>li {
font-weight: bold;
}
Add a rule for li. That forces the child <li> elements to use their own style instead of inheriting it from their parent.
Set all the li to font-weight normal, then only apply the bolding to direct children of the original ol.
li {
font-weight: normal;
}
.container > ol:first-child > li {
font-weight: bold;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
Take the Title in span tag and than to that span apply font-weight:bold ol >li > span {font-weight:bold;}
working example : http://jsbin.com/gifaliluve/edit?html,css,output
Here is the code :
<html>
<body>
<head>
<style>
ol >li > span {font-weight:bold;}
</style>
</head>
<div class="container">
<ol type="I">
<li>
<span>Title 1</span>
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
<span>Title 1</span>
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
</body>
</html>
Nth-child will make bold first sub items of each,
ol> li> ol>li:nth-child(odd){
font-weight:bold;
}
Edit 1:
Sorry I understood wrong, this may help.
ol>li {
font-weight:bold;
}
ol > li > ol > li {
font-weight:normal;
}
Hope helps,
Problem is that you've got ordered lists nested within the li's you're trying to target specifically. Try the following:
.container > ol > li {
font-weight: bold;
}
.container > ol > li ol {
font-weight: normal;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
Or, another way:
.container li {
font-weight: bold;
}
.container > ol > li > ol > li {
font-weight: normal;
}
<div class="container">
<ol type="I">
<li>
Title 1
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
<li>
Title 2
<ol>
<li>sub 1</li>
<li>sub 2</li>
</ol>
</li>
</ol>
</div>
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
I am trying to make a menu with submenus. I wrote my HTML and it looks like:
<nav>
<ul>
<li>Home</li>
<li>Page 1
<ul>
<li>dropdown 1</li>
<li>dropdown 2</li>
<li>submenu
<ul>
<li>submenu 1</li>
<li>submenu 2</li>
<li>submenu 3</li>
</ul>
</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
</nav>
I have a stylesheet linked to it, and it looks like:
nav ul {
display:inline-block;
position:relative;
list-style:none;
}
nav ul ul {
display:none;
}
nav ul li:hover > ul {
display:block;
}
For some reason the list is displayed as a block. I tried float:left, and it made no difference.
You have to to put display:inline-block for li elements:
nav li {
display:inline-block;
}
check here the example: http://jsfiddle.net/9y1uzqye/1/
You need to make the individual list items use block display, not the list itself.
I have a menu element like:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3
<ul>
<li>SubItem 1</li>
<li>SubItem 2</li>
<li>SubItem 3</li>
</ul>
</li>
<li>Item 4</li>
</ul>
The element is positioned absolutely. How can I center it without knowing its width (number of parent elements might change).
Regards,
Dave
I think what you're after is possible if you have a parent element to the ul:
<div class="example">
<ul>
<!-- lots of li's -->
</ul>
</div>
Then use the old school text-align trick that was used to center layouts:
.example {
text-align: center;
}
.example ul {
text-align: left;
display: inline-block;
}
See: http://jsfiddle.net/chippper/WK5Z4/