August 19, 201016 yr Hey guys, Right, I'm basically creating my first ever site. It a kennel website for the couple that bred one of my dogs. I'm literally having to read, research and learn how to do each step using books, and tutorials etc. Please bare with me as I don't yet know the proper terminology or even the right way to go about things. I know this doesnt exactly push the boundaries of web design but I'm quite pleased with it as my first ever attempt. The first big hurdle I've come to is the navigation and general positioning. Sticking some basic text up and getting it to link to one of the other pages is easy enough but looks cack. What I wanted to do was make some buttons, position them on top of the header image and then obviously have them link to the relevant pages. If the picture has attached ok you can see where I've put the navigation text as an example. I'd like the buttons to go above that and below the 'afghan hounds' text. I like the idea of having the buttons linked together and with a shadow so it looks like they're sitting on a shiny white floor. Hope that made sense. If someone could point me in the right direction of how to make the buttons and then how to code them I'd be most grateful. I've googled until my eyes hurt but don't seem to be able to come up with the info I need. Cheers.
August 19, 201016 yr You want a shadow so your probably looking at using photoshop, unless you want to go into css3. Create the buttons in photoshop, with the shadow. You can either create one file with all the buttons, or individual ones. Then save that image as a .png You will then need to use an unordered list for the navigation. Each <li> (list item) is a single link. eg: <ul> <li>Home</li> <li>About</li> </ul> You then need to use css to align the <ul>. And then for each list item. Add a float:left. To show the background image, use background: url('../images/image.png'); Set the width and height. Also add a text-indent:-999 (This hides the text if css is loaded) (Only use if the image has text already written) Let me know if you need more help
August 20, 201016 yr Author Cheers mate. I managed to get the links sorted in a list using a book I've got (never thought to look in there). It gave a basic bit of styling but I don't really have much of a clue what each bit of code does in that part. Apart from the obvious, obviously Am I right in thinking that for the button images you need three images for each button, so show the various states? Havent got the foggiest idea of how to get them behind the text though. And on top of the header.
August 20, 201016 yr I recommend having 3 states on navigation links. Which are (normal, hover and active(when pressed)). A lot of sites only use normal and hover. To get the image behind the text you would use css styling. You would set the background of each "a" (link) element as the image you have created. Each link would have a different class so that you could target it in the css code. To get the various states, say hover, you would target it like: [ li.aboutus a:hover ] in the css. Then you could either change the background url or if you are using a sprite, then change the background position. If you take a look atthis link, it may help you. It looks into how the apple.com menubar is created. Hope it helps you, let me know if you need more help
August 20, 201016 yr Author Thanks for your patience asek! When creating the button do you add the button text via photoshop or do you just make a blank button image and then use the link text on top? I think I've got the jist of it. But making the button is proving harder than I thought. I'm pretty sure I saw one on here somewhere but I can't for the life of me find it.
August 20, 201016 yr You could do either. Depending on which you choose, you have to change the css. If you add the text in photoshop, you can control the look much easier, as it will look the same on everybody elses computer. You can use different fonts, effects etc.. The problem is, it takes more time to edit the button later on, say you want to change the menu item, or add a new item you would have to go into photoshop. When using this method, use a text-indent on the html text, and also set overflow:hidden. This prevents the html text from showing on the button, but also provides the text for screen readers and improves SEO. If you choose to use the link text, you have a limited set of fonts, and it may look different depending on the font size the user sets. So you would test at different sizes. It is much easier CSS wise, just show the link text. Use CSS to style it. Eg. use text-decoration:none, to hide the default underline. You could also set display:block, so that the user can click anywhere in the button, not just the text. Not sure of any tutorials on here, but try not to go for harsh gradients. Subtle ones look much better.
August 21, 201016 yr Author Well I was up 'till about 3am trying to do it and ended up with no navigation at all when I finally gave up. I can make the buttons in photoshop and I think I understand the basic principle of how it should work. I watched a vid on CSS tricks about making the buttons into a sprite, but none of the code worked. I then tried using my CSS book and none of the code worked from that either. The only thing I've managed to do is take the bullet points off the list. Couldnt even get the list to show horizontally.
August 21, 201016 yr Before making the buttons etc, make a basic text navigation using the list structure. To make the list items to show horizontally. Add float:left to the css for the li item <ul> <li>Nav1</li> <li>Nav2</li> </ul> for that the css: ul{ width: 600px; height:40px; } ul li{ float:left; }
August 21, 201016 yr Author This is the code I have in the index.html file...(Would you have a homepage button on the homepage itself?) <ul id="navigation"> <li><a href="news.html">News</a></li> <li><a href="about.html">About</a></li> <li><a href="our-dogs.html">Our Dogs</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="links.html">Links</a></li> </ul> and this is what I have in the CSS file...(so far) /*navigation*/ ul li { float: left; } #navigation { } Not sure whether the float code worked how it should or not, see pic.
August 21, 201016 yr Yes you would want to keep the navigation the same on each page for continuity. It keeps the links in the same order on each page, so the user doesnt get confused when the links are in a different order. That is exactly what the float code does. Can you change it to this. The reason is, the float changes the flow of the page, so the float needs to be cleared. Its probably not the best way of doing it, but I don't know what the rest of the layout is like, so this is the easiest way. <ul id="navigation"> <li><a href="news.html">News</a></li> <li><a href="about.html">About</a></li> <li><a href="our-dogs.html">Our Dogs</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="links.html">Links</a></li> <div class="clear"></div> </ul> In the css, add this: .clear{ clear:both; } The next step is to add a background to each button. What do you want your navigation to look like? Is it a horizontal bar, like the apple.com one, or is it individual buttons? For the bar one, I found this link, which goes step-by-step http://www.secondpicture.com/tutorials/web_design/css_ul_li_horizontal_css_menu.html
August 21, 201016 yr Author Thanks guys! My idea with this site was to plan what I wanted to do, then try to work out how to do it. The only thing I new prior to this was how to create the pages in notepad!...lol I made a header, footer and main content image in photoshop after watching a CSS tricks vid, then coded them in so they kind of linked together. Got that part sorted. Then my idea was to put in a menu bar but so that was sitting on top of the header image itself. (see pic) The header image stops just below Blondie's paw. Looks a bit cack looking at that pic...lol
August 21, 201016 yr Its not great, but since you've made it, you may as well use it to learn. Now you have the layout sorted, you need to transfer that to the coded solution. There are a few ways of doing it, 1. You can use the image as the background of the ul element 2. You can use portions of the image as the background of the li element 3. You can use portions of the image as the background of the a element. Numbers 2 and 3 are more time consuming as they require you to do some measurements if the menu items are different widths. Number 1: First set the ul width to the width of the image and height to the height of the image, then for each li item, use float:left, and text-align:center, also set the the height to the height of the image. Within each li item, add your hyperlink. If the width of each menu item is different then you need to make individual id's for each one and set the width. If they are all equal set a width in the li element. In the css, for the "ul li a" element set the height to the same value as before, and set display:block. I think that is all. Try it out and see if it works. If it doesn't post the code and I can see what I can do.
August 21, 201016 yr Author I gave up. Just ended up following that tutorial and using a 1px wide image that I made myself. It looks crap but it works ok.
August 27, 201016 yr Author Not being happy with not being able to do it I decided to have another go. Think that was about Tuesday and I still cant do it! So I don't mess up anything done so far I just knocked up a quick menu (with two 'states') and some code. I've been all over the place for code and this was the only code that made sense to me. I haven't a clue how to select each 'state' in the background-position code and no matter what I do it just shows four home buttons and nothing else. Here is the css code so far. ul { list-style: none; } ul#navigation { } ul#navigation li { display: inline; } ul#navigation li a { display: block; width: 800px; height: 50px; text-indent: -9999px; float: left; } ul#navigation li.home a { width: 200px; background-position: 0 0; background: url(images/nav-bar.png); } ul#navigation li.about a { width: 200px; background-position: -200px 0; background: url(images/nav-bar.png); } ul#navigation li.portfolio a { width: 200px; background-position: -400px 0; background: url(images/nav-bar.png); } ul#navigation li.contact a { width: 200px; background-position: -600px 0; background: url(images/nav-bar.png); } Html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>menu attempt sprites</title> <link rel="stylesheet" rev="stylesheet" href="menu.css" type="text/css" media="screen" /> </head> <body> <ul id="navigation"> <li class="home"><a href="#" >home</a></li> <li class="about"><a href="#" >about</a></li> <li class="portfolio"><a href="#" >portfolio</a></li> <li class="contact"><a href="#" >contact</a></li> </ul> </body> </html> The menu bar is attached. I put it together quickly just to play with. Each bar measures 800x200px and each button is 200px. Not sure how to crop it properly or if there is supposed to be a gap between the bars, so its looks pretty crap. If someone can give me a hand with this that would be awesome as its proper getting me down now.
August 29, 201016 yr Anyone? Can you add this to your css ul#navigation li.home a:hover { background-image:url("images/nav-bar.png"); background-position:0 50px; } this should work on the first link EDIT: here are all the settings ul { list-style-image:none; list-style-position:outside; list-style-type:none; } ul#navigation { } ul#navigation li { display:inline; } ul#navigation li a { display:block; float:left; height:50px; text-indent:-9999px; width:800px; } ul#navigation li.home a { background-image:url("images/nav-bar.png"); background-position:0 0; background-repeat:repeat; width:201px; } ul#navigation li.home a:hover { background-image:url("images/nav-bar.png"); background-position:1px 50px; } ul#navigation li.about a:hover { background-image:url("images/nav-bar.png"); background-position:-199px 152px; } ul#navigation li.portfolio a:hover { background-image:url("images/nav-bar.png"); background-position:-399px 254px; } ul#navigation li.contact a:hover { background-image:url("images/nav-bar.png"); background-position:-599px 356px; } ul#navigation li.about a { background-image:url("images/nav-bar.png"); background-position:-200px 0; background-repeat:repeat; width:201px; } ul#navigation li.portfolio a { background-image:url("images/nav-bar.png"); background-position:-400px 0; background-repeat:repeat; width:201px; } ul#navigation li.contact a { background-image:url("images/nav-bar.png"); background-position:-600px 0; background-repeat:repeat; width:201px; }
August 29, 201016 yr Author Ha ha...awesome! Thank you So apart from the hover states, what had I left out or done wrong? Because all I ended up with was four home buttons!
August 29, 201016 yr Ha ha...awesome! Thank you So apart from the hover states, what had I left out or done wrong? Because all I ended up with was four home buttons! Ha I cant remember what I changed now, but basically I had to adjust the positioning a bit and put the hover state in
August 29, 201016 yr Author Ha I cant remember what I changed now, but basically I had to adjust the positioning a bit and put the hover state in The original code is in my previous post. I just pasted over it in notepad and didnt save..doh! I couldn't work out how I kept ending up with four home buttons. And then there was the small issue of selecting which 'bar' was going to be viewed for each state. I was on the right track though (sort of) so I'm kinda happy about that
August 29, 201016 yr The original code is in my previous post. I just pasted over it in notepad and didnt save..doh! I couldn't work out how I kept ending up with four home buttons. And then there was the small issue of selecting which 'bar' was going to be viewed for each state. I was on the right track though (sort of) so I'm kinda happy about that you can also add this to the css to highlight the page you are on ul#navigation li.home .current { background-image:url("images/nav-bar.png"); background-position:1px 50px; } and the html <ul id="navigation"> <li class="home"><a class="current" href="#" >home</a></li> <li class="about"><a href="#" >about</a></li> <li class="portfolio"><a href="#" >portfolio</a></li> <li class="contact"><a href="#" >contact</a></li> </ul>
August 29, 201016 yr Author you can also add this to the css to highlight the page you are on ul#navigation li.home .current { background-image:url("images/nav-bar.png"); background-position:1px 50px; } and the html <ul id="navigation"> <li class="home"><a class="current" href="#" >home</a></li> <li class="about"><a href="#" >about</a></li> <li class="portfolio"><a href="#" >portfolio</a></li> <li class="contact"><a href="#" >contact</a></li> </ul> Easy there tiger, I'm still stuck on the last bit of code So do you have to copy that code to each list item? And do you have to mess about with the background positioning again? As I couldnt get that bit right the first time.
August 29, 201016 yr Easy there tiger, I'm still stuck on the last bit of code So do you have to copy that code to each list item? And do you have to mess about with the background positioning again? As I couldnt get that bit right the first time. you won't have to alter the positioning, just change the .current class to what ever page you are on eg about page would be <ul id="navigation"> <li class="home"><a href="#" >home</a></li> <li class="about"><a class="current" href="#" >about</a></li> <li class="portfolio"><a href="#" >portfolio</a></li> <li class="contact"><a href="#" >contact</a></li> </ul> and the css ul#navigation li.about .current { background-image:url("images/nav-bar.png"); background-position:-199px 152px; }
August 29, 201016 yr Author Ahhh I get you. I bet you could hear the penny drop from there! Do you know of any simple tutorials that explain the whole sprite thing? To save me asking you loads of stupid questions. A lot of sites just tell you what to put in, rather than why or how to change it to suit what you're working on. Cheers
August 30, 201016 yr Ahhh I get you. I bet you could hear the penny drop from there! Do you know of any simple tutorials that explain the whole sprite thing? To save me asking you loads of stupid questions. A lot of sites just tell you what to put in, rather than why or how to change it to suit what you're working on. Cheers Here is one of many http://www.electrictoolbox.com/css-sprites-image-navigation/
August 30, 201016 yr Author Here is one of many http://www.electrictoolbox.com/css-sprites-image-navigation/ Thank you. I read about four other tutorials and not one explained it like that one. Why does the padding and margin need to be 'reset' to 0?
August 30, 201016 yr Thank you. I read about four other tutorials and not one explained it like that one. Why does the padding and margin need to be 'reset' to 0? That is just a reset, those settings could probably be removed if you used * {margin:0; padding:0;} at the top of your css style sheet. It basically gives a blank canvas across browsers like ie as ie I believe uses certain default margins and paddings
Create an account or sign in to comment