Creating my initial navigation bar for the first time?

Today was my first day diving into the world of HTML and CSS. Instead of just reading text, I decided to learn by building something.

[ http://jsfiddle.net/GUkrK/ ]

I chose to create a sample navigation bar.

<html>
<head>
    <title> navigation bar </title>
    <link rel="stylesheet" type="text/css" href="menu.css">
</head>
<body>
    <ul id="menu">
        <li id="menu1">
            <a href="http://www.google.com">
                <span>GOOGLE</span>
            </a>
        </li>
        <li id="menu2">
            <a href="http://www.github.com">
                <span>GITHUB</span>
            </a>
        </li>
        <li id="menu3">
            <a href="http://www.quora.com">
                <span>QUORA</span>
            </a>
        </li>
        <li id="menu4">
            <a href="http://www.facebook.com">
                <span>FACEBOOK</span>
            </a>
        </li>
    </ul>
    <hr/>
</body>
</html>

Here is the accompanying CSS:

ul {
    list-style:none;
color:red;
}

#menu {
    float:left;
    vertical-align:middle;
    display:block;
    width:600px;
    height:108px;
}

#menu li {
    display:inline;
    font-size:20px;
    padding:0px;
}

#menu a:link {
    color:white;
    font-weight:bold;
    padding:20px;
    background-color:#27A285;
}

#menu a:hover {
    background-color:#E1C618;
    color:brown;
}

hr {
    height:5px;
    background-color:red;
}

I'm currently struggling with positioning the horizontal line in the design. Should I set it using absolute or relative positioning? Is there a way to make it adjust automatically? Also, why doesn't it span the entire width of the browser and can its width be adjusted?

EDIT: Thank you for all the input. Here's the updated sample http://jsfiddle.net/sunu0000/zdDU5/

Answer №1

Eliminate the use of float: left; in the CSS styling code for #menu.

Example

http://jsfiddle.net/Y8AAH/3/

CSS for #menu

#menu {
    vertical-align:middle;
    display:block;
    width:600px;
    height:108px; /* Changing to 40px may improve appearance */ 
}

Depending on your desired layout, this definition might suffice:

#menu {
    display:block;
    height:108px; /* Changing to 40px may improve appearance */ 
}

Updated example: http://jsfiddle.net/Y8AAH/4/

Updated example with centered menu

#menu {
    height:40px;
    text-align: center;
}

http://jsfiddle.net/Y8AAH/5/

Answer №2

Before moving forward, I strongly recommend reading this resource. It seems like you may need to brush up on your knowledge before seeking clarification =p

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Preserving the dimensions of an expandable div

Is there a way for a div to maintain its print layout while still allowing for zooming? I attempted to enable zoom functionality on a div using jQuery to adjust the height and width percentages of a specific div with the ID "page". <div style=" heigh ...

What is the best way to apply a CSS class to my anchor tag using JavaScript?

I have a good grasp of using JavaScript to insert an anchor element into my webpage. For instance, var userName_a = document.createElement('a'); However, I am interested in adding a style name to that same element as well. I attempted the follo ...

Including a logo and navigation bar in the header while collaborating with different subregions

I'm having trouble getting a picture to display in the header alongside a horizontal menu. I've divided the header into two sections: img and navbar (html). The navbar is showing up correctly, but the image isn't appearing. Any suggestions o ...

Having trouble displaying an image in the background using CSS? Look no further than Laravel

After running the command php artisan storage:link, I am facing an issue where the image does not load. Upon inspection, it displays a message saying "Could not load the image". https://i.sstatic.net/KKFy9.png What adds to my confusion is that ...

Having trouble resizing a KineticJs group to 300x300?

Attempting to adjust the size of a kinetic group is resulting in an error message in JavaScript. The Kinetic JS documentation states that setSize should work with group nodes. ...

Tips for Implementing Multi-Level/Nested in Ajax Requests

I am currently developing a user-friendly web application with intuitive multi-level options that loads new content without the need to refresh the entire page. This is how my structure looks: /index.php /schools.html /colleges.html Within schools.html, ...

Customize the color of Bootstrap active tabs to have a unique and distinct hue for each tab

I have successfully managed to change the color of both active and non-active tabs as a group, but I am wondering if it is possible for the color to remain the same when moving to the next tab. Here is what I've tried: http://jsfiddle.net/pThn6/2031/ ...

Conceal certain tables within a container

On my SharePoint page, I have the following HTML structure: <div id="ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView"> <table cellspacing="0" cellpadding="0" style="border-width:0;"> <table cellspacing="0" cellpadding="0" style="border-width: ...

Are there any methods to improve the coding, align images to the center, and ensure that elements stay in their designated positions?

Is there a way to tidy up the code, center images, and keep everything in place? This is the look I desire: The main outer box should remain centered on the browser page. Pause, play, and stop buttons should float to the left of the box. My image sh ...

Using jQuery to create animations in the ::after pseudo element

My HTML and CSS structure looks like this: <div class="box">Box Content</div> The CSS code is as follows: <style> @-webkit-keyframes widthresize { 0% { width:10px } 50% { width:50 ...

Creating a stylish border for a clip path shape: A step-by-step guide

I'm attempting to design hexagon-shaped buttons with a transparent background and a white 1px border around the hexagon shape I've created using clip path. However, when I add the border, it gets cut off at parts. How can I fix this issue? Below ...

Generating a list of items to buy using a JSON document

So here's the json file I'm working with: [ {"task":"buy bread","who":"Sarah","dueDate":"2023-10-18","done":false}, {"task":"clean car","who":"David","dueDate":"2023-08-30","done":true}, {"task":"write report","who":"Jenny","dueDate":"2023-09 ...

How to create horizontal spacing between divs using Bootstrap 3

I am struggling to create a small horizontal space between the "Away Team" and "Baseball Field" divs in my code. I have tried adjusting padding, margins, and even adding decimal column offsets without any success. The desired spacing effect can be seen in ...

Having trouble implementing font css file in Reactjs

When working with Reactjs (Nextjs), every time I try to incorporate "css" into my project, I encounter the following error on my screen: Module not found: Can't resolve '../fonts/fontawesome-webfont.eot?v=4.7.0' How can I solve this issue? ...

Top method for transforming an HTML button into a hyperlink

Having some trouble with my code here. I currently have a Button that has an arrow hack, but I want it to display the link on the status bar instead. However, simply changing it to a href link doesn't work as expected. How can I convert this to a href ...

Tips for adjusting the time interval on an automatic slideshow when manual controls are in play

I'm having trouble with my slideshow. I want it to run automatically and also have manual controls, but there are some issues. When I try to manually control the slides, it takes me to the wrong slide and messes up the timing for the next few slides. ...

Display a div using Jquery when hovering over it with several classes

I want to create a hover effect where div2 fades in slowly when hovering over div1 within the same container. However, my jQuery code doesn't seem to be working as expected... $(".div").hover(function() { $(this).find(".div2").animate({ opac ...

What is the method for choosing outerHTML using Simple HTML DOM Parser?

Check out this code snippet: include('simple_html_dom.php'); // Creating a DOM from the specified URL $page = "http://indonesiax.co.id"; $html = new simple_html_dom(); $html->load_file($page); // Locating all images in the HTML $value = $htm ...

How can I embed an iframe in an Angular 4 application?

I'm facing an issue with my Angular 2 v4 application where I have the following code snippet: <iframe src="https://www.w3schools.com" style="width: 100%; height: 500px"></iframe> However, the iframe does not seem to work. I attempted to ...

Utilize the drag functionality seamlessly in the background of KineticJs

I have two layers with a large background and some content on top. I made the background draggable, but when dragged, it covers the content in the other layer. Is there a way to keep it in the background while dragging? I attempted to bind drag events wit ...