I need to target only specific li in an ul but I can't add a Class to solve my issue. I guess there's a way using Javascript, but it would be my last resort.
To explain:
<div>
<ul>
<li>Start</li>
<li>Previous</li>
<li>>1</li> <!--need to target this-->
<li>2</li> <!--need to target this-->
<li>3</li> <!--need to target this-->
<li--in future a new li will be generated--/li>
<li>Next</li>
<li>End</li>
</ul>
This example is only the general idea as my jsFiddle contains more info such as span and classes.
http://jsfiddle.net/8aW77/
note: I looked for special and advanced selectors but I couldn't find one that fits my case.
Preferably you'd assign classes to the elements you do have control over, such as Start, Previous, Next and End. When you've done that, it's easy to style the other elements.
<ul>
<li class="static">Start</li>
<li class="static">Previous</li>
<li>>1</li> <!--need to target this-->
<li>2</li> <!--need to target this-->
<li>3</li> <!--need to target this-->
<li--in future a new li will be generated--/li>
<li class="static">Next</li>
<li class="static">End</li>
</ul>
Thus the CSS would look like:
UL LI {
color: green;
}
UL LI.static {
color: red;
}
This would be the most straight-forward solution. However, if you can't add those classes to the "static" LI-tags but you know that the DOM-structure will look the same then use CSS such as this:
UL LI {
color: green;
}
UL LI:first-child,
UL LI:nth-child(2),
UL LI:nth-last-child(2),
UL LI:last-child {
color: red;
}
Related
I am hoping to have a navigation bar run across the entire screen, with a purple background and a to have a the menu sit in the middle of the bar. Right now I cant get the background color to work.
My Css:
div#main-navigation {
background-color: #AC56B8;
width: 100%;
height: 100px;
}
My Html:
<div class="main-navigation">
<ul id="menu">
<li>HOUSE</li>
<li>BABY</li>
<li>MORE</li>
<li>ABOUT</li>
</ul>
</div>
You are using wrong css selector # is for ids, to select element by class you have to use ., so the first line of your CSS must be: div.main-navigation {
Look for this:
Replace div#main-navigation for div.main-navigation
div.main-navigation {
background-color: #AC56B8;
width: 100%;
height: 100px;
}
<div class="main-navigation">
<ul id="menu">
<li>HOUSE</li>
<li>BABY</li>
<li>MORE</li>
<li>ABOUT</li>
</ul>
</div>
Write . instead of #
# is for id, . is for class.
How can I make this have the buttons in the same column as each other?
ul
li
p button
p button
using flexbox
if the p has different width the buttons are shifted.
Flexbox has no grid notion.
Instead, you can use CSS tables
ul {
display: table;
}
li {
display: table-row;
}
p, button {
display: table-cell;
}
<ul>
<li>
<p>Short</p>
<button>Foo</button>
</li>
<li>
<p>Long long long text</p>
<button>Bar</button>
</li>
</ul>
I have a menu within a ul li and I'd like to change the background image for only one of the menu items.
In the css below the current background image is menu-ul.jpg and I need the additional background image for the "Capsules" menu item to be menu-ul2.jpg
Here's my current menu html:
<ul class="menu">
<li><strong>home</strong><span></span></li>
<li><strong>Products</strong><span></span>
<ul>
<li>Dew Drops</li>
<li>Capsules</li>
<li>Salvation Balm</li>
</ul>
Here's the piece of css that deals with the background image for the menu items:
.menu ul {
position: absolute;
padding: -3px 10px;
top: -999em;
width: 107px;
background: url(../images/menu-ul.jpg) left top repeat;
}
Any help would be greatly appreciated...thanks.
Meg
You can reach that effect by adding a class to the list item you want to change.
Add this to your CSS
.menu ul li.capsule {
background: url(../images/menu-ul2.jpg)
}
And this in your html
<li class="capsule">Capsules</li>
Off course there are many other ways...
Is it possible to not have the top bar in Foundation to collapse to Menu and the three lines? We don't really need this feature but not sure how to disable the collapse.
Will this require modifying the foundation.topbar.js?
If you're using Foundation via sass, there's an even better way to go about it.
Just open up the _settings.scss file and find this line:
// $topbar-breakpoint: emCalc(940px); // Change to 9999px for always mobile layout
Uncomment it and change the value to 0, or whatever breaking point you would like to use.
Things have changed in foundation 5.1.1 and this worked for me in the css: changed
#media only screen and (min-width: 40.063em) {
.top-bar {
to
#media only screen and (min-width: 4.063em) {
.top-bar {
Yes, it's possible to not show the default nav menu for small-screens with the menu toggle icon without modifying any js files. Foundation 4 uses a series of visibility classes to show and hide elements on the screen along with media queries.
As an example here's the main navigation for Zurb's demo site linked above:
<nav class="top-bar hide-for-small" style="">
<ul class="title-area">
<!-- Title Area -->
<li class="name">
<h1>Foundation</h1>
</li>
<!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
<li class="toggle-topbar menu-icon"><span>Menu</span></li>
</ul>
<section class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="divider"></li>
<li class="">Features</li>
<li class="divider"></li>
<li class="">Add-ons</li>
<li class="divider"></li>
<li class="">Case Studies</li>
<li class="divider"></li>
<li class="">Docs</li>
<li class="divider"></li>
<li class="">Training</li>
<li class="divider"></li>
<li class="has-form">
Getting Started
</li>
</ul>
</section></nav>
As you can see it's simple to remove the .menu-icon class or even the li; if you look at line 2816 of docs.css you can see that a minimum screen breakpoint (58.75em) is set for the .top-bar class:
#media only screen and (min-width: 58.75em) {
.top-bar {
background: #111111;
*zoom: 1;
overflow: visible; }
.top-bar:before, .top-bar:after {
content: " ";
display: table; }
.top-bar:after {
clear: both; }
.top-bar .toggle-topbar {
display: none; }
.top-bar .title-area {
float: left; }
.top-bar .name h1 a {
width: auto; }
...
Since F4 is built with a mobile first design approach by default the menu is set for small screens. At a minimum width of 58.75 em, the breakpoint is set to modify the default .top-bar view for larger screens so that the menu ul is displayed inline and the child li are floated left.
You can override the .top-bar so that this is the default view by overriding the corresponding lines of css/scss or even the global variables.
If you're working directly with the Foundation CSS, you can override the mobile mode of the .top-bar menu by changing the breakpoints in the following lines of CSS to 0em:
.top-bar-js-breakpoint {
width: 58.75em !important;
visibility: hidden; }
.js-generated {
display: block; }
#media only screen and (min-width: 58.75em) {
----- numerous lines below -------
However, if you're working with a child theme in WordPress or another CMS, you have to copy all of the .top-bar related selectors below the actual media query and paste them into your child CSS, then change the breakpoints to 0. Works like a charm.
I need to display a MenuBar on the Liferay Portal Page (A menuBar which will be common to all portlets in that page)
For this, I have created a custom Theme, and modified the navigation.vm file under the templates folder.
I have added this below MenuBar code inside the navigation.vm file and deployed it to the server
<html>
<head>
<title>Menu Bar Using CSS</title>
<style>
.menu ul
{
list-style: none;
}
.menu ul li
{
display: inline;
}
.menu ul li a
{
/*Increase Clickable Area*/
padding: 8px;
padding-left: 15px;
padding-right: 15px;
/*Remove the Underline for the Link*/
text-decoration: none;
color: #000;
background: #ccc;
}
/*On Mouse Over the Link*/
.menu ul li a:hover
{
color: #fff;
background: #000;
}
</style>
</head>
<body>
<div class="menu">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
</body>
</html>
I have put all these code under the navigation.vm file under my Applied Custom Theme, but it didn't worked (I mean the Menu Bar is not shown on the Portal page)
Please let me know if I am doing anything wrong.
navigation.vm does not contain <html>,<head> and <body> tags, these go inside the portal_normal.vm or if the page is a pop-up then portal_pop_up.vm. This file (navigation.vm) just helps in displaying the pages and is included inside the portal_normal.vm file.
So try moving your code inside portal_normal.vm for the menu-bar.
Hope this helps.