Is there a way to wrap UL sub-menu to div? - wordpress

Here is my problem is there a way to wrap WordPress UL submenu to div?
WordPress output is this:
<ul>
<li>link 1</li>
<li>link 2</li>
<li>link 3
<ul class="sub-menu">
<li>Sub-link 1</li>
<li>Sub-link 2</li>
<li>Sub-link 3</li>
</ul>
</li>
</ul>
And I need to get this:
<ul>
<li>link 1</li>
<li>link 2</li>
<li>link 3
<div class="wrap">
<ul class="sub-menu">
<li>Sub-link 1</li>
<li>Sub-link 2</li>
<li>Sub-link 3</li>
</ul>
</div>
</li>
</ul>

Using $.fn.wrap:
$('.sub-menu').wrap('<div class="wrap">');

Related

Target first level ul li elements only

This solution isn't going to work since I have no control over adding a class/id to the ul element: Get first level li from ul
Given that the parent ul has no id/class, can css be written to target only the first level li? If not, how could it be done?
This is the html:
<ul>
<li id="acomment-62" class=" comment-item" data-bp-activity-comment-id="62">
<div class="bb-activity-more-options-wrap action"></div>
<ul>
<li id="acomment-65" class=" comment-item" data-bp-activity-comment-id="65">
<div class="bb-activity-more-options-wrap action"></div>
<div class="acomment-meta"></div>
<div class="acomment-content"></div>
</li>
</ul>
</li>
<li id="acomment-63" class=" comment-item" data-bp-activity-comment-id="63">
<div class="bb-activity-more-options-wrap action"></div>
<ul>
<li id="acomment-66" class=" comment-item" data-bp-activity-comment-id="66">
<div class="bb-activity-more-options-wrap action"></div>
<div class="acomment-meta"></div>
<div class="acomment-content"></div>
</li>
</ul>
</li>
<li id="acomment-64" class=" comment-item" data-bp-activity-comment-id="64">
<div class="bb-activity-more-options-wrap action"></div>
<ul>
<li id="acomment-67" class=" comment-item" data-bp-activity-comment-id="67">
<div class="bb-activity-more-options-wrap action"></div>
<div class="acomment-meta"></div>
<div class="acomment-content"></div>
</li>
</ul>
</li>
You can do that with CSS alone. There's a few ways you can do it. Here is one of them and a working codepen so you can mess around with it yourself.
HTML
<ul>
<li>Item 1</li>
<li>Item with list 1
<ul>
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item with list 2
<ul>
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3</li>
<li>Sub List
<ul>
<li>Sub list item 1</li>
<li>Sub list item 2</li>
<li>Sub list item 3</li>
</ul>
</li>
</ul>
</li>
<li>Item 5</li>
CSS
li {
color: red;
}
li li {
color: initial;
}
I'm not sure how supported this is but you could apply the style to all li and then override that style to target any descendant li
EG.
li li {
color: initial;
}
li {
color: red;
}
<ul>
<li>A</li>
<li>B</li>
<li>
C
<ul>
<li>C1</li>
<li>C2</li>
<li>C3</li>
</ul>
</li>
<li>D</li>
<li>E</li>
</ul>

How to add content before ::marker in CSS?

ol::before:marker {
font-size: 120%;
color: #00b7a8;
font-family: "Comic Sans MS", cursive, sans-serif;
content: '√';
}
I want to add "√" before ::marker element and this is my CSS code, but it's no use,could you help me?
Add symbol with class
ol>li.checked::marker {
content: "√ " counter(list-item) ". ";
}
ul>li.checked::before {
content: "√";
margin-left: -30px;
margin-right: 21px;
}
<h3>Ordered</h3>
<ol>
<li class='checked'>item 1</li>
<li>item 2</li>
<li class='checked'>item 3</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
<li>item 7</li>
</ol>
<h3>Unordered</h3>
<ul>
<li class='checked'>item 1</li>
<li>item 2</li>
<li class='checked'>item 3</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
<li>item 7</li>
</ul>
<h3>Nested list</h3>
<ul>
<li class='checked'>
<ol>
<li class='checked'>item 1</li>
<li>item 2</li>
<li class='checked'>item 3</li>
<li>
<ul>
<li class='checked'>item 1</li>
<li>item 2</li>
<li class='checked'>item 3</li>
<li>item 4</li>
</ul>
</li>
<li>item 5</li>
</ol>
</li>
<li>item 2</li>
<li class='checked'>item 3</li>
<li>item 4</li>
</ul>
Add symbol without class
ol>li::marker {
content: "√ " counter(list-item) ". ";
}
ul>li::before {
content: "√";
margin-left: -30px;
margin-right: 21px;
}
<h3>Ordered</h3>
<ol>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
<li>item 7</li>
</ol>
<h3>Unordered</h3>
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
<li>item 7</li>
</ul>
<h3>Nested list</h3>
<ul>
<li>
<ol>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
</li>
<li>item 5</li>
</ol>
</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
If you don't want to use a class then use :nth-* to specify which <li> to style. Just style the ::marker pseudo-element, it gets too crowded with ::before added in. The content: can be manually filled. The normal ::marker for a <li> inside an <ol> is a number and a dot (ex: 1.) so include that and add anything behind it, in front of it, etc..
li:first-of-type::marker {
content: '✔️/*space*/1./*space*/'
}
li:first-of-type::marker {
content: '✔️ 1. ';
}
<ol>
<li>...I</li>
<li>...II</li>
<li>...III</li>
<li>...IV</li>
<li>...V</li>
</ol>

Not Able to Skip Adding CSS Rule to First li Element Using not(first)

Can you please take a look at this demo and let me know why I am not able to not add the css rule to the first item using the not option?
li:not(first) {
color: red;
}
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2-1</li>
<li>Item 2-2</li>
<li>Item 2-3</li>
<li>Item 2-4</li>
</ul>
</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
You probably meant :not(:first-child) (there is no CSS first). There is :first but that's for printing:
The :first #page CSS pseudo-class describes the styling of the first
page when printing a document.
li:not(:first-child){ color:red; }
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2-1</li>
<li>Item 2-2</li>
<li>Item 2-3</li>
<li>Item 2-4</li>
</ul>
</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
You could also do li:not(:first-of-type):
li:not(:first-of-type){ color:red; }
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2-1</li>
<li>Item 2-2</li>
<li>Item 2-3</li>
<li>Item 2-4</li>
</ul>
</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
Or li:not(:nth-child(1)):
li:not(:nth-child(1)){ color:red; }
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2-1</li>
<li>Item 2-2</li>
<li>Item 2-3</li>
<li>Item 2-4</li>
</ul>
</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
Or li:not(:nth-of-type(1)):
li:not(:nth-of-type(1)){ color:red; }
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2-1</li>
<li>Item 2-2</li>
<li>Item 2-3</li>
<li>Item 2-4</li>
</ul>
</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
By the way, if you're wondering why the inner list doesnt have its first element's color changed it because color is an inherited property.
You got the syntax wrong
li:not(:first-child)

Responsive horizontal menu needs overflow hidden but how?

I have a multi-level horizontal menu with unknown number of top level and sub level menus. I want to display this menu as a single line and display as many as the display width will allow. I'm planning to then put all the menu items in a modal dialogue box which the icon is right justified in the menu.
I'm using zurb foundation 5 and I need the menu to cater for different screen widths but I'm 99.9% certain this is a css problem, not foundation. (ie I don't want to code for medium/large/xlarge)
My problem is that I'm having trouble limiting the menu to a single level. It spills/overflows onto subsequent lines but if I specify a height and overflow:hidden, it then breaks the multi-level sub levels of the menu.
I've created a jsfiddle here http://jsfiddle.net/gavtwtd/4tkpoL74/6/
but please note you may have to widen the result pane to see the problem.
Ah, I must accompany jsfiddle with my code, so here's some code:
<div class="sticky">
<nav class="top-bar" data-topbar role="navigation">
<section class="top-bar-section">
<ul class="right">
<li class="divider"></li>
<li>☰</li>
</ul>
<ul class="left" style="width:90%;">
<li class="has-dropdown">Menu 1
<ul class="dropdown">
<li>Sub menu 1</li>
<li>Sub menu 2</li>
<li>Sub menu 3</li>
<li>Sub menu 4</li>
<li>Sub menu 5</li>
</ul>
</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
<li>Menu 5</li>
<li>Menu 6</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 7</li>
<li>Menu 99</li>
</ul>
</section>
</nav>
</div>
<div id="myModal" class="reveal-modal" data-reveal>full menu here <a class="close-reveal-modal">×</a></div>

Removing specific list-style's with multiple ul's [duplicate]

This question already has answers here:
How do I remove a specific bullet point within a ul in CSS?
(2 answers)
Closed 9 years ago.
Let's say as an example, I have two lists.
1st:
<ul>
<li>TEST 1</li>
<li>TEST 2</li>
<li>TEST 3</li>
<li>TEST 4</li>
<li>TEST 5</li>
<li>TEST 6</li>
<li>TEST 7</li>
</ul>
2nd:
<ul>
<li>TEST 1</li>
<li>TEST 2</li>
<li>TEST 3</li>
<li>TEST 4</li>
</ul>
I'd like to remove the list-style (just the icon) from TEST 4 in the first list and the list-style (again, just the icon) from TEST 3 from the second list.
How can I achieve this?
Working jsFiddle here.
Using nth-last-child(2) is one option, as shown here.
li:nth-last-child(2) {
list-style-type: none;
}
<ul>
<li>TEST 1</li>
<li style='list-style-type:none;'>TEST 2</li>
<li>TEST 3</li>
</ul>
<ul>
<li>TEST 1</li>
<li>TEST 2</li>
<li style='list-style-type:none;'>TEST 3</li>
<li>TEST 4</li>
</ul>

Resources