d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Just Starting Html And Css > Website Building For Beginners
Add Reply New Topic New Poll
Member
Posts: 12,348
Joined: Jun 30 2007
Gold: 1,573.00
Trader: Trusted
Nov 22 2013 01:30pm
This thread will be dedicated to improving my coding skills and a place where other new comers can join in on this learning experience with me I will try and post something new I learn everyday.
If you find areas where I can improve such as condensing code please post with instructions on how and what they do Please keep criticism constructive..


To start things off i thought a navigation bar would be a good spot to start so here it is

Basic nav menu html
Code
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Project 1</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>

<header>

<nav>
<ul>
<li><a href="Your site url here">Name of your button</a></li>
<li><a href="Your site url here">Name of your button</a></li>
<li><a href="Your site url here">Name of your button</a></li>
</ul>
</nav>
</header>
<section>
<article>
</article>
<section>
<footer>
</footer>
</body
</html>


CSS for basic nav bar
Code
/*Navigation bar*/
/*===============================*/

nav{
border-width:1px 0;
list-style:none;
margin:1;
padding:1;
text-align:center;
font-size:18px;


}
nav li{
display:inline;
}



advaced nav menu html (cascading)

Code
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Project 1</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>

<header>

<nav>
<ul id="navmenu">

<li><a href="#">main button name</a>
<ul class="sub1">
<li><a href="your link here">Button name</a></li>
<li><a href="your link here">Button name</a></li>
<li><a href="your link here">Button name</a></li>
</ul>

</li><li><a href="#">main button name</a>


<ul class="sub2">
<li><a href="#">Button name</a></li>
<li><a href="#">Button name</a></li>
<li><a href="#">Button name</a></li>
</ul>
</li>

<li><a href="your link here">main button name</a>
<ul class="sub3">
<li><a href="#">Button name</a></li>
<li><a href="#">Button name</a></li>
<li><a href="#">Button name</a></li>
</ul>
</li>

</ul>
</nav>
</header>
<section>
<article>
</article>
<section>
<footer>
</footer>
</body
</html>


Css for advanced nav menu

Code
header li {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
}
ul {
list-style-type: none;
padding: 0;
text-align: center;
}
ul#navmenu, ul.sub1, ul.sub2, ul.sub3 {
list-style-type: none;
}
ul#navmenu li {
float: left;
margin-right: 4px;
outline: 1px none;
position: relative;
text-align: center;
width: 125px;
}
ul#navmenu a {
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
border-radius: 3px;
display: block;
height: 25px;
line-height: 25px;
text-decoration: none;
width: 125px;
}
ul#navmenu .sub1 a {
margin-top: 3px;
}
ul#navmenu .sub1 li {
border: 1px solid #808080;
}
ul#navmenu .sub2 a {
margin-top: 3px;
}
ul#navmenu .sub2 li {
border: 1px solid #808080;
}
ul#navmenu .sub3 a {
margin-top: 3px;
}
ul#navmenu .sub3 li {
border: 1px solid #808080;
}
ul#navmenu li:hover > a {
background-color: #CCFFCC;
}
ul#navmenu ul.sub1 {
display: none;
left: 0;
position: absolute;
top: 26px;
}
ul#navmenu ul.sub2 {
display: none;
left: 0;
position: absolute;
top: 26px;
}
ul#navmenu ul.sub3 {
display: none;
left: 0;
position: absolute;
top: 26px;
}
ul#navmenu li:hover .sub1 {
display: block;
}
ul#navmenu li:hover .sub2 {
display: block;
}
ul#navmenu li:hover .sub3 {
display: block;
}


This post was edited by Derek on Nov 22 2013 01:31pm
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Nov 22 2013 01:51pm
Did you even check this code on w3validator? Just scrolling through the code I noticed failing syntax for </body and servere lack of indentation in certain places.
w3validator is a really great way to learn to code correctly. It's also a good base to making cross-browser compliant websites.

Why don't you use a jsfiddle if you are looking for contributions and critiscm? You know your post won't be editable after some hours right?

When you don't know the link href (<a href="">), you usually use # instead of creating a broken link like "Your link here", because then if you try to click it (to trigger :active or :visited) it won't go somewhere silly where you'll have to click Back in your browser.
Member
Posts: 12,348
Joined: Jun 30 2007
Gold: 1,573.00
Trader: Trusted
Nov 22 2013 02:02pm
Quote (Eagl3s1ght @ Nov 22 2013 03:51pm)
Did you even check this code on w3validator? Just scrolling through the code I noticed failing syntax for </body and servere lack of indentation in certain places.
w3validator is a really great way to learn to code correctly. It's also a good base to making cross-browser compliant websites.

Why don't you use a jsfiddle if you are looking for contributions and critiscm? You know your post won't be editable after some hours right?

When you don't know the link href (<a href="">), you usually use # instead of creating a broken link like "Your link here", because then if you try to click it (to trigger :active or :visited) it won't go somewhere silly where you'll have to click Back in your browser.


I did not use the validator i should have though also i know that use the # sign is better practice then put your link here an stuff it was more to help other that dint know as for the indentation thats something I know i need to work on.

No idea what jsfiddle is looking at it now :P
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Nov 22 2013 02:08pm
Also, look at Wordpress CSS Coding Standards http://make.wordpress.org/core/handbook/coding-standards/css/ to learn a thing or two, while it may be a bit of a preference-thing, I think you should make a new line for every CSS selector, like so:

Code
ul#navmenu,
ul.sub1,
ul.sub2,
ul.sub3{
list-style-type: none;
}


This post was edited by Eagl3s1ght on Nov 22 2013 02:11pm
Member
Posts: 12,348
Joined: Jun 30 2007
Gold: 1,573.00
Trader: Trusted
Nov 22 2013 02:36pm
Quote (Eagl3s1ght @ Nov 22 2013 04:08pm)
Also, look at Wordpress CSS Coding Standards http://make.wordpress.org/core/handbook/coding-standards/css/ to learn a thing or two, while it may be a bit of a preference-thing, I think you should make a new line for every CSS selector, like so:

Code
ul#navmenu,
ul.sub1,
ul.sub2,
ul.sub3{
    list-style-type: none;
}


Ah yes that looks alot cleaner
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll