Learn how to incorporate a vertical divider pipe into your website using Bootstrap

Hello, I'm having trouble adding a separator between nav-links that actually works. I tried adding the following code snippet:

nav-link:after {
content:"|";
}

But unfortunately, it's either not working at all or appearing on the left side of the nav-link.

Below is the code snippet I'm working with:

<nav class="navbar navbar-expand-md navbar-dark bg-color">
    <div class="navbar-brand header-title">Title</div> <!-- this is in the middle -->
    <div class="navbar-collapse collapse" id="collapsingNavbar">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="navbar-brand" href="#">
                    <img src="logo.png" />
                </a>
            </li>
        </ul>
        <!-- Here between nav-item I would like to add a pipe separator -->
        <ul class="navbar-nav ml-auto">
            <li class="nav-item nav-link mr-md-2">
                <div> some test some test</div>
            </li>
            <li class="nav-item nav-link mr-md-2">
                 <div> some test</div>
            </li>
            <li class="nav-item nav-icons">
                <a href="">
                    <span class="icon"> X </span>
                </a>
            </li>
            <li class="nav-item nav-icons">
                <a href="">
                    <span class="icon"> V </span>
                </a>
            </li>
        </ul>
    </div>
</nav>

Answer №1

Don't forget to include a period before the class in your CSS selector .nav-link and add position: absolute; to position it properly...

Check out the example on JSFiddle: https://jsfiddle.net/3ah58br4/7/

body{background-color:black!important;}
.nav-link:after {
    content: "|";
    position: absolute;
    top: 16px;
    margin-left: -10px;
}
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
    <nav class="navbar navbar-expand-sm navbar-dark bg-color">
        <div class="navbar-brand header-title">Title</div> <!-- this is in the middle -->
        <div class="navbar-collapse collapse" id="collapsingNavbar">
            <ul class="navbar-nav">
                <li class="nav-item active">
                    <a class="navbar-brand" href="#">
                        <img src="logo.png" />
                    </a>
                </li>
            </ul>
<!-- I want to add a pipe separator here between nav-items -->
            <ul class="navbar-nav ml-auto">
                <div class="nav-item nav-link mr-md-2">
                    <div> some test some test</div>
                </div>
                <div class="nav-item nav-link mr-md-2">
                     <div> some test</div>
                </div>
                <li class="nav-item nav-icons">
                    <a  href="">
                        <span class="icon"> X </span>
                    </a>
                </li>
                <li class="nav-item nav-icons">
                    <a  href="">
                        <span class="icon"> V </span>
                    </a>
                </li>
            </ul>
        </div>
    </nav>

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 there a way to retrieve the filename of a file uploaded using a shiny fileInput function?

This shiny app has a feature where users land on the 'Upload data' panel upon launching. To restrict access to the other two 'tabpanels', users must first upload both necessary files in the 'Upload data' tab. The condition for ...

What is causing the initial activation of the <button> within a form?

Within my <form>, I have included 2 submit buttons. The first button looks like this: <button class="regular" id="geocodesubmit" style="height:40px;">Set Location</button> The second button looks like this: <button type="submit" ...

Is there a way to keep the text animation going even when I'm not hovering over it with the cursor?

Is there a way to make text continue animating on the page even when the cursor is not placed on it? I understand the hover function, but how can I ensure the text keeps animating without interruption? $(document).ready(function () { $("#start&q ...

What's the best way to link up rotated div elements?

I'm currently attempting to connect rotated divs at a 45-degree angle, but I'm struggling to find the solution. Here is the current state of the page: Here is a screenshot of the page: https://i.sstatic.net/jqPYJ.png This is what I am aiming f ...

Tips for creating PrimeNG tables with columns that automatically adjust in size

Is there a way to automatically adjust and resize the columns in my PrimeNG table? I'm looking for a method to make this happen. Can you help me achieve this? ...

What is the correct way to specify an image path for a background URL?

Currently, I am setting a background image for the hr tag using the following code: <hr style="height:6px;background: url(http://ibrahimjabbari.com/english/images/hr-11.png) repeat-x 0 0;border: 0;margin:0px!important"> However, I have now saved th ...

Selenium can locate an element by its CSS selector that comes after a specific element

How can I locate the text "Interesting" which is the first occurrence of the class b after h1.important when using Selenium? <div class="a"> <div class="b">Not interesting</div> </div> <div class="title"> <h1 c ...

I possess a pair of UI tabs. Whenever a button located outside the tab is clicked, I am required to activate a distinct tab

As a beginner in Javascript, I recently encountered an issue with a UI tab element that contains two tabs. My goal is to create a button that, when clicked, will scroll up and activate the second tab. <style> .tab-container { overflow-x: ...

When attempting to view an .html file, SVG images may not appear on

I've encountered a common issue that I can't seem to solve. After creating a website using HTML, CSS, and JS, I uploaded it to the hosting server via FileZilla. Everything is working perfectly on the live site. However, when I downloaded the fi ...

Adding Bootstrap to a button is a simple process that can enhance the

I am new to using Bootstrap and have a question. I am currently working with CodeIgniter for my website, and I have added the Bootstrap files to the asset folder along with my CodeIgniter file. I want to incorporate Bootstrap CSS into the following code: ...

Ways to transform a 4-column CSS table into a 2-column layout for mobile and tablet viewing

For my latest project, I am faced with the challenge of creating a responsive table that transforms from 5 columns to 2 columns on smaller screens. While using complex jQuery is an option, I prefer a more semantic approach. Additionally, I need to incorpor ...

Acquiring administrative authorization upon user login with PHP

I have developed a registration form and a login form using PHP. However, whenever I run this code, it displays the message "invalid username" when the username is invalid, or it says "your account isn't approved by admin yet." Can anyone please guide ...

Applying CSS to an iframe using JavaScript: A Step-by-Step

I have an Iframe editor and I am trying to change some CSS inside the editor. However, when I attempt to apply the CSS, it does not affect the styles within the Iframe. <div id="editor" style="flex: 1 1 0%;"> <iframe src="https://editor.unlay ...

Is there a way to align the height of a standard column with the ng-include section to ensure a cohesive page display?

I have been working on my Angular app and have implemented ng-include to dynamically add content to a template within the page. The issue I'm facing is that this specific area ends up being longer than both the html and body elements where it resides. ...

Limit Content to be contained within a Bootstrap Container/Div

How can I shrink the content inside a container without distorting images? When the screen size decreases, all the images and content inside start to lose their alignment and sizes begin to change. I am aware that this may make the content harder to see. ...

Can CSS stylesheets be set up to automatically load based on the browser being used to access the website?

I am inquiring because I recently completed a beautiful homepage design and, after viewing the website on Chrome and Safari on OSX, I noticed that certain elements were broken when I opened it in Firefox. In addition, an issue I was experiencing with the ...

Utilizing props to define the background-color of the '&:hover' state

I'm adapting Material UI's Chip component to accept custom values for the colors prop, rather than being limited to "primary" and "secondary". Additionally, I want the chip to exhibit a hover effect when clicked, transitioning to a different colo ...

Can a CSS rule be prevented from inheriting?

Currently, I have implemented this CSS rule in the body selector: body { text-align:center } However, it seems like this rule is inheriting down to all other text elements on the page. Is there a way to prevent CSS from applying this rule to other elem ...

Ways to target other links exclusively during hover effect on a single link

I've been attempting to shrink all other links when one link is hovered over, but I'm only able to make the links after the hovered one shrink. .navlink { width: 100px; display:inline-block; background-color: red; } .navlink:hover~.navl ...

Utilizing a Recycled jQuery UI Themeroller Overlay

I'm looking to optimize css-loading bandwidth by reusing the overlay from jQuery UI for a specific section of my page. However, I'm encountering an issue where the overlay only covers a semi-transparent blackout of the entire page instead of just ...