Putting a | in the navigation bar

Could use some assistance here as I'm struggling to add a | between 'About Us' and 'Login' in my code. Any tips on how to achieve this? I've checked other posts but can't seem to apply it correctly to my specific lines of code.

HTML

color:rgba(152,226,80,0.6); font-family: 'Bahnschrift Regular';" title="This Header is rendered by /app/_layout/site-header/site-header.component.html">
   <div id="logo">
     <a href="/index.html">
     </a>
 </div>
      <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a class="nav-link" routerLink="/" style="color:White;" >Home</a>
          </li>
          <li class="nav-item">            
            <div class="dropdown">
           <li class="dropbtn">Services</li>
           <div class="dropdown-content">
            <a href="/carmaintenance" style="text-align:center">Car Maintenance
              ______________________
            </a>
            <a href="/gogreenseminars" style="text-align:center">Go Green Seminars
              ______________________
            </a>
            <a href="/microgridresources" style="text-align:center">Microgrid Resources
              ______________________
            </a>
            <a href="/gardeningtogether" style="text-align:center">Gardening Together
              ______________________
            </a>
            <a href="/volunteering" style="text-align:center">Volunteering and Activism
              ______________________
            </a>
            <a href="/recyclingefforts" style="text-align:center">Recycling Efforts
              ______________________
            </a>            
            <a href="/inhousevegancafe" style="text-align:center;">In-House Vegan Cafe              
            </a>    

            </div>
            </div>            
          <li class="nav-item">
            <a class="nav-link" routerLink="/dashboard"style="color:White;">Membership Plans</a>
          </li>          
          <li class="nav-item">
            <a class="nav-link" routerLink="/about" style="color:White;">About Us</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" routerLink="/login"style="color:White">Login</a>
          </li>
        </ul>
      </div>
    </nav>

CSS

/* Position the navbar container inside the image */
/*.container {
  position: absolute;
  margin: 20px;
  width: auto;
  top:3%;
  left:1%;
}
*/

/* The navbar */
.topnav {
  overflow: hidden;
  background-color: rgba(152,226,80,0.6);

}

/* Navbar links */
.topnav a {
  float: right;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 16px;


}
.nav-link 
{
  /*background-color:;*/
  font-weight: bolder;
  color: white;  
  font-size: 125%;
  align-items:center;
  text-align:center;
  float: left;
  display: block;   
  margin-left: 65px;
  margin-right:5px;

}        
.navbar {
  float: left;
  width:66%;
  height:8%;
  opacity:1;
  border-radius:15px 0px 0px 15px;
  padding-left: 0%;
  top:3%;
  left:1%;  

}

.topnav a:hover {
  background-color: #ddd;
  color: black;  
}
/* Dropdown Button */
.dropbtn {
  background-color: rgba(152,226,80,0.0);
  color: white;
  padding: 8px;
  font-size: 125%;
  border: none;
  font-weight:bolder;
  margin-left:65px;
  margin-right:5px;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
  position: relative;
  display: inline-block;  
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute; 
  min-width: 90px;
  box-shadow: 0px 0px 0px 0px rgba(152,226,80,0.0);
  z-index: 1; 
  text-align:center;
  padding-left:20px;
  padding-top:13px;
}

/* Links inside the dropdown */
.dropdown-content a {
  color: #FFFFFF;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  background-color : rgba(152,226,80,0.6);
  font-weight:bolder;
  margin-top: -10px;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
}

/* Change color of dropdown links on hover */
//.dropdown-content a:hover {background-color: #ddd;}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}

/* Change the background color of the dropdown button when the dropdown content is shown */
//.dropdown:hover .dropbtn {background-color: #3e8e41;}

@font-face {
    font-family: 'Bahnschrift Regular';
    font-style: normal;
    font-weight:bolder;
    src: local('Bahnschrift Regular'), url('BAHNSCHRIFT 1.woff') format('woff');
}

Appreciate any help or guidance you can provide. Thank you in advance!

Answer №1

To achieve this effect, you have a couple of options. One way is to apply a border-left to the last li element using the :last-child pseudo-element, or you can insert content before each li using the :before pseudo-element. Keep in mind that when adding pseudo-elements, they are inserted as the first child of the selected element, which may impact other styling considerations.

EDIT - As mentioned earlier, only li elements should be direct children of a ul element. To ensure proper HTML structure, make sure any additional elements like divs or dropdowns are nested within an li instead of directly under the ul parent.

Credit to @dale landry for providing the initial code framework below :)

.flex-box {
  display: flex;
}

li, .nav-item {
  text-decoration: none;
  list-style-type: none;
  padding: 2px 12px;
  color:black;
}


.nav-item:last-child {
  border-left: solid 1px black;
}
<div>
  <ul class="flex-box">
    <li class="nav-item">
      <a class="nav-link" routerLink="/">Home</a>
    </li>
    <li class="nav-item">
       <a class="nav-link" routerLink="/services">Services</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" routerLink="/about">About Us</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" routerLink="/login">Login</a>
    </li>
  </ul>
</div>

You can also achieve the desired divider effect by using a :before pseudo-element:

.nav-item:last-child {
  position: relative
}
.nav-item:last-child:before {
  position: absolute;
  content: "|";
  left: 0;
  color: #d4d4d4;
}

.flex-box {
  display: flex;
}

li, .nav-item {
  text-decoration: none;
  list-style-type: none;
  padding: 2px 12px;
  color:black;
  position: relative
}

.nav-item:last-child:before {
  position: absolute;
  content: "|";
  left: 0;
  color: black;
}
<div>
  <ul class="flex-box">
    <li class="nav-item">
      <a class="nav-link" routerLink="/">Home</a>
    </li>
    <li class="nav-item">
       <a class="nav-link" routerLink="/services">Services</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" routerLink="/about">About Us</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" routerLink="/login">Login</a>
    </li>
  </ul>
</div>

Another approach is to add an element that acts as a divider and spans the full height of the li element:

.nav-item:last-child {
  position: relative
}
.nav-item:last-child:before {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0; 
  width: 1px;
  background-color: #d4d4d4;
}

If you prefer not to rely on :last-child, you can assign a specific class to the last li item for the same effect:

      <li class="nav-item login-link">
        <a class="nav-link" routerLink="/login" style="color:white">Login</a>
      </li>

      //css
      .login-link {
         border-left: solid 1px #d4d4d4;
      }

To create dividers between every li except the last one, you can use the adjacent sibling combinator "+" in CSS:

.nav-item + .nav-item {
  border-left: solid 1px #d4d4d4;
}

Alternatively, you can achieve this using a :before pseudo-element:

.nav-item {
  position: relative
}
.nav-item + .nav-item:before {
  position: absolute;
  content: "|";
  left: 0;
  color: #d4d4d4;
}

Answer №2

Have you considered including a span within your li element for the About Us section? Take a look at the example below:


<li class="nav-item">
            <a class="nav-link" routerLink="/about" style="color:White;">About Us</a>
<span>|</span>
          </li>

Answer №3

To create a semantically valid code for your navigation bar, simply include a bar wrapped in a list item tag within your nav section. Check out the example below:

.flex-box {
  display: flex;
}

li,
.nav-item {
  text-decoration: none;
  list-style-type: none;
  padding: 2px 4px;
  color: black;
}

.bar {
  font-weight: bold;
}
<div>
  <ul class="flex-box">
    <li class="nav-item">
      <a class="nav-link" routerLink="/">Home</a>
    </li>
    <li class="nav-item">
      <li class="dropbtn">Services</li>
      <li class="nav-item">
        <a class="nav-link" routerLink="/about">About Us</a>
      </li>
      <li class="bar">|</li>
      <li class="nav-item">
        <a class="nav-link" routerLink="/login">Login</a>
      </li>
  </ul>

</div>

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

Issue with disabled state in radio button container not functioning

I am facing an issue with a radio button div that I need to disable when the condition yAxisEditorCtrl.forceCombinedYAxis is true. Here is the original code: <div class="y-axis-editor"> <div class="vis-config-option display-size-normal form- ...

Arrange the image in a way that flows smoothly with the text

I want to achieve the effect of having a picture of a Pen positioned behind the text "Create" on the left side. It looks good at full size, but the positioning gets messed up when the screen size is adjusted. How can I make it responsive so that the image ...

Trouble Ensuring First Radio Button Is Checked in Angular 6

I'm working on setting the first radio button in a group to be checked by default. Within my application, I have 6 tabs each containing a set of scales that need to be displayed as radio buttons. The goal is to have the first button in each tab check ...

Issues with scrollspy functionality in Bootstrap 4 beta

Although similar to this question, I'm facing a different issue. The solution provided there involves manually writing JavaScript code to highlight active links on scroll, while I am trying to use the scrollspy plugin. I've reviewed various othe ...

Is there a way to automatically scroll to the last dynamically added div?

Within the chat.html file, I have included a div tag and implemented a script that dynamically adds rows to the div when a button is clicked. In another file named list.html, I have inserted an iframe tag with the src attribute pointing to chat.html. Howev ...

The overflow:hidden property does not completely conceal the parent div when it has a border-radius applied

I've noticed some residual overflow in my simple layout that becomes quite apparent when setting a border radius. The expected behavior is for the white div class='inner' to fully cover the red div class='outer'. However, there see ...

Navigate a Bootstrap 4 drop-down menu by scrolling rather than having it drop down

I recently designed a Navbar with dropdown menus, but I have encountered an issue where the dropdown menus do not overlay the content as intended. Instead, they create a scroll-down menu and display the contents within it. I would appreciate it if someone ...

Combining Angular with Google Maps

Currently, I am utilizing angular-googlemaps(agm) and it has been functioning well for me so far. However, I have a requirement to search for an address using latitude and longitude. After some research, I discovered a partial solution here. The only issu ...

Achieving precise field alignment with React.js and Bootstrap

I am currently in the process of creating a reporting website that will feature multiple graphs as well as a live Twitter feed. The current layout of the website can be previewed here: https://i.sstatic.net/ZLK3x.png Unfortunately, due to the placement of ...

Is it possible to create a crossfade effect using angular animate and ngFor in my project?

I am trying to initiate an animation whenever I update the collection I provide in *ngFor: //JS state : string = 'a'; colors = { a: ['red','blue','green','yellow'], b: ['orange'] } public o ...

How can the navbar class be altered when there is a change in routes?

My navbar class is set to change based on scroll position Script <script> $(window).scroll(function () { if ($("#main-navbar").offset().top > 100) { $("#main-navbar").addClass("navbar-shrink"); } else { $(" ...

Display or conceal elements based on the screen size using Bootstrap 3 classes

While this may seem straightforward for some, the reality is quite different. I have two images that need to be displayed based on screen size. In my HTML code, I used classes like hidden-md, hidden-sm, and hidden-xs assuming they would only show on larg ...

Align columns responsively with Bootstrap and center overlay image

Experiencing issues with aligning responsive divs using Bootstrap. Here is the code in question: <div class="container-fluid"> <div class="row"> <div class="col-xl-5"> <img src=&quo ...

CSS container design with customized paragraph formatting

How can I format a CSS container for quotes that span multiple paragraphs? Here is an example of the code: #quotebox { width: 80%; border-top: 1px solid #242729; padding-left: 10%; padding-bottom: 2%; } I am currently using this CSS container for quotes, ...

Having trouble sending data from AJAX to PHP

My goal is to implement a "load more" feature in my web app that automatically calls a PHP file to load additional products as soon as the page is fully loaded. In order to achieve this, I am using AJAX to call the PHP file: $(document).ready(function() { ...

unable to modify the attributes of an object in Angular

I've been tasked with modifying an existing Angular project that includes a component where I have the following variable: public testRunDetails: ITestRunDetails[] = []; The variable testRunDetails is of type ITestRunDetails, which is defined as: exp ...

I am interested in incorporating a personalized class into the Kendo UI for Angular TabStrip

<kendo-tabstrip (tabSelect)="onTabSelect($event)"> <kendo-tabstrip-tab title="Paris" [selected]="true"> <ng-template kendoTabContent> <div class="content"> ...

When adjusting to mobile dimensions, the responsive website design struggles to center the navbar properly

I am currently developing my senior year portfolio website and I am struggling to center the navbar (Work About Contact) when it is in mobile mode. My goal is for it to be positioned directly below the logo, perfectly centered, but so far nothing I have tr ...

Mastering intricate CSS customization

The situation I have a specific issue with CSS that I need help with. I am currently working on customizing the user interface of our Zimbra deployment, which uses jetty (a platform I am not very familiar with). I have come across two files that seem to b ...

Navbar toggler in Bootstrap 4 is invisible

I'm taking a shot at Bootstrap 4 beta for the first time. The website for my charity group currently runs on BS3 and uses a fixed top navbar with custom CSS. However, I'm facing an issue when viewing the site on smaller screens where the toggle i ...