Increase the padding and add a border to separate the list items in bootstrap 4

I have a header with some links and I want to create space and add a border between them.

I attempted using ::before pseudo-content, but it's not displaying the content where I intended.

.header_links_ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.header_links_ul li a {
  color: #000;
  font-size: 12px;
  display: block;
}

@media (min-width:992px) {
  .header_links_ul li+li::before {
    position: absolute;
    top: 50%;
    left: 0;
    width: 1px;
    height: 8px;
    margin-top: -4px;
    background: #ff0000;
    content: '';
  }
}
<div class="row">
  <div class="col-md-6">
    <ul class="header_links_ul header_links_ul_left d-flex justify-content-center justify-content-md-start">
      <li><a href="#">Vásárlási információk</a></li>
      <li><a href="#">Szállítás</a></li>
      <li><a href="#">Kapcsolat</a></li>
    </ul>
  </div>
  <div class="col-md-6">
    <ul class="header_links_ul header_links_ul_right d-flex justify-content-center justify-content-md-end">
      <li><a href="#">Regisztráció</a></li>
      <li><a href="#">Bejelentkezés</a></li>
    </ul>
  </div>
  <div class="clearfix"></div>
</div>

The current result I have can be seen on this photo, along with what I am aiming for: https://i.sstatic.net/iUk6k.jpg

Answer №1

Feel free to utilize the provided code snippet. You can access the accompanying LINK

.header_links_ul li{
  padding: 0px 20px;
  border-right:1px solid #000;
}
.header_links_ul li:last-child{
  padding: 0px 20px;
  border-right:none;
}

Answer №2

Hello @max777, I recommend incorporating the following CSS into your code for improved styling:

<style>
  .header_links_ul li {
    border-right: 1px solid green;
    margin-left: 2%;
  }
</style>

Answer №3

To properly space out the li tags, you will need to add position:relative along with some padding and margin. Here's a suggestion:

.header_links_ul li+li {
 position: relative;
 padding-left: 20px;
 margin-left: 20px;
}

The ::before pseudo elements are placed absolutely, so the top and left values specified will be relative to the next parent element with relative or absolute positioning. If there is no such parent, it will default all the way back up to the element itself, meaning it will be positioned relative to the page itself (which seems to be the issue in this case).

For more information and additional reading, check out: https://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/

Answer №4

Creating a header using this method is not recommended!

Instead, consider using the bootstrap nav bar by referencing the links below:

Bootstrap Navbar Documentation W3Schools Bootstrap Navbar Tutorial

To style your navigation items, apply position:relative to the li element as shown below

.header_links_ul li {
  position: relative;
 }

If you require further assistance, please share a CodePen or fiddle of your code for better understanding.

Answer №5

.header_links_ul {
          list-style: none;
          margin: 0;
          padding: 0;
        }

        .header_links_ul li a {
          color: #000;
          font-size: 12px;
          display: block;
        }
        .header_links_ul li{
        line-height:15px
        }

        @media (min-width:992px) {
          .header_links_ul li+li::before {
            position: absolute;
            top: 50%;
            left: 0;
            width: 1px;
            height: 8px;
            margin-top: -4px;
            background: #ff0000;
            content: '';
          }
        }
<div class="row">
          <div class="col-md-6">
            <ul class="header_links_ul header_links_ul_left d-flex justify-content-center justify-content-md-start">
              <li><a href="#">Shopping Information</a></li>
              <li><a href="#">Shipping</a></li>
              <li><a href="#">Contact Us</a></li>
            </ul>
          </div>
          <div class="col-md-6">
            <ul class="header_links_ul header_links_ul_right d-flex justify-content-center justify-content-md-end">
              <li><a href="#">Registration</a></li>
              <li><a href="#">Login</a></li>
            </ul>
          </div>
          <div class="clearfix"></div>
        </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

IE11 React application cannot recognize the <main> tag

When using my React application, I encountered the following error message in the dev console while using IE11: Warning: The tag <main> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase let ...

Achieving compatibility with IE7 for utilizing "before:" and "after:" pseudo-elements along with the "box-sizing:border

My website is constructed with twitter bootstrap 3 and functions perfectly on all browsers except for IE7. IE7 seems unable to interpret pseudo classes like before:, after:, and box-sizing: border-box. Is there a solution to make IE7 understand this code ...

What is the best way to arrange multiple elements on the second row within a div?

As I attempt to utilize CSS for positioning elements within a div, my challenge lies in the limitation of only being able to use classes/ids due to the fact that the div and its content are generated from a third-party plug-in (datatables). This restricts ...

Tap to smoothly scroll through each block using the animate() function

ul { padding: 0; margin: 0; height: 180px; overflow: auto; } li { height: 50px; background: pink; list-style: none; margin-bottom: 10px; height: 50px; ...

concealing additional content within a DIV using ellipsis

Looking to conceal additional text within my DIV element with ellipsis (...) at the end Currently using: <div style="width:200px; height:2em; line-height:2em; overflow:hidden;" id="box"> this is text this is text this is text this is text </div ...

What are the steps to creating a fading effect for an item that appears as it enters the field of view and disappears as it exits the field of view?

Implementing a fade-in effect for a button as the user scrolls down and the button comes into view, along with a fade-out effect as the user continues scrolling down and the button goes out of view. var fadeInButton = $('#fadeInButton'); ...

It is not possible to attach separate links to images in a JavaScript slider

I am struggling with linking individual images in a JavaScript slider for a client's website. The slider is fully functional and works well, but I can't seem to figure out how to link the images properly. When I remove items from <--ul class= ...

The responsive design of Bootstrap NavBar seems to be malfunctioning when viewed on an iPhone device

Having an issue in Bootstrap Studio that I can't seem to resolve. I've seen recommendations to add the following meta tag to the <head> section: meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0", bu ...

Struggling with setting up a search bar for infinite scrolling content

After dedicating a significant amount of time to solving the puzzle of integrating infinite scroll with a search bar in Angular, I encountered an issue. I am currently using Angular 9 and ngx-infinite-scroll for achieving infinity scrolling functionality. ...

Is there a way to make the hoverzoom effect only apply to a specific object instead of all objects?

I'm currently troubleshooting my code in order to implement a hover effect on Mui <cards> when a user hovers over the object. I have managed to make it work partially, but the issue is that the effect gets applied to all objects instead of just ...

Transform preexisting Vue UI library measurements into pixels

I was curious about converting all existing units (em / rem) to pixels. How can I easily convert the entire output units to px? Are there any tricks or methods available? Currently, I am utilizing Vuesax UI to create a plugin for various websites and temp ...

Utilize grids to ensure consistency in the width of every <li> element across the browser

Is there a way to make the ul element span the entire width of the webpage regardless of window size? http://jsfiddle.net/32hp1w5p/ ul { grid-column: 1/13; list-style-type: none; display: table; margin: 0 auto; } li { float: left; border: ...

Any tips on creating a website with a gradient background that moves along with the window as you scroll?

Can anyone help me figure out how to achieve this? I'm trying to create a similar effect to the one on the fireship website, but I'm having trouble replicating it. Appreciate any guidance. Thanks! ...

Ensuring the Angular Material bottom sheet (popover) stays attached to the button

Recently, I've been working on an Angular project where I successfully integrated a bottom sheet from Angular Material. However, I encountered an issue when trying to make the opened popup sticky to the bottom and responsive to its position, but unfor ...

Parent window login portal

I have just started learning how to program web applications, so I am not familiar with all the technical terms yet. I want to create a login window that behaves like this: When a user clicks on the Login button, a window should pop up on the same page t ...

In Chrome, the computed style of background-position is returned as 0% 0%

Let's say I have an element and I am interested in finding out its background-position: To achieve this, I use the following code snippet: window.getComputedStyle(element).getPropertyValue('background-position') If the value of background ...

I'm experimenting with crafting a new color scheme using MUI, which will dynamically alter the background color of my card based on the API

I am attempting to create a function that will change the colors based on the type of Pokemon. However, I'm not sure how to go about it. Any suggestions or ideas!? Check out where I'm brainstorming this logic [This is where the color palette sh ...

The hover functionality for the cursor's pointer is malfunctioning

I currently have two div elements in my HTML code: <div id="hm-sp-lenovo-wr"> ....... <div id="hm-sp-motorola-wr"> ....... In my stylesheet, I have defined the following CSS rules: #hm-sp-lenovo-wr:hover { cursor: pointer } #hm-sp-motorol ...

Can HTML Elements be used within a Contenteditable section?

I am facing an issue with a contenteditable tag on my website. Users are unable to type code into the tag and have it display as an actual element instead of just text. Is there a way for users to input full, working HTML elements in a contenteditable box ...

transform the input button into an anchor tag

How can I create a hyperlink for the code below: echo "<td><input type='button' class='btn btn-link text-dark' value='{$val_str}' onclick='redirect(\"{$value}\")'></td>" ...