Consider this HTML:
<li role="presentation">Home </li>
<li role="presentation">About Us</li>
<li role="presentation">Contact Us</li>
<li role="presentation">Gallery</li>
I would like to know how I can add borders around each button in a light blue or blue color.
It's pretty easy, just add the following rule:
a {
border: 1px blue solid;
}
And here is the snippet:
a {
border: 1px blue solid;
}
<ul>
<li role="presentation">Home </li>
<li role="presentation">About Us</li>
<li role="presentation">Contact Us</li>
<li role="presentation">Gallery</li>
</ul>
Reference this guide here https://www.w3schools.com/css/css_border.asp
add a class to all of the buttons and add border attributes to it.
In your html file
<a href="index.php" class="border">
In your style file (or styles in header)
.border{border: 2px solid #0000FF;}
You could also do this inline but head over to w3schools to learn about that
You can just add a border to the a element and with padding make it farther away from the words. Displaying the li elements as inline block will make them stay on the same line. Since I added the border on the a element, that means that the whole area inside the border is clickable.
a{
border:2px solid lightblue;
padding:10px 20px;
text-decoration:none;
}
li{
display:inline-block;
}
<li role="presentation">Home </li>
<li role="presentation">About Us</li>
<li role="presentation">Contact Us</li>
<li role="presentation">Gallery</li>
Rob,
You should be able to add the following code in your CSS.
ul li {
border-bottom:1px solid blue;
}
li {
display:inline-block;
}
<ul>
<li>Border</li>
<li>Bottom</li>
<li>Blue</li>
</ul>
You can change the border attributes. ie
ul li {
border-bottom: 5px solid green;
}
li {
display:inline-block;
}
<ul>
<li>Border</li>
<li>Bottom</li>
<li>Green</li>
</ul>
etc.
You can make other styling changes but your question the "border-bottom" attribute might be what you're looking for.
Hope this helps.
I've made a fiddle that might help: https://jsfiddle.net/9mmf3omc/1/
html
<li role="presentation">Home </li>
<li role="presentation">About Us</li>
<li role="presentation">Contact Us</li>
<li role="presentation">Gallery</li>
css
li {
display: inline-block; # necessary to format links/buttons correctly
margin: 10px 0;
}
li a {
border: 1px solid blue; # adds blue border around link/button
padding: 10px; # gives some room between text and border
text-decoration: none; # removes underlined link if you prefer
}
As for border colors, check out one of many color-picker tools like THIS and make the border any shade of blue you want. Just change:
border: 1px solid blue;
to say,
border: 1px solid #88EBFB;
You can do it by a few ways.
1st does the ul or ol the li belong too have a class name like
<ul class = "name">
<li role="presentation">Home </li>
<li role="presentation">About Us</li>
<li role="presentation">Contact Us</li>
<li role="presentation">Gallery</li>
</ul>
Related
I was trying to make dropdown menu using only css, however it doesn't work in my case.
It's kinda working when I don't put position:absolute at .dropdown_content in CSS, but even when I do that, dropdown doesn't work.
HTML:
<nav>
<ul>
<div class="dropdown">
<li>Game order</li>
<div class="dropdown_content">
Half-life
Half-life 2
Half-life EP1
</div>
</div>
<li>Portal series</li>
<li>Half Life Alyx</li>
</ul>
</nav>
CSS:
.dropdown {
position:relative;
display:inline-block;
}
.dropdown_content {
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
min-width: 160px;
display:none;
}
.dropdown_content a {
color:white;
text-decoration: none;
display:block;
padding: 12px 16px;
}
}
.dropdown:hover .dropdown_content {
display: block;
}
To keep things simple, I have reduced your code to a bare minimum.
I'm not sure exactly how you want it to look, but here's a possible solution.
When making css only menu's I try to stick to a nested list of <ul> and <li>'s.
This makes it clearer to read, and keeps the semantics in order.
Ther is no need for container divs within. (like the <div class="dropdown_content"> in your code)
The HTML is a nested list. Initially we hide the nested ul, and only show it when it's parent is hovered over. By using .dropDown li:hover>ul you only target the ul that is DIRECTLY under the hovered li. That way you dan nest as deep as you want.
.dropDown ul {
display: none;
position: absolute;
background: white;
border: 1px solid red;
}
.dropDown li:hover>ul{
display: block;
}
<ul class="dropDown">
<li>Game order
<ul>
<li>Half-life</li>
<li>Half-life 2</li>
<li>Half-life EP1</li>
</ul>
</li>
<li>Portal series</li>
<li>Half Life Alyx</li>
<li>deeper nesting
<ul>
<li>level 1</li>
<li>more here
<ul>
<li>level 2</li>
<li>more here
<ul>
<li>level 3</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
So I have the following code:
<ul class="nav-items">
<li class="menu-active nav-stuff"><a href='1'>One</a></li>
<li class="menu-active nav-stuff"><a href='2'>Two</a></li>
<ul>
<li><a href='A'>A</a></li>
<li><a href='B'>B</a></li>
<li><a href='C'>C</a></li>
</ul>
</li>
<li class="menu-active nav-stuff"><a href='3'>Three</a></li>
</ul>
I'm trying to apply a border specifically to One Two and Three but NOT A B and C. Right now I have:
.nav-items.menu-active a {
color: green;
padding-bottom: 13px;
border-bottom: 5px solid orange;
}
This works great for hitting One Two and Three but completely screws up as it also applies to A B and C. I've tried to do a:first-child but that's not working. Is there a way to hit only the upper li a?
EDIT: Fixed the nested unordered list and put in the right code for the CSS.
Use the Direct Descendant/Child selector >
The child combinator (>) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the children of elements matched by the first.
MDN
.nav-items > li.active > a
a {
text-decoration: none;
}
.nav-items>li.active>a {
color: green;
border-bottom: 5px solid orange;
}
<ul class="nav-items">
<li class="menu active nav-stuff"><a href='1'>One</a></li>
<li class="menu active nav-stuff"><a href='2'>Two</a>
<ul>
<li><a href='A'>A</a></li>
<li><a href='B'>B</a></li>
<li><a href='C'>C</a></li>
</ul>
</li>
<li class="menu active nav-stuff"><a href='3'>Three</a></li>
</ul>
Also note that padding-bottom: 5px solid orange; is invalid CSS.
I have also corrected the HTML in that you had closed the li holding the submenu too soon.
.nav-items.menu-active a {
color: green;
padding-bottom: 5px solid orange;
}
.nav-items ul li a {
text-decoration: none;
}
<ul class="nav-items">
<li class="menu active nav-stuff"><a href='1'>One</a></li>
<li class="menu active nav-stuff"><a href='2'>Two</a></li>
<ul>
<li><a href='A'>A</a></li>
<li><a href='B'>B</a></li>
<li><a href='C'>C</a></li>
</ul>
<li class="menu active nav-stuff"><a href='3'>Three</a></li>
</ul>
I have the following CSS block:
nav li {
border-bottom: 1px solid Gray;
}
How could I make it so that it applies to nav and li but not the class called export? As it currently is, the styling is being applied to the export class because it is in a nav and an li tag.
Here is the corresponding HTML:
</head>
<body>
<nav class="main menu">
<ul class = button-container>
<li>
<i class="..." style="font-size:6em;" title="..."></i>
</li>
<li>
<i class="..." style="font-size:6em;" title="..."></i>
</li>
</ul>
<ul class="export button-container">
<li>
<i class="fa fa-floppy-o" style="font-size:6em;" title="Export"></i>
</li>
</ul>
</nav>
You can do nav li:not( .export ) {}.
More on :not pseudo class.
nav li:not( .export ) {
color: red;
}
<nav>
<ul>
<li>One</li>
<li class="export">Two</li>
<li>Three</li>
</ul>
<nav>
Edit
- Example using markup OP added to question.
Notice I simplified the CSS selector using the lowest amount of specificity to change the li. Unless .export appears on other elements or you have some other rule specifically targeting the li, you won't need the extra specificity that nav ul:not( .export ) li would provide.
ul:not( .export ) {
color: red;
}
<nav>
<ul class="other">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<ul class="export">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
nav li:not(.export) {
border-bottom: 1px solid Gray;
}
You can use :not css selector:
If .export class is applied to li:
nav li:not(.export) {
border-bottom: 1px solid Gray;
}
And in case if .export class is applied to ul:
nav ul:not(.export) li {
border-bottom: 1px solid Gray;
}
try this
nav li:not(.export) {
border-bottom: 1px solid Gray;
}
In the code below, I'm adding a down array (via generated content) to the top level elements that have child menus. And I'm adding a right arrow to the submenu elements that have child menus.
However, I need some help with my css, because it applies the arrows to all child elements if the parent has children. I only need it to be applied to those elements that have children.
<ul id="menu-site-menu">
<li class="hasChild top">About Us
<ul class="sub-menu">
<li>Our Charity Partners</li>
<li>Privacy Policy</li>
</ul>
</li>
<li class="hasChild top">Buy Apparel
<ul class="sub-menu">
<li class="hasChild sub">Benevolent Elephant
<ul class="sub-menu">
<li>Benevolent Elephant Short Sleeve</li>
<li>Benevolent Elephant Long Sleeve</li>
</ul>
</li>
<li class="hasChild sub">Eagle-Spirit
<ul class="sub-menu">
<li>Eagle-Spirit Short Sleeve</li>
<li>Eagle-Spirit Long Sleeve T-Shirts</li>
</ul>
</li>
</ul>
</li>
<li>Customer Service</li>
<li>Contact Us</li>
</ul>
The css is below
.hasChild.top a:after {
content: ' ';
height: 0;
position: absolute;
bottom:-5px;
right:-5px;
width:0;
border: 5px solid transparent;
border-top-color: #ccc;
}
.hasChild.sub a:after {
content: ' ';
height: 0;
position: absolute;
bottom:0;
right:-5px;
width:0;
border: 5px solid transparent;
border-left-color: #ccc;
}
Add the child selector >:
.hasChild.top > a:after {
}
.hasChild.sub > a:after {
}
I want to create a CSS/JS accordion menu, with HTML like so:
<ul>
<li>First Link
<ul>
<li>Child One</li>
<li>Child Two</li>
</ul>
</li>
<li>Second Link</li>
<li>Third Link</li>
</ul>
The nav structure can get N levels deep, and each child menu will be indented from its parent. I want there to be a border that spans 100% of the width between all nav elements including the n-th level child elements. Like this:
alt text http://files.getdropbox.com/u/64548/nested-nav.png
I cannot for the life of me figure out an easy way to do this without using JavaScript, but it feels like something that should be possible. (I will be using JS to expand/collapse the nav tree).
You need to have the border and padding on the <a> which also must be set to display:block. This gives an added bonus as it makes the whole <li> region clickable.
There is no extra markup needed in the ul. Just define the max number of sublists in your css.
Example here
a {text-decoration:none;}
ul {width:240px;padding:0;list-style:none;border-top:1px solid #000;}
ul ul, ul ul ul {border-top:0;}
li a {border-bottom:1px solid #000;display:block;padding-left:0px;}
li li a {padding-left:40px;}
li li li a {padding-left:80px;}
<ul>
<li>First Link
<ul>
<li>Child One</li>
<li>Child Two
<ul>
<li>Child Two One</li>
<li>Child Two Two</li>
</ul>
</li>
</ul>
</li>
<li>Second Link</li>
<li>Third Link</li>
</ul>
The tiling background image for the divider rows does not contradict resizing (at least should not, with sane CSS renderers).
This is pretty sloppy for my tastes, but basically it requires text-indent instead of padding or margin to achieve the nesting. But then to use a sprite image as the bullet for the <a>, you have to end up taking the current text-indent for the level and bump the sprite image over that many px, minus the sprite image width.
I've changed it to use padding-left on the anchor instead, but then this requires overflow: hidden on the parent div to hide the extra border that gets pushed to the right with each nesting.
And of course, visualize any of the stuff like .two_deep, .expanded, etc. as being done with jQuery, and NOT hardcoded into the CSS. It should be fairly simple to get a ul's depth in the menu.
<html>
<head>
<style>
body {font: normal 11px Arial;}
a:link, a:visited {color: #888; text-decoration: none;}
a:hover, a:active {color: #000; text-decoration: none;}
div {width: 250px; border-top: 1px solid #888; overflow: hidden;}
ul {
width: 100%;
margin: 0; padding: 0;
list-style-type: none;
}
li {
padding: 5px 0;
border-bottom: 1px solid #888;
}
li a {
display: block;
}
.two_deep li a {
padding-left: 25px;
}
.three_deep li a {
padding-left: 50px;
}
.four_deep li a {
padding-left: 75px;
}
.expanded {
display: block;
width: 100%;
border-bottom: 1px solid #888;
margin: -5px 0 5px;
padding: 5px 0;
}
li > ul {margin: -5px 0 -6px;}
</style>
</head>
<body>
<div>
<ul>
<li><a class="expanded" href="#">First Link</a>
<ul class="two_deep">
<li>Child One</li>
<li>
<a class="expanded" href="#">Child Two</a>
<ul class="three_deep">
<li>
<a class="expanded" href="#">Child One of Child Two</a>
<ul class="four_deep">
<li>Child One of . . .</li>
<li>Child Two of . . .</li>
</ul>
</li>
<li>Child Two of Child Two</li>
</ul>
</li>
</ul>
</li>
<li>Second Link</li>
<li>Third Link</li>
</ul>
</div>
</body>
</html>
But honestly, maybe you would rather just use a background image, and have it look ugly/broken when text is resized. The css is a bit 'hack-y' for my tastes, especially all the padding compensation needed due to the anchor and li having to be siblings.
I've tested this in Firefox 3.5, Safari 4, and Opera 9.6. I don't have access to anything else at the moment, so it's probably not even very pretty.
Needless to say it's probably a complete wreck in all IE versions. Sorry… It was just my own little test to see if I was up to the task!
Edit: It DOES work with page zoom and text resize, but again, IE support (?)…