<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SEO Teknikleri ve Google SEO Makaleleri &#187; Turning a list into a navigation bar</title>
	<atom:link href="http://www.sanalbilisim.net/seo/tag/turning-a-list-into-a-navigation-bar/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sanalbilisim.net/seo</link>
	<description></description>
	<lastBuildDate>Wed, 11 Aug 2010 02:08:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Turning a list into a navigation bar</title>
		<link>http://www.sanalbilisim.net/seo/css-makaleleri/turning-a-list-into-a-navigation-bar.html</link>
		<comments>http://www.sanalbilisim.net/seo/css-makaleleri/turning-a-list-into-a-navigation-bar.html#comments</comments>
		<pubDate>Mon, 17 Nov 2008 02:47:11 +0000</pubDate>
		<dc:creator>teori</dc:creator>
				<category><![CDATA[CSS Makaleleri]]></category>
		<category><![CDATA[En iyi css makelesi]]></category>
		<category><![CDATA[Turning a list into a navigation bar]]></category>

		<guid isPermaLink="false">http://www.sanalbilisim.net/?p=389</guid>
		<description><![CDATA[Turning a list into a navigation bar I’ve received a couple of requests for a description of how I created the navigation bar that is currently used on this site. The CSS used isn’t all that advanced, and I hadn’t really thought about describing it in detail, but after being asked about it I decided [...]]]></description>
			<content:encoded><![CDATA[<p>Turning a list into a navigation bar<br />
I’ve received a couple of requests for a description of how I created the navigation bar that is currently used on this site. The CSS used isn’t all that advanced, and I hadn’t really thought about describing it in detail, but after being asked about it I decided to do a write-up.<span id="more-389"></span></p>
<p>I’ve cleaned up the HTML and CSS slightly, so if you compare this to what is actually used on the site there will be some small differences. In case I have redesigned by the time you read this, check out <a href="http://www.456bereastreet.com/lab/ul_navbar/step11/">the finished example</a> to see what the menu looked like at the time of this writing.<br />
The HTML<br />
The markup is very simple. It’s an unordered list, with each link in a separate list item:</p>
<ol class="code">
<li><code>&lt;ul id="nav"&gt;</code></li>
<li class="tab1"><code>&lt;li id="nav-home"&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;</code></li>
<li class="tab1"><code>&lt;li id="nav-about"&gt;&lt;a href="#"&gt;About&lt;/a&gt;&lt;/li&gt;</code></li>
<li class="tab1"><code>&lt;li id="nav-archive"&gt;&lt;a href="#"&gt;Archive&lt;/a&gt;&lt;/li&gt;</code></li>
<li class="tab1"><code>&lt;li id="nav-lab"&gt;&lt;a href="#"&gt;Lab&lt;/a&gt;&lt;/li&gt;</code></li>
<li class="tab1"><code>&lt;li id="nav-reviews"&gt;&lt;a href="#"&gt;Reviews&lt;/a&gt;&lt;/li&gt;</code></li>
<li class="tab1"><code>&lt;li id="nav-contact"&gt;&lt;a href="#"&gt;Contact&lt;/a&gt;&lt;/li&gt;</code></li>
<li><code>&lt;/ul&gt;</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step01/">View Step 1</a>.</p>
<p>Why use a list? Because a navigation bar, or menu, is a list of links. The best (most semantic) way of marking up a list of links is to use a list element. Using a list also has the benefit of providing structure even if CSS is disabled.</p>
<p>At this stage, with no CSS applied, the list will look like any old (normally bulleted) list, styled only by the browser’s defaults.</p>
<p>I’ve given <code>id</code> attributes to the <code>ul</code> and <code>li</code> elements. The <code>id</code> attribute for the <code>ul</code> element is used by the CSS rules that style the entire list. The <code>li</code> elements have different <code>id</code> values to enable the use of CSS to highlight the currently selected link. This is done by specifying an <code>id</code> for the <code>body</code> element. More on that later.</p>
<h2>The CSS</h2>
<p>I’ll describe the CSS I’ve used to style the list in a step-by-step fashion.</p>
<p>First of all, I set the margins and padding of the list and list items to zero, and tell the list items to be displayed inline:</p>
<ol class="code">
<li><code>#nav {</code></li>
<li class="tab1"><code>margin:0;</code></li>
<li class="tab1"><code>padding:0;</code></li>
<li><code>}</code></li>
<li><code>#nav li {</code></li>
<li class="tab1"><code>display:inline;</code></li>
<li class="tab1"><code>padding:0;</code></li>
<li class="tab1"><code>margin:0;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step02/">View Step 2</a></p>
<p>This will make all the links display one after another on the same line, as if the list wasn’t there. It will also remove the list bullets, since they are only displayed when <code>display:list-item</code> (the default display mode for list items) is used. Some browsers are said to incorrectly display the list bullets even though <code>display:inline</code> has been applied to the list items. I haven’t seen this happen in any of the browsers I tested in, but if you want to make sure that no browsers display list bullets, you can add <code>list-style-type:none</code> to the rule for <code>#nav</code>.</p>
<p>Next, it’s time to start styling the menu tabs. I do this by adding styles to the links, not to the list items. The reason for that is that I want the entire area of each tab to be clickable. First a bit of colour to make the changes more obvious:</p>
<ol class="code">
<li><code>#nav a:link,</code></li>
<li><code>#nav a:visited {</code></li>
<li class="tab1"><code>color:#000;</code></li>
<li class="tab1"><code>background:#b2b580;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step03/">View Step 3</a>.</p>
<p>Note that I’m styling the normal and visited states of the links to look the same. the next step is to add a bit of padding to the links:</p>
<ol class="code">
<li><code>#nav a:link,</code></li>
<li><code>#nav a:visited {</code></li>
<li class="tab1"><code>color:#000;</code></li>
<li class="tab1"><code>background:#b2b580;</code></li>
<li class="tab1 changed"><code>padding:20px 40px 4px 10px;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step04/">View Step 4</a>.</p>
<p>That’s a bit better. But there is a potential problem that isn’t visible here. Since the links are inline elements, their vertical padding will not add to their line height. It’s easier to see this if the <code>ul</code> element has a background, so I’ll add a background colour and a background image:</p>
<ol class="code">
<li><code>#nav {</code></li>
<li class="tab1"><code>margin:0;</code></li>
<li class="tab1"><code>padding:0;</code></li>
<li class="tab1 changed"><code>background:#808259 url(nav_bg.jpg) 0 0 repeat-x;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step05/">View Step 5</a>.</p>
<p>Oops. Now the links are sticking out of the list element. To fix this, I’ve turned the links into block boxes by floating them to the left. I’ve also set their width to <code>auto</code>, to make them shrink to fit their content:</p>
<ol class="code">
<li><code>#nav a:link,</code></li>
<li><code>#nav a:visited {</code></li>
<li class="tab1"><code>color:#000;</code></li>
<li class="tab1"><code>background:#b2b580;</code></li>
<li class="tab1"><code>padding:20px 40px 4px 10px;</code></li>
<li class="tab1 changed"><code>float:left;</code></li>
<li class="tab1 changed"><code>width:auto;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step06/">View Step 6</a>.</p>
<p>Adding <code>display:block</code> to the CSS rule for the links would also have made them block boxes, but since a floated element automatically generates a block box, that isn’t necessary.</p>
<p>As you may have noticed, the background disappeared when the links were floated. That’s because floated elements are taken out of the document flow, which causes the <code>ul</code> element containing them to have zero height. Thus, the background is there, but it isn’t visible. To make the <code>ul</code> enclose the links, I’ve floated that too. I’ve also set its width to 100%, making it span the whole window (except for the padding I’ve given the <code>body</code> element in this example):</p>
<ol class="code">
<li><code>#nav {</code></li>
<li class="tab1"><code>margin:0;</code></li>
<li class="tab1"><code>padding:0;</code></li>
<li class="tab1"><code>background:#808259 url(nav_bg.jpg) 0 0 repeat-x;</code></li>
<li class="tab1 changed"><code>float:left;</code></li>
<li class="tab1 changed"><code>width:100%;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step07/">View Step 7</a>.</p>
<p>To visually separate the links from each other, I’ve added a right border to the links. Then, to give the first link a left border as well, I’ve used a <code>:first-child</code> pseudo-class to apply a rule only to the link in the very first list item. I’ve also added top and bottom borders to the <code>ul</code> element:</p>
<ol class="code">
<li><code>#nav {</code></li>
<li class="tab1"><code>margin:0;</code></li>
<li class="tab1"><code>padding:0;</code></li>
<li class="tab1"><code>background:#808259 url(nav_bg.jpg) 0 0 repeat-x;</code></li>
<li class="tab1"><code>float:left;</code></li>
<li class="tab1"><code>width:100%;</code></li>
<li class="tab1 changed"><code>border:1px solid #42432d;</code></li>
<li class="tab1 changed"><code>border-width:1px 0;</code></li>
<li><code>}</code></li>
<li><code>#nav a:link,</code></li>
<li><code>#nav a:visited {</code></li>
<li class="tab1"><code>color:#000;</code></li>
<li class="tab1"><code>background:#b2b580;</code></li>
<li class="tab1"><code>padding:20px 40px 4px 10px;</code></li>
<li class="tab1"><code>float:left;</code></li>
<li class="tab1"><code>width:auto;</code></li>
<li class="tab1 changed"><code>border-right:1px solid #42432d;</code></li>
<li><code>}</code></li>
<li class="changed"><code>#nav li:first-child a {</code></li>
<li class="tab1 changed"><code>border-left:1px solid #42432d;</code></li>
<li class="changed"><code>}</code></li>
</ol>
<p>The <code>:first-child</code> pseudo-class is not recognised by Internet Explorer for Windows, so the first link won’t have a left border in that browser. In this case, that isn’t a major problem, so I’ve left it like that. If it’s really important to you, you’ll need to add a class to the first list item (or the link in it), and then use that to give the link a left border.</p>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step08/">View Step 8</a>.</p>
<p>Next I’ve changed the way the link text is displayed by removing the underlining, making the text bold, specifying font size, line-height, and a different font family, making the text uppercase, and adding a little bit of drop shadow. The drop shadow is created with the <code>text-shadow</code> property, a CSS3 property that is currently only supported by Safari and OmniWeb:</p>
<ol class="code">
<li><code>#nav a:link,</code></li>
<li><code>#nav a:visited {</code></li>
<li class="tab1"><code>color:#000;</code></li>
<li class="tab1"><code>background:#b2b580;</code></li>
<li class="tab1"><code>padding:20px 40px 4px 10px;</code></li>
<li class="tab1"><code>float:left;</code></li>
<li class="tab1"><code>width:auto;</code></li>
<li class="tab1"><code>border-right:1px solid #42432d;</code></li>
<li class="tab1 changed"><code>text-decoration:none;</code></li>
<li class="tab1 changed"><code>font:bold 1em/1em Arial, Helvetica, sans-serif;</code></li>
<li class="tab1 changed"><code>text-transform:uppercase;</code></li>
<li class="tab1 changed"><code>text-shadow: 2px 2px 2px #555;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step09/">View Step 9</a>.</p>
<p>To give some visual feedback when the links are hovered over, I’ve given their <code>:hover</code> state different text and background colours:</p>
<ol class="code">
<li><code>#nav a:hover {</code></li>
<li class="tab1"><code>color:#fff;</code></li>
<li class="tab1"><code>background:#727454;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step10/">View Step 10</a>.</p>
<p>In the final step, I’ve added rules that will make the selected link look different than the others, to show visitors where they are on the site.</p>
<p>In case you haven’t seen an example of specifying an <code>id</code> attribute for the <code>body</code> element to style the “current” navigation tab differently before, that’s what the first two rules do. In the examples linked to from this article, I’ve set <code>id</code> of the <code>body</code> element to “<code>home</code>”, which makes the “Home” tab the current one. Changing it to “<code>about</code>” would make the “About” tab the current one, and so on.</p>
<p>I’ve also made the selected link stay the same when it’s hovered over. It can be argued that the current menu item should not be a link at all. In this case, I’ve chosen to leave the link in the markup and use CSS to remove the visual feedback on hover.</p>
<p>To give some visual feedback when you click on one of the links, I’ve given the <code>:active</code> state of the links the same styling as the selected link:</p>
<ol class="code">
<li><code>#home #nav-home a,</code></li>
<li><code>#about #nav-about a,</code></li>
<li><code>#archive #nav-archive a,</code></li>
<li><code>#lab #nav-lab a,</code></li>
<li><code>#reviews #nav-reviews a,</code></li>
<li><code>#contact #nav-contact a {</code></li>
<li class="tab1"><code>background:#e35a00;</code></li>
<li class="tab1"><code>color:#fff;</code></li>
<li class="tab1"><code>text-shadow:none;</code></li>
<li><code>}</code></li>
<li><code>#home #nav-home a:hover,</code></li>
<li><code>#about #nav-about a:hover,</code></li>
<li><code>#archive #nav-archive a:hover,</code></li>
<li><code>#lab #nav-lab a:hover,</code></li>
<li><code>#reviews #nav-reviews a:hover,</code></li>
<li><code>#contact #nav-contact a:hover {</code></li>
<li class="tab1"><code>background:#e35a00;</code></li>
<li><code>}</code></li>
<li><code>#nav a:active {</code></li>
<li class="tab1"><code>background:#e35a00;</code></li>
<li class="tab1"><code>color:#fff;</code></li>
<li><code>}</code></li>
</ol>
<p><a href="http://www.456bereastreet.com/lab/ul_navbar/step11/">View Step 11</a>, the finished navigation menu.</p>
<p>That’s it. This step-by-step tutorial makes the whole thing look more advanced than it really is. View source on the final example to see the complete set of CSS rules. By the way, with a couple of small exceptions (the left border on the first link, and the text shadow), this works in just about any browser, even Internet Explorer (version 5 or newer).</p>
<p>I hope you’ve been able to follow along well enough to be able to create your own navigation menu. The styling possibilities are almost endless.</p>
<p>kaynak: <a href="http://www.456bereastreet.com/archive/200501/turning_a_list_into_a_navigation_bar/">http://www.456bereastreet.com/archive/200501/turning_a_list_into_a_navigation_bar/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sanalbilisim.net/seo/css-makaleleri/turning-a-list-into-a-navigation-bar.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
