Trying to remove a left border style from an a-element - html

I have a navbar that is like so:
<ul>
<li>Home</li>
<li>Gallery</li>
<li>Testimonials</li>
<li>Services</li>
<li>Contact</li>
</ul>
And it has css like so:
.nav_bar {
margin: 0px 0px 0px 0px;
height:40px;
}
.nav_bar ul {
margin:0px;
padding:0;
list-style:none;
width:940px;
}
.nav_bar li {
margin: 0px 0px 0px 0px;
display:inline;
}
.nav_bar li a {
text-align:center;
border-left: 1px solid #fff;
text-decoration:none;
padding: 20px;
width:147px;
background:#000000;
color:#eee;
float:left;
}
As you can imagine, this puts a white line to the left of the elements, Which I want except for the first one. I tried adding:
Home
to the first li but it doesn't do anything, and in developer tools, it is crossed out with a orange triangle next to it. So, how would I accomplish the task at hand?
Thanks for your help.

You have a slight error in your border-left syntax, it should be:
Home
See this introduction to CSS shorthands for more info on the sort of syntax you should use.

Why not do
.nav_bar li a:first-child {
border-left: 1px solid #000;
}
Or if you don't want it at all
.nav_bar li a:first-child { border:none; }

From http://www.w3.org/TR/CSS2/selector.html#first-child:
The :first-child pseudo-class matches an element that is the first child element of some other element.
In the following example, the selector matches any P element that is the first child of a DIV element. The rule suppresses indentation for the first paragraph of a DIV:
div > p:first-child { text-indent: 0 }
This selector would match the P inside the DIV of the following fragment:
<P> The last P before the note.
<DIV class="note">
<P> The first P inside the note.
</DIV>
but would not match the second P in the following fragment:
<P> The last P before the note.
<DIV class="note">
<H2>Note</H2>
<P> The first P inside the note.
</DIV>

Related

Curved corners with CSS

I have a simple navigation Bar and some styling with CSS already.
The nav Bar will have a white border on along the top for the inner links.
For the two outer links I want there to be a border on the left for the left link and on the right for the right link and also curved corners but i don't know how to focus the CSS on just these two li's.
I tried to give the li an id of home but that didn't work
i'v also tried putting the curved corners code in the ul and the NavBar tags.
Here is wht I have tried
<div id="NavBar">
<ul>
<li id="Home"><strong>Home</strong></li>
<li><strong>About Us</strong></li>
<li><strong>Products</strong></li>
<li><strong>Policies</strong></li>
<li id="ContactUs"><strong>Contact Us</strong></li>
</ul>
And this is the CSS which i have tried to focus on the one li home.
#NavBar li {
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
border:solid 3px #FFF;
border-bottom:0px;
width:20%;
}
#NavBar li Home {
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
border:solid 3px #FFF;
border-bottom:0px;
width:20%;
-moz-border-radius-topleft: 10px;
-webkit-border-top-left-radius: 10px;
}
Thanks for any help
Created a JSFiddle: https://jsfiddle.net/b4ejndkz/
If you're going to use width:20% and specify a border width, you'll need box-sizing:border-box;, that way it'll take into account the border size when determining total width. Otherwise it'll split off into 2 lines like it is at the moment.
Then you can set a specific corner to apply a border radius on by doing: border-radius: 5px 0 0 0; (top left, top right, bottom right, bottom left).
You could do it with id selectors https://jsfiddle.net/b4ejndkz/2/... or instead use the CSS selectors :first-child and :last-child to select your first and last elements of your list:
#NavBar li {
box-sizing:border-box;
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
border:solid 3px #FFF;
border-bottom:0px;
width:20%;
}
#NavBar li:first-child {
border-radius: 5px 0 0 0;
}
#NavBar li:last-child {
border-radius: 0 5px 0 0;
}
https://jsfiddle.net/b4ejndkz/1/
Use :first-child and :last-child.
To access only the first or last element of your list, do something like this:
ul li:first-child {
Styles for first element
}
ul li:last-child {
Styles for last element
}
With that, you can apply the needed styles to the matching links.

Creating a vertical line next to a list item

I want to put a little vertical line next to the right of each list item (except the last) but I'm wondering if there is a way to do it other than adding in a new div or something to accommodate the line. I tried just adding a border line for the list but it added one more than I needed.
html
<ul class="list">
<li><span id = "home">Home</span></li>
<li><span id = "about">About</span></li>
<li><span id = "portfolio">Portfolio</span></li>
<li><span id = "contact">Contact</span></li>
</ul>
CSS
.list li {
display: inline;
margin: 0px 25px 0px 0px;
white-space: nowrap;
font-family: Oswald;
color: white;
}
.list {
text-align: right;
padding-right: 2%;
}
#home {
height: 50px;
background-color: black;
}
Just add a right border to all the li elements and then remove it from the last one using the :last-child pseudo class. This will work for dynamic content.
Example Here
.list li {
display:inline-block;
border-right:2px solid;
padding:10px;
}
.list li:last-child {
border-right:none;
}
Alternatively, you could also just use the :not() pseudo class, and avoid applying the border to the last element to begin with.
Example Here
.list li:not(:last-child) {
border-right:2px solid;
}
Support for both of these methods can be found here - http://caniuse.com/#feat=css-sel3
If support is a concern, you could also alternatively just add a left border and remove it from the first child element. (:first-child has more browser support than :last-child/:not). I doubt you need to support older versions of IE though.
Example Here
.list li {
display:inline-block;
border-left:2px solid;
padding:10px;
}
.list li:first-child {
border-left:none;
}
You can achieve that by adding a border on every <li> item and just removing the border for the last element using the css last child selector: li:last-child selecting the last li element of its parent.
You can even combine that with the :not selector to achieve it with one css block.
JSFiddle Demo
I would probably set a border-right on the whole list and use jQuery to remove it on the last item.
This is a little trickier if you don't know the ID of the last item ahead of time, but if it's always going to be "Contact," you can say
$("#contact").attr('style','border-right:none');
You can add this:
li:before {
content: " | ";
}
li:first-child:before {
content: none;
}
Or:
li:not(:first-child):before {
content: " | ";
}
Here's a more universal and simpler solution that will work in older browsers without a hitch: http://jsfiddle.net/pw3vpvLv/.
HTML:
<ul>
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
CSS:
ul > li {
display:inline-block;
padding: 5px 10px;
}
ul > li + li {
border-left: 1px solid;
}

Reduce a white gap between two <hr> tags

I have the following menu
The two lines are both 'hr' tags and the menu is a div containing a ul. I have been googling for a while now and trying adjusting the css with margin and padding but I want to reduce the white space between the lines and the text bringing them closer to the text.
HTML:
<hr id="header_line"/>
<div id="menu_bar">
<ul>
<li>Add new Form</li>
<li>View old forms</li>
<li>Reports</li>
<li>Site Administration</li>
</ul>
</div>
<hr id="under_menu_line"/>
CSS:
#menu_bar ul {
list-style:none;
padding-left:0px;
}
#menu_bar ul li {
display:inline;
padding-left:10px;
}
#menu_bar ul li a {
text-decoration:none;
color:Black;
font-family:Century Gothic;
font-size:12pt;
}
#menu_bar ul li a:hover {
color:#007C5A;
}
#header_line {
margin-top:5px;
}
#under_menu_line {
margin-top:5px;
}
Any ideas?
The best solution would be to drop the <hr>s, and use border-top and border-bottom in conjunction with padding on the div.
<hr> should be used as a horizontal rule. For instance, a hard separation of paragraphs or a long break. And not as a visual element.
Just like with any other element, the <hr> is controlled by CSS. The space you want to control is just the margin. This is the default from Firefox:
hr {
-moz-box-sizing: border-box;
-moz-float-edge: margin-box;
border: 1px inset;
color: gray;
display: block;
height: 2px;
margin: 0.5em auto;
}
So, the following will make the space 0.1em instead of 0.5em:
hr { margin: 0.1em auto; }
Try this and tell me if this is what you wanted.
#header_line { margin-top:5px; margin-bottom:-10px;}
#under_menu_line { margin-top:-10px; }
Use
#header_line{
margin-bottom:0px;
}
#under_menu_line{
margin-top:0px;
}

Rounding corners nav bar

Hi Im having troubles rounding corners on my navigation bar, when I write -
border-radius: 15px; it round all the corners of the <a> but I want only to round of the <li> so only the margins of the whole toolbar.
Here is a fiddle.
thanks
EDIT
only want home and contact to be rounded
This also works:
ul#list-nav li {
border:2px solid blue;
float:left;
overflow:hidden;
}
li.first{
border-top-left-radius:15px;
border-bottom-left-radius:15px;
}
li.last{
border-top-right-radius:15px;
border-bottom-right-radius:15px;
}
Here is the updated fiddle.
To round the corners of the first and last li elements. Try
:first-child and :last-child selectors
Check out the live Demo: http://jsfiddle.net/HYhBe/33/
Add two new classes; one that rounds the left corners and one that rounds the right corners and apply these to the first and last element respectively.
Fiddle
.round_left {
border-radius: 15px 0 0 15px;
}
.round_right {
border-radius: 0 15px 15px 0;
}
<ul id="list-nav">
<li>HOME</li>
<li>SERVICES</li>
<li>GALLERY</li>
<li>THE WAY WE WORK</li>
<li>CONTACT</li>
</ul>
Link updated - http://jsfiddle.net/HYhBe/24/
ul#list-nav li -> float:left & overflow:hidden;
you can remove display inline. li is a block level element.
ul#list-nav li {
border-radius: 15px;
float:left;
overflow:hidden;
}
-- For updated question --
Remove border-radius property from 'ul#list-nav li a' and add to your CSS file:
ul#list-nav li:first-child a{ border-radius: 15px 0 0 15px;}
ul#list-nav li:last-child a{ border-radius: 0 15px 15px 0;}

HTML/CSS - Remove spaces from line breaks in code for LI

Hey,
Is there a way to get browsers to ignore line breaks in the source?
<div id="navbar">
<div id="navbar-container">
<ul>
<li>HOME</li>
<li>TUTORIALS</li>
<li>BLOG</li>
<li>FORUMS</li>
<li>LINKS</li>
<li> </li>
</ul>
</div>
</div>
#navbar {
background:#FFF;
width:940px;
margin:auto;
border-radius: 10px 10px;
-webkit-box-shadow: 5px 5px 10px #888;
}
#navbar-container {
margin:auto;
}
#navbar-container ul {
list-style:none;
text-align:center;
display:block;
width:auto;
padding:0;
margin:0;
}
#navbar-container li{
list-style:none;
border-left:3px solid black;
display:inline-block;
font-family:"Arial", sans-serif;
font-size:2em;
padding:0 7px 0 10px;
margin:0;
white-space:nowrap;
}
#navbar-container li:hover{
color:#FFF;
background:#000;
border-left:3px solid black;
display:inline-block;
font-family:"Arial", sans-serif;
font-size:2em;
margin:0;
padding:0 7px 0 10px;
}
It's placing a small space between each LI, I've set it up so then line up horizontally,
i could just remove the line breaks in the source, but id prefer not to.
You can float them (either left or right), or you can comment-out the spaces:
<ul>
<li>...</li><!--
--><li>...</li>
</ul>
Or simply leave the tags open 'til the next line.
<ul>
<li>...</li
><li>...</li
><li>...</li>
</ul>
IE seems to do that as a hold-over from the days when list items did not have closing tags. A common way around that is to put the closing > on the next line, i.e.
<ul>
<li>HOME</li
><li>TUTORIALS</li
><li>BLOG</li
>etc...
All browsers should totally ignore whitespace. Is there a particular browser giving you trouble?
Try:
li { margin: 0; padding: 0 }
I was wondering the same thing and what worked for me was:
li { display: table-cell; }
All breaks are ignored and now my menu buttons are right next to each other.
You can see a live example here on my music site: http://www.yanike.tk
I used a CSS Sprite on my UL LI for my navigation menu (home, media,...).