Website Navigation Bar Template

Can someone assist me, please?

I've been working on this project for a few hours now. As a beginner in html and css, I've been doing extensive research but haven't found a solution that works perfectly for my needs. The only thing that somewhat worked for me was following this example: http://codepen.io/wolfcry911/pen/HyLdg.

Here's what I'm trying to achieve:

  • I want to create a navigation bar with 4 links (Home, About Me, Contact, Resume) along with a logo in the center that adjusts well to various screen sizes including tablets, laptops, and smartphones. I tried using an unordered list with the logo as the third item, but it appeared messy and positioning the logo at the center of the screen was challenging due to different text lengths. I also attempted using the logo as a background image, but aligning it in the middle of the page proved difficult, and the text didn't adjust properly around the logo. When I looked at the provided link, about 50% of the CSS made sense to me. However, when I tried making tweaks, I struggled with centering the text within the navigation and placing the logo correctly. Here is the code I have so far:

body {
  background: #f5f5f5;
  font-family: arial;
  font-size: 11px;
  margin: 0;
}
#header {
  height: 56px;
  position: relative;
  margin: auto;
  background: #fff;
  box-shadow: 0px 2px 2px #ebebeb;
  text-align: center;
  padding: 20px 10px;
}
#header ul {
  margin: 0 auto;
  width: 800px;
  padding: 0;
  list-style: none;
}
#header ul li {
  float: left;
  width: 97px;
}
#header ul li:nth-of-type(4) {
  margin-left: 217px;
}
#header ul li a {
  text-transform: uppercase;
  text-decoration: none;
  display: block;
  text-align: center;
  padding: 12px 0 0 0;
  height: 28px;
}
#header ul li a:hover {
  background: rgb(235, 200, 35);
}
.logo {
  position: absolute;
  left: 50%;
  margin: -48px 0 0 -108px;
  background: url(img/logo.jpg) 50% 0 no-repeat;
  background-size: 125px 56px;
  width: 125px;
  height: 56px;
  top: 20px;
}
@media screen and (max-width: 800px) {
  .logo {
    bottom: 100%;
  }
  #header ul li:nth-of-type(4) {
    margin-left: 0;
  }
  #header ul {
    width: 600px;
    position: relative;
  }
}
<html>

<head>
  <title>Template</title>

  <link rel="stylesheet" href="navigation.css">


</head>

<body>

  <div id="header">
    <a class="logo" href="index.html">
      <img src="img/logo.jpg" alt="Michigan State" width="215" height="140" />
    </a>
    <ul>
      <li><a href="index.html">Home</a>
      </li>
      <li><a href="index.html">About Me</a>
      </li>
      <li><a href="index.html">Contact</a>
      </li>
      <li><a href="index.html">Resume</a>
      </li>
    </ul>
  </div>
</body>

</html>

I managed to grasp roughly 50% of the CSS code. If anyone could provide some insight into how the ul, li, logo, and @media formatting work together, I would greatly appreciate it.

Thank you in advance for your help.

Answer №1

ul represents an unordered list that displays bullet points instead of numbers like with an ordered list, ol. The list-style is set to none to hide the bullet points and each element has a fixed width of 97px.

The CSS selector ul li:nth-of-type(4), introduced in CSS3, targets the fourth item in the unordered list to apply specific styles. Learn more about it here: http://css-tricks.com/almanac/selectors/n/nth-of-type/

ul li a:hover defines the styles that change when a user hovers over an item in the unordered list.

.logo is a class used for styling elements such as positioning, size, background images, and other formatting properties.

The @media rule detects the browser's size and applies different styles based on that size. More information can be found at: http://css-tricks.com/css-media-queries/

For valuable resources and insights into CSS, I recommend visiting css-tricks.com. It has been incredibly helpful to me in staying informed about new techniques and features in CSS3.

Answer №2

Let me provide a concise overview of the current situation, but it is highly recommended to delve deeper into CSS fundamentals. There are numerous beginner-friendly tutorials available online, such as those on Codecademy.

#header ul {
   margin: 0 auto; /* Utilized for centering the UL element. */
   width: 800px; 
   padding: 0;
   list-style: none; /* Eliminates list bullets */
}

#header ul li {
   float: left; /* Floats the LI elements, arranging them horizontally instead of stacking vertically*/
   width: 97px;
}

#header ul li:nth-of-type(4) {
    margin-left: 217px; /* Applies a left-margin to the fourth LI item (Resume). This prevents overlap with the logo image and adjusts its position based on image width. */
}

.logo {
position: absolute; /* Removes image from document flow, enabling placement anywhere on the page relative to parent elements with position:relative. In this case, #header */

left: 50%;/* Aligns left edge of image at 50% mark from the left */
margin: -48px 0 0 -108px; /* Negative top/bottom margin centers the image vertically and horizontally. */
width: 125px;
height: 56px;
top: 20px; /* Positions image 20px from the top */
}

The media queries delineate menu behavior under window widths less than 800px.

Answer №3

Behold, a basic markup/layout example for your viewing pleasure. (Just so you know, it's extremely simplistic). This layout utilizes positioning techniques and offers the flexibility to easily tweak various elements.

.header {
  margin-top: 50px;
  height: 40px;
  width: 100%;
  background-color: blue;
  position: relative;
  border-bottom: 5px solid gold;
  border-top: 5px solid gold;
}
.link {
  position: absolute;
  width: 20%;
  height: 100%;
  background: red;
}
.link2 {
  left: 20%;
  background: green;
}
.logo {
  left: 40%;
  background: orange;
}
.link3 {
  left: 60%;
  background: purple;
}
.link4 {
  left: 80%;
  background: pink;
}

@media screen and (max-width: 800px) {
  .link {
  position: absolute;
  width: 25%;
  height: 100%;
  background: red;
}
.link2 {
  left: 25%;
  background: green;
}
.logo {
  display:none;
}
.link3 {
  left: 50%;
  background: purple;
}
.link4 {
  left: 75%;
  background: pink;
}
}
<div class="header">
  <div class="link link1">Link1</div>
  <div class="link link2">Link2</div>
  <div class="link logo">logo</div>
  <div class="link link3">Link3</div>
  <div class="link link4">Link4</div>
</div>

You can utilize media queries to adjust styling based on different screen sizes. For instance, if the screen width shrinks below 800px, the 'logo' div will vanish, but as it expands, the logo div will reappear. (For optimal results, view in full screen mode to witness this effect)

It's just a simple setup, but I believe there's room for customization with this template.

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

Is it feasible to generate a realistic arrow using CSS and then rotate it?

Can a fully functional arrow be created using CSS alone? Here is the method I used to create just the arrowhead: http://jsfiddle.net/2fsoz6ye/ #demo:after { content: ' '; height: 0; position: absolute; width: 0; border: 10p ...

Substituting HTML checkboxes with highlighted images for consistent display across different web browsers

I am looking to transform a list of HTML checkboxes into clickable images for the user to select or deselect. My goal is to create a similar functionality as shown in this video using just CSS if possible. I have successfully implemented it in Chrome wit ...

What are the steps to view my HTML webpage on a smartphone?

Recently, I successfully created an HTML webpage with CSS and JS that looks and functions perfectly on my PC. However, when attempting to access it on my phone, I encountered some issues. Despite transferring all the necessary files to my phone, only the ...

Hover state remains persistent even after modal window is activated in outouchend

One of the buttons on my website has a hover effect that changes its opacity. This button is used to share information on Facebook. It's a simple feature to implement. Here is the CSS code: .social_vk, .social_fb { height: 38px; obj ...

Unable to connect the CSS file from the JSP during a Cross Domain request in Internet Explorer 9

I have created a GWTP web application and am making AJAX calls to a JSP page on a different domain (Cross domain) from the GWT client side. Most of the time, the CSS files are linking correctly and working fine. However, occasionally they do not link prop ...

Displaying a value in a React component using material-ui's TextField

Can anyone help me with printing the email a user enters into the textfield within the Dialog when a button is clicked? I have been struggling to achieve this due to my function's structure. Any guidance would be greatly appreciated. export default fu ...

Streaming Ogg audio from a PHP file is not possible to seek in Chrome

As I work on creating a basic audio player using the HTML5 audio element, the files being served are in .ogg format coming from another system as a binary string through an API. They are then processed by a simple PHP handler that includes some security ch ...

Accordion border in Bootstrap should be applied to all items except the first one

I am currently implementing Bootstrap accordions in an Angular application and I am facing an issue where I want to have a colored border all around each accordion panel. The problem is that by default, Bootstrap removes the top border from all accordions ...

Set the datepicker with the window positioned to the right side

In my current project, I am utilizing Angular 13, Bootstrap 5, and ngx-bootstrap-fix-datepicker version 5. "bootstrap": "^5.1.3", "ngx-bootstrap": "^8.0.0", "ngx-bootstrap-fix-datepicker": "^5.6.8" ...

Having trouble with the jQuery each function's functionality

I am creating circular counters for surveys by generating a counter for each answer option. Currently, I am utilizing this "plugin": Issue: The problem lies in the plugin not fetching the text value from the <div> element and failing to draw coun ...

Transforming an Ionic mobile application into a web-based application: A step-by

I currently have a mobile app developed using Ionic. I now require a desktop-friendly website version of the app to cater to users who wish to access it from their computers. Can anyone point me to any resources or documentation that demonstrate that th ...

What is the best way to switch the visibility of a div on click from another div?

My goal is to make a div toggle visible or hidden when another div is clicked. The only connection between the two divs is that they are both nested within the same parent div. There's a DIV element with the class of "comment" which contains a DIV ele ...

Tips for ensuring a static html element remains visible at the bottom of the screen even when the soft keyboard is opened in iOS Safari

Within a webpage, there is an input field and a fixed div positioned at the bottom of the window using CSS properties such as position:fixed; and bottom:0;. To better illustrate this setup, I have created a Codepen demo which can be viewed here: https://c ...

What are some creative ways to design the selected tab?

In my Vue parent component, I have multiple child components. There are several elements that toggle between components by updating the current data. The issue is that I am unsure how to indicate which tab is currently active. I've tried various li ...

Establishing the initial value of a <select> element

My webpage features a table that displays the details of past order history, with columns for Order, Date, and Review. For the Review column, I am seeking to add a select dropdown with various options. Upon the initial page load, I would like the select d ...

Utilize JavaScript to randomly choose images as background tiles in HTML

Currently, I am in the process of developing a game using HTML/CSS/JavaScript. My background is currently set to a single image (100px / 100px) being repeated vertically and horizontally to tile across the entire page body; CSS: body { background-ima ...

Variations between <div/> and <div></div>

When using Ajax to load two divs, I discovered an interesting difference in the way they are written. If I write them like this: <div id="informCandidacyId"/> <div id="idDivFiles"/> Although both divs are being loaded, only one view is added ...

Automatically altering variable without manual intervention

Hey there, I'm encountering a strange issue with the form below echo "<td class='contact-delete'> <form method='post' action='update_record.php'>"; echo "<button type='submit' value='" . $ ...

CSS techniques for aligning content

I am currently working on designing a website template, and I have encountered an issue with positioning three individual columns that contain blocks of content. My objective is to have the first block of content in each column start at the top of their re ...

Struggling to get the nth-child selector to function properly in IE8

Looking for a solution to alternate colors in a table? Here's what I tried: #grid tr:nth-child(odd) { background-color:#eee; } #grid tr:nth-child(even) { background-color:#fff; } Unfortunately, this works in Firefox but not in IE8. After some i ...