What effect does the addition of a border-top have on the position of the left column, causing it

Currently, I am working on creating a list with each list item having a bottom border of 1px solid. The list is then divided into 3 columns using column-count:3 CSS property. For instance, if there are 8 items, it should display 3 items in the first column, 3 in the second, and 2 in the third.

Everything works fine until I try to add a top border of 1px solid to the first element. Instead of displaying "3,3,2" as intended, it shows as "2,3,3".

I have avoided using grid because the number of items I want to show can vary.

I have created an example demonstrating this behavior:

.wrapper {
  column-count: 3;
}

.border-bottom {
  break-inside: avoid;
  border-bottom: 1px solid;
}

.border-top {
  border-top: 1px solid;
}

li {
  list-style: none;
}
<ul class="wrapper">
  <li class="border-bottom border-top">
    A
  </li>
  <li class="border-bottom">
    B
  </li>
   <li class="border-bottom">
    C
  </li>
   <li class="border-bottom">
    D
  </li>
   <li class="border-bottom">
    E
  </li>
   <li class="border-bottom">
    F
  </li>
   <li class="border-bottom">
    G
  </li>
     <li class="border-bottom">
    H
  </li>
</ul>

Loading the same code without Border-top:1px solid on the first <li>:

.wrapper {
  column-count: 3;
}

.border-bottom {
  break-inside: avoid;
  border-bottom: 1px solid;
}

li {
  list-style: none;
}
<ul class="wrapper">
  <li class="border-bottom">
    A
  </li>
  <li class="border-bottom">
    B
  </li>
   <li class="border-bottom">
    C
  </li>
   <li class="border-bottom">
    D
  </li>
   <li class="border-bottom">
    E
  </li>
   <li class="border-bottom">
    F
  </li>
   <li class="border-bottom">
    G
  </li>
     <li class="border-bottom">
    H
  </li>
</ul>

Answer №1

To ensure uniform size, I applied a subtle 1px transparent border.

Feel free to examine the code snippet below:

.wrapper {
  column-count: 3;
}

.border-bottom {
  break-inside: avoid;
  border-bottom: 1px solid;
}

.border-top {
  border-top: 1px solid;
}

li {
  list-style: none;
  border:1px solid transparent;
}
<ul class="wrapper">
  <li class="border-bottom border-top">
    A
  </li>
  <li class="border-bottom">
    B
  </li>
   <li class="border-bottom">
    C
  </li>
   <li class="border-bottom">
    D
  </li>
   <li class="border-bottom">
    E
  </li>
   <li class="border-bottom">
    F
  </li>
   <li class="border-bottom">
    G
  </li>
     <li class="border-bottom">
    H
  </li>
</ul>

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

What is the best way to incorporate link tags into text in AngularJS?

I'm struggling with making links within strings clickable in Angular. Can anyone provide guidance on how to accomplish this? One of the string examples from my JSON data is: "I’m hosting #AFF Catwalk Show @Bullring on 27th Sept with @BillieFaiers. ...

Is there a way to monitor the home button press event within a PhoneGap application?

Hello! I'm curious if there is a way to track when the Home button is pressed on both Android and IOS using phonegap phonegap build. I have looked into events for the home button press, but have only found information on back button events so far. ...

What is the best way to ensure the proper formatting of my initial form?

Hello, I am encountering some challenges with formatting my form. As a beginner in web coding, I apologize for what may seem like a simple issue - this is the first form I am attempting to code. My objective is as follows: On screens and tablets: have fo ...

Scaling Images using HTML and CSS

Hey there, I'm currently learning web development and running into a bit of trouble with creating responsive images. Can anyone give me some guidance on what changes I should make in the code below? Here's the HTML code: <div class="caro ...

Clickability issue with searchbar results caused by onBlur event

My searchbar functionality includes showing results in a dropdown list when the user searches. However, I am facing an issue with the onBlur event that changes the display of the list to none when the user clicks away from the search box. The problem aris ...

The CSS Media Query won't be effective for a precise 767

I have created an HTML file that changes the background color based on the browser width. When the width is 769, the background color is set to white. At 768, it changes to green. However, when the width is 767, I expected it to become red but it still rem ...

What is the process behind the creation of the class or id fields in HTML for Gmail and Quora? How are these

When using Gmail: <tr class="zA yO" id=":1t4"> While on Quora: <span id="ld_zpQ1Cb_27965"> What is the purpose behind this and what specific tool do they employ to achieve it? ...

javascript code for subtracting values in arrays

I am facing a scenario where I have 3 arrays of the same length. My requirement is to automatically subtract the values in the first two arrays without any user input. If the result of subtraction is negative, I need to identify the index of that array num ...

Is it possible to use speech recognition on browsers besides Chrome?

Is there a way to utilize a microphone with JavaScript or HTML5 without relying on Flash technology? I was able to achieve this in Chrome by using webkit-speech, but I am looking for solutions that will work in other browsers as well. Any suggestions wou ...

access the database information within the fullcalendar plugin

I've been exploring the calendar code on arshaw/fullcalendar and made some modifications, but I'm still unsure how to link JavaScript with a database. Here is the original code: $(document).ready(function() { var date = new Date(); var d = dat ...

The div is not completely encased by the fieldset

I have utilized fieldset to generate a titled border around a div. Here is the code snippet: <div class="form-group col-xs-12"> <fieldset class="field_set col-xs-12"> <legend style="font-weight:bold;font-size:20px"> ...

What is the best solution for adjusting spacing in justified text columns within bootstrap?

As I work on creating a div with two columns, I am facing an issue with maintaining justified alignment. It looks great with two divs using col-lg6- in Bootstrap, but when I switch to col-md-6 or col-sm-6, there are excessive spaces between words to keep t ...

Utilizing CSS3 webkit-transitions with multiple properties on a div element along with multiple webkit-transition-delays

Is there a way to make a div slide 200px to the right and then reduce its scale by half separately? I want it to slide first and then scale, but currently both transformations happen simultaneously. I tried using webkit-transition-delay to set different ...

I am looking to modify the background color of characters in a text box once the characters in a textarea exceed 150 characters

Currently, I am utilizing event.data to capture the text inputted into this particular HTML textbox. My intention is to change the background color to red based on that input. However, when using the style attribute on event.data, I encounter an error. It& ...

JQuery mishandles its left positioning

Here's the code snippet I've been working with: $(this).closest("p").after('<strong>' + arMess[iCurIndex] + '</strong>').next().animate({ top: $(this).offset().top - 57, left: -$(this).widt ...

Position a button to be aligned with the bottom of its container

My goal is to have the button positioned at the bottom of the red div, nested inside it. .grand-parent { display: flex; flex-direction: row; flex-wrap: wrap; height: 300px; background-color: green; } .pa ...

Steps for accessing CSS variables within a scoped style block in Vue with Buefy_integration

After diving into the Buefy documentation, I successfully personalized my color scheme and even crafted unique hues by applying the is-[colorName] as a class to HTML elements. <style lang="scss"> // Importing Bulma's core @import "~bulm ...

Firefox experiencing problem with retrieving video.duration in HTML5

I am currently working on developing a unique video player from scratch. <video preload="metadata" id="videoPlayer" style="width: 640px; height: 360px;"> </video> <script type="text/javascript"> var v = ""; var myV ...

Using Beautiful Soup to scrape the web and populate a Python list with the data

I have been working on learning how to web scrape with Python and BeautifulSoup, but I am running into an issue. When I try to add scraped items to a new list, only the final entry in the relevant tags is being displayed when I print the lists. How can I m ...

What is causing so many issues when this component is integrated? (the scope of issues will be detailed later on)

I have the following 3 components: news-feed.component user-activity-item.component user-activity-list.component Both user-activity components are located within a subdirectory of the news-feed component. Additionally, the user-activity-item is just a ...