Border edge for menu bar

I'm trying to create a stylish navigation bar with borders on the sides only, not the top. My goal is to achieve a design like this: |______________| so that my links are nicely boxed off. However, despite my efforts as a beginner, I can't seem to get it right without bordering every single link.

<nav>
    <div align="center">
    <div id="navigation">
    <ul>
       <li><a href="/">Home</a></li>
       <li><a href="/about">About</a></li>
       <li><a href="/products">Products</a></li>
       <li><a href="/news">News</a></li>
       <li><a href="/careers">Careers</a></li>
       <li><a href="contact us">Contact Us</a></li>
    </ul>
    </div><!--navigation-->
</nav>  

Here's the CSS code snippet:

nav { 
  width: 100%;
  margin:0 auto;     
}
nav ul li {
  width: 16.6%;
  float: left;
  border-bottom: 1px solid #A2A2A2;
  list-style-type: none;
  display: inline;
}

nav ul li a {
  display: block;
  width: 100%;
  text-align: center;
  padding-top: 8px;
  padding-right: 8px;
  padding-bottom: 8px;
  padding-left: 8px;
  color: #202020;
  font-family: "Myriad Pro Light";
  text-transform: uppercase;
  text-decoration: none;
  font-size: 12pt;
}
nav ul li a:hover {
  color:  #89ccca
}
nav ul{
  width: 80%;
  list-style: none;
  margin: 0;
  padding: 0;
 }

Answer №1

To achieve this effect, you can use the properties first-child and last-child in your CSS as shown below.

CSS

 nav ul li:first-child
 {
   border-left: 1px solid #A2A2A2; 
 }
 nav ul li:last-child
 {
   border-right: 1px solid #A2A2A2; 
 }

Check out the demo on FIDDLE

Answer №2

If you need assistance, I am here to help

Give this a try

    nav ul li {
width: 16.0%;
float: left;
border-bottom: 1px solid #A2A2A2;
border-right: 1px solid #A2A2A2;
list-style-type: none;
display: inline;
}

nav ul li:first-child{border-left: 1px solid #A2A2A2;}

Check out the example on this fiddle link

http://jsfiddle.net/zfdxko8h/

Answer №3

Consider adding this code snippet to your project:

#menu ul li:first-child { 
    border-left: 1px solid #A3A3A3;
}
#menu ul li:last-child { 
    border-right: 1px solid #A3A3A3;
}

Check out the example on JSFiddle

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

Using the ternary operator in PHP to output various statuses depending on an event's status in a SQL database

When the status is 1, it's referred to as an "Active Insurance Event," and when it's 2, it becomes a "Completed Insurance Event." if(!empty($ins_event)) { echo "<tr><td>&nbsp;<img src='/check-icon. ...

The content within React Material Tabs may move outside of the designated Container area, causing it to shift unexpectedly

I am trying to incorporate the Tabs Component into my React Website but I am facing an issue. The content intended for display in the red/blue Container is getting shifted to the bottom for the blue container. Upon investigation, it seems that the problem ...

The 'CSS border-radius targeting the last child element'

I am facing an issue with this code snippet: tr:first-child th:last-child { -webkit-border-top-left-radius: 15px; -moz-border-radius-topleft: 15px; border-top-left-radius: 15px; } tr:first-child th:first-child { -webkit-border-top-rig ...

The positioning of absolute CSS elements is causing alignment issues with their adjacent siblings

I am currently developing a customized Tooltip component using React that can be rendered to the right or below the target element. In my approach, the Tooltip component takes children as input and displays them. When these children are hovered over, the t ...

Embed the Nest API into your HTML5 code

My mobile HTML5 application includes a script in the index.html file. Nest.js (code below) Whenever I run my application, I encounter an error stating that Firebase is not defined. This is odd because the function seems simple: --> var dataRef = new ...

The page is displaying a horizontal scrolling bar when utilizing bootstrap framework

Currently, I am in the process of designing a webpage that utilizes Bootstrap. To structure my page layout, I am utilizing the grid system and the col-lg-x class. Specifically, I have split the page into two sections with the code below: <div class=&ap ...

Disabling CSS transitions and attempting to alter the style of an HTML element using JavaScript may not consistently work as expected

Currently, I am in the process of creating an animated effect for a website that involves moving two elements' positions over time and resetting them to their original position. Only one element is displayed at a time, and the animation should run smo ...

What is the best way to send an array element to a function?

In my PHP code, I am fetching data from a database and encoding it in JSON to be called by an AJAX request. while ($row = mysqli_fetch_assoc($empRecords)) { $data[] = array( "level"=>$whatTeam($row['level&a ...

The webpage is not displaying any results despite using .innerHTML with Ajax

I am currently developing a web application that displays query results using the Google Books API. While my code is functioning, I am encountering an issue where the .innerHTML method does not show any results on the HTML page. Below is the HTML code bein ...

Responsive Bootstrap 4 navigation bar featuring collapsible menu and various elements displayed on the right side

I have been struggling for quite some time to create a mobile menu using Bootstrap 4. My goal is to display the 3 brand names and the toggle button on the same row in the mobile menu. However, when I click the toggle button, the 3 brands end up below the c ...

Stop elements from overextending within their parent container

I am facing an issue with two divs that are wrapped inside a container div. The bottom div contains a dynamically filled table, which determines the overall width of all the divs. On the top div, I want to display several small red blocks that need to tak ...

JavaScript: Retrieve the following instance of a div element

Is it possible to create a single function that will only impact the next instance of a div with the class "hiddenDiv" in relation to the clicked link? For example: <p><a href="#" class="showDivLink">click to show/hide div</a></p> ...

Unable to display menu content text using jQuery

Currently experimenting with jQuery to create a dynamic submenu. The goal is to have a sub menu appear when the main menu is clicked, and then disappear when an item in the sub menu is selected, revealing additional information within a div. Unfortunately, ...

The HTML calculator is failing to show any output

My HTML calculator is facing issues with displaying input and results. I want to maintain the existing layout and design of the calculator while fixing this problem. The calculator was created using only HTML code to keep it simple for integration into an ...

I am interested in creating a user interface that enables me to choose and unchoose specific Test Cases, as well as run the selected tests (Test Developer)

I have a large number of test cases, approximately 100. In order to run my regression/smoke tests more efficiently, I am considering dividing them into groups and running the testng.xml file. However, what I really wish for is to create a user interface ...

Remove dynamically inserted list item using a button

I have dynamically created an unordered list (<ul>) that adds list items (<li>) when a button is clicked, along with a remove button. Initially, the default list item should not contain a remove button so I added it in the script. SCRIPT $(d ...

Is the Expand All / Collapse All feature malfunctioning when used with a tree table?

I have been working on implementing the Expand All/Collapse All feature for a nested tree table, but unfortunately, I am not achieving the desired output. I referred to a related question on this topic which can be found here. You can also view the code on ...

By default, the first table row is displayed when using table grouping in AngularJS

I am attempting to display only the first tr in the table and hide all other tr elements by default. I have tried using ng-show and ng-hide but it does not seem to be working as expected. This is not originally my plunker; I used it for reference on group ...

Segment will expand completely upon inserting a new division

Lately, I've been trying to simplify things by consolidating my JavaScript functions into one file instead of using multiple separate files. The idea was to merge all the functions together and wrap each one in its own function so that they can be eas ...

Detecting changes to DOM elements without using jQueryResponding to DOM element

Suppose I have the following HTML structure: <div id='content'></div> I want to receive an alert when there are height mutations on this element. I thought about using the MutationObserver class for this, but I encountered a specifi ...