.

Tuesday, 13 October 2015

A Super Simple Horizontal Navigation Bar

A Super Simple Horizontal Navigation Bar



I occurs to me that, while I’ve written tutorials on tabbed navigation bars, dropdown navigation bars, and even horizontal dropdown navigation bars, I’ve never stopped to explain how to build a basic, no-frills horizontal navigation bar. And in more cases than not, a simple navigation bar is exactly what the doctor ordered.
So today’s tutorial is all about going back to basics. This is what you need to know to build a simple navigation bar like the one pictured above (and you can see a working example here).

The List

As with most modern navigation bars, ours will be based on the unordered list (<ul>) tag. This makes semantic sense, a navigation bar is really nothing but a list of links leading into your site. The traditional horizontal orientation is simply a convenient means to get all of our most important list items “above the fold,” so the user can see them without having to scroll down the page.
So here is our sample HTML:



<ul id="nav">
<li><a href="#">About Us</a></li>
<li><a href="#">Our Products</a></li>
<li><a href="#">FAQs</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Login</a></li>
</ul>
That’s really all it takes! You’ll notice I did use one ID, so we could tell our navigation bar apart from all the other unordered lists on the page. But if this were tucked into a div with its own ID (like a “banner” or “header” div), the ID probably wouldn’t be necessary. And yes, I could add even more IDs and classes if I wanted to make this fancier, but we’re all about simplicity today.

Making It Horizontal

By default, our list is vertical. So let’s make it horizontal:

#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none; }
#nav li {
float: left; }
Here we’re floating both our list and our list items left. Floating the list items left is what pulls them into a nice horizontal row for us, stacking the items from left to right. However, because of how floats behave, our containing list will collapse to a height of zero unless it is also floated left.
And that wouldn’t be a major problem, except I’m planning to give my list a background color later that I want to show up behind my list items, and if my list collapses, that won’t happen. That’s also why I’m giving my list a width of 100%: That way, it’ll fill up the entire width of the page (or of its container, if it’s in a container with a width set).
I’m also removing most of the margins and padding to make the list behave itself (I’m leaving some margin on the bottom, simply for aesthetic purposes), and setting the list-style to “none,” which removes the bullets from my list.

Certainly nothing stylish (and probably difficult to use, to boot), but believe it or not, most of our heavy lifting is now done! From this basic framework, you could construct any number of unique navigation bars. But let’s style ours a bit.
First, we’ll give our navigation bar a background and some borders by updating our #nav CSS to this:

#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc; }
And let’s give our anchor tags a bit of breathing room and style, too:

#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #069;
border-right: 1px solid #ccc; }
Here, I’m giving the anchors a display of “block” to make sure they fill up the entire list item and make the whole area clickable. Then I’m adding some padding to space them out a bit. I’m also removing the underline, making the font bold, setting our color to a nice blue, and adding a border to the right-hand side of the item, which matches the border we added to the top and bottom of our unordered list.
And finally, let’s give the navigation items a different color when our users mouse over:

#nav li a:hover {
color: #c00;
background-color: #fff; }
And just like that, we have a perfectly functional, useable, and useful navigation bar.You can see it in action here. And here’s all the CSS in one location:



#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc; }
#nav li {
float: left; }
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #069;
border-right: 1px solid #ccc; }
#nav li a:hover {
color: #c00;
background-color: #fff; }

Like I said, this is a useful framework from which to work. 90% of the navigation bars I build start out almost exactly like this. It’s just a matter of styling them in different ways to get the look you’re going for.

Monday, 12 October 2015

CSS3 Color Names

CSS3 Color Names

147 color names are defined in the CSS3 color specification (17 standard colors plus 130 more). The table below lists them all, along with their hexadecimal values.

Remark Tip: The 17 standard colors are: aqua, black, blue, fuchsia, gray, grey, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow.



Color NameHEXColorShadesMix
AliceBlue #F0F8FFShadesMix
AntiqueWhite #FAEBD7ShadesMix
Aqua #00FFFFShadesMix
Aquamarine #7FFFD4ShadesMix
Azure #F0FFFFShadesMix
Beige #F5F5DCShadesMix
Bisque #FFE4C4ShadesMix
Black #000000ShadesMix
BlanchedAlmond #FFEBCDShadesMix
Blue #0000FFShadesMix
BlueViolet #8A2BE2ShadesMix
Brown #A52A2AShadesMix
BurlyWood #DEB887ShadesMix
CadetBlue #5F9EA0ShadesMix
Chartreuse #7FFF00ShadesMix
Chocolate #D2691EShadesMix
Coral #FF7F50ShadesMix
CornflowerBlue #6495EDShadesMix
Cornsilk #FFF8DCShadesMix
Crimson #DC143CShadesMix
Cyan #00FFFFShadesMix
DarkBlue #00008BShadesMix
DarkCyan #008B8BShadesMix
DarkGoldenRod #B8860BShadesMix
DarkGray #A9A9A9ShadesMix
DarkGrey #A9A9A9ShadesMix
DarkGreen #006400ShadesMix
DarkKhaki #BDB76BShadesMix
DarkMagenta #8B008BShadesMix
DarkOliveGreen #556B2FShadesMix
Darkorange #FF8C00ShadesMix
DarkOrchid #9932CCShadesMix
DarkRed #8B0000ShadesMix
DarkSalmon #E9967AShadesMix
DarkSeaGreen #8FBC8FShadesMix
DarkSlateBlue #483D8BShadesMix
DarkSlateGray #2F4F4FShadesMix
DarkSlateGrey #2F4F4FShadesMix
DarkTurquoise #00CED1ShadesMix
DarkViolet #9400D3ShadesMix
DeepPink #FF1493ShadesMix
DeepSkyBlue #00BFFFShadesMix
DimGray #696969ShadesMix
DimGrey #696969ShadesMix
DodgerBlue #1E90FFShadesMix
FireBrick #B22222ShadesMix
FloralWhite #FFFAF0ShadesMix
ForestGreen #228B22ShadesMix
Fuchsia #FF00FFShadesMix
Gainsboro #DCDCDCShadesMix
GhostWhite #F8F8FFShadesMix
Gold #FFD700ShadesMix
GoldenRod #DAA520ShadesMix
Gray #808080ShadesMix
Grey #808080ShadesMix
Green #008000ShadesMix
GreenYellow #ADFF2FShadesMix
HoneyDew #F0FFF0ShadesMix
HotPink #FF69B4ShadesMix
IndianRed  #CD5C5CShadesMix
Indigo  #4B0082ShadesMix
Ivory #FFFFF0ShadesMix
Khaki #F0E68CShadesMix
Lavender #E6E6FAShadesMix
LavenderBlush #FFF0F5ShadesMix
LawnGreen #7CFC00ShadesMix
LemonChiffon #FFFACDShadesMix
LightBlue #ADD8E6ShadesMix
LightCoral #F08080ShadesMix
LightCyan #E0FFFFShadesMix
LightGoldenRodYellow #FAFAD2ShadesMix
LightGray #D3D3D3ShadesMix
LightGrey #D3D3D3ShadesMix
LightGreen #90EE90ShadesMix
LightPink #FFB6C1ShadesMix
LightSalmon #FFA07AShadesMix
LightSeaGreen #20B2AAShadesMix
LightSkyBlue #87CEFAShadesMix
LightSlateGray #778899ShadesMix
LightSlateGrey #778899ShadesMix
LightSteelBlue #B0C4DEShadesMix
LightYellow #FFFFE0ShadesMix
Lime #00FF00ShadesMix
LimeGreen #32CD32ShadesMix
Linen #FAF0E6ShadesMix
Magenta #FF00FFShadesMix
Maroon #800000ShadesMix
MediumAquaMarine #66CDAAShadesMix
MediumBlue #0000CDShadesMix
MediumOrchid #BA55D3ShadesMix
MediumPurple #9370D8ShadesMix
MediumSeaGreen #3CB371ShadesMix
MediumSlateBlue #7B68EEShadesMix
MediumSpringGreen #00FA9AShadesMix
MediumTurquoise #48D1CCShadesMix
MediumVioletRed #C71585ShadesMix
MidnightBlue #191970ShadesMix
MintCream #F5FFFAShadesMix
MistyRose #FFE4E1ShadesMix
Moccasin #FFE4B5ShadesMix
NavajoWhite #FFDEADShadesMix
Navy #000080ShadesMix
OldLace #FDF5E6ShadesMix
Olive #808000ShadesMix
OliveDrab #6B8E23ShadesMix
Orange #FFA500ShadesMix
OrangeRed #FF4500ShadesMix
Orchid #DA70D6ShadesMix
PaleGoldenRod #EEE8AAShadesMix
PaleGreen #98FB98ShadesMix
PaleTurquoise #AFEEEEShadesMix
PaleVioletRed #D87093ShadesMix
PapayaWhip #FFEFD5ShadesMix
PeachPuff #FFDAB9ShadesMix
Peru #CD853FShadesMix
Pink #FFC0CBShadesMix
Plum #DDA0DDShadesMix
PowderBlue #B0E0E6ShadesMix
Purple #800080ShadesMix
Red #FF0000ShadesMix
RosyBrown #BC8F8FShadesMix
RoyalBlue #4169E1ShadesMix
SaddleBrown #8B4513ShadesMix
Salmon #FA8072ShadesMix
SandyBrown #F4A460ShadesMix
SeaGreen #2E8B57ShadesMix
SeaShell #FFF5EEShadesMix
Sienna #A0522DShadesMix
Silver #C0C0C0ShadesMix
SkyBlue #87CEEBShadesMix
SlateBlue #6A5ACDShadesMix
SlateGray #708090ShadesMix
SlateGrey #708090ShadesMix
Snow #FFFAFAShadesMix
SpringGreen #00FF7FShadesMix
SteelBlue #4682B4ShadesMix
Tan #D2B48CShadesMix
Teal #008080ShadesMix
Thistle #D8BFD8ShadesMix
Tomato #FF6347ShadesMix
Turquoise #40E0D0ShadesMix
Violet #EE82EEShadesMix
Wheat #F5DEB3ShadesMix
White #FFFFFFShadesMix
WhiteSmoke #F5F5F5ShadesMix
Yellow #FFFF00ShadesMix
YellowGreen #9ACD32ShadesMix

.

Popular Posts

Powered by Blogger.