Creating unique borders in a Bootstrap 4 table

Currently in the process of developing a web shop cart (utilizing Bootstrap 4.1) and faced with the task of creating a list of items in the cart along with their quantities, prices, and total prices... To tackle this, I opted to use a table structure but encountered an issue:

My goal was to design a table that resembles this desired layout: https://i.sstatic.net/Z6mKm.jpg

However, my initial attempt resulted in a table that looks more like this..: https://i.sstatic.net/Ik02I.jpg

Calling out to you, fellow internet dwellers, for advice on how can I achieve the table borders surrounding the "quantity" to mirror the appearance seen in the first image??? And also seeking guidance on how to combine the final cells to present the total price (23,97 €) centered within the table as depicted in the initial picture??

P.S. Wondering whether utilizing a table is indeed the correct choice or should I have considered a different element such as an or ?

Thank you in advance, intergalactic friends :)

Here's My Code: HTML:

<div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
        <th scope="col">&nbsp;</th>
        <th scope="col">Product</th>
        <th scope="col">Quantity</th>
        <th scope="col">Price</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">#</th>
        <td>100 % Mango</td>
        <td>1 X</td>
        <td>12.99 €</td>
      </tr>
      <tr>
        <th scope="row">#</th>
        <td>Vanilla</td>
        <td>2 x</td>
        <td>10.98 €</td>
      </tr>
    </tbody>
  </table>
</div>

SCSS:

.table {
  border-right: 1px solid #000000;
  background-color: transparent;
  color: #000000;
  text-align: center;

  thead {
    font-family: 'Alegreya', serif;
    border: none;

    th {
      border: none;
    }
  }

  tbody {
    font-weight: 700;
    text-transform: uppercase;
    border: none;
    font-size: 1.5rem;

    th, td {
      border: none;

      &:nth-child(3) {
        border-right: 2px solid #000000;
        border-left: 2px solid #000000;
      }
    }
  }
}

Answer №1

To achieve this effect, you can utilize the `:after` pseudo-element as outlined below, and apply a normal `border-right` for the fourth row.

Using :after

td{
  position:relative; 
  &:nth-child(2):after,&:nth-child(3):after{
    content:'';
    width:2px;
    height:20px;
    background:#000;
    display:block;
    position:absolute;
    top:50%;
    right:0;
    transform:translateY(-50%);
  }
  
  &:nth-child(4){
    border-right:2px solid #000;
  }
}

Complete Code:

.table {
  border-right: 1px solid #000000;
  background-color: transparent;
  color: #000000;
  text-align: center;
  
  thead {
    font-family: 'Alegreya', serif;
    border: none;

    th {
      border: none;
      
      &:nth-child(4){
        border-right:2px solid #000;
      }
    }
  }

  tbody {
    font-weight: 700;
    text-transform: uppercase;
    border: none;
    font-size: 1.5rem;

    td{
      position:relative;
      &:nth-child(2):after,&:nth-child(3):after{
        content:'';
        width:2px;
        height:20px;
        background:#000;
        display:block;
        position:absolute;
        top:50%;
        right:0;
        transform:translateY(-50%);
      }
      
      &:nth-child(4){
        border-right:2px solid #000;
      }
    }

    th, td {
      border: none;
    }
  }
}

Answer №2

Here's a working example:https://jsfiddle.net/b2f03y1p/17/

Instead of the code shown below:

  &:nth-child(3) {
    border-right: 2px solid #000000;
    border-left: 2px solid #000000;
  }

Replace it with this code:

   td:nth-child(2):after,td:nth-child(3):after{
    content: '';
    height: 21px;
    width: 2px;
    background-color: black;
    position: absolute;
    top: 35%;
    left: 90%;

}
   td:nth-child(4):after{
    content: '';
    height: 100%;
    width: 2px;
    background-color: black;
    position: absolute;
    left: 90%;

}

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

In HTML, specify that the height of both the `html` and

I am facing an issue with the container-about div. I have set its height to 100% so that the div occupies the entire width and height after the header div. The problem is that currently, I cannot scroll to view the full text. It would be great if there wa ...

Changing the style of a single element in various components in Vue

I need to alter the design of a specific div that is used in different components within my Vue.js application. The #app div should have a padding of 172px only in the Hello.vue component, while it should remain at 0px in all other components. Is there a w ...

Tips for preventing an element from scrolling horizontally along with the page body

This is the structure of my HTML: <div class='header-wrapper'> <div class='title'>Title</div> </div> <div class='some-wide-content'> </div> Let's imagine a scenario where the br ...

excess white space appears in the mobile version

I recently completed a website using both materializecss and bootstrap platforms. While I know this may not be the best practice, it worked for my needs. However, I am facing an issue with the mobile view. When I reduce the viewport size, a margin appear ...

Removing a CSS class using JQuery

Within my website layout, I have a div that is dynamically included using PHP. This div is inserted in two different locations, each inside its own parent div. <div id="parent_div"> <div id="contact_details_div" class="contact_details_div sam ...

Expand the image to fill the entirety of the viewing area

Check out my development website. Whenever you click on an image, a photo slider (using photoswipe) pops up. Is there any way to have the image fill the entire viewport? I attempted using height: 100vh, width: auto, but it didn't work. https://i.ssta ...

What is the best way to locate the final text node within the <p> element?

Looking at the code below, my goal is to identify and retrieve the text node that serves as the last child element. <p class="western" style="margin-bottom: 0.14in"> <font color="#000000"> <font face="Arial, serif"> <font ...

Tips for personalizing PNG images within an SVG element

Looking to update the color of a PNG image within an SVG tag. The PNG images I have are transparent, and I want to customize their colors based on user selections. How can this be achieved? Is there anyone out there who can assist me? <HoodieSvg ...

JQuery Mobile header style vanishing when applied to a page generated dynamically

My second page retrieves data from an Ajax call on the home page, but the header lacks JQuery styling and I suspect a connection between the two. Here is the HTML for the dynamically generated page: <div data-role="page" id="breakdownDialog" data-add-b ...

Tips for eliminating excessive spacing between words to achieve justified alignment on a mobile device

please add image description hereMy issue is with using text-align: justify; as it sometimes creates large gaps between words. I attempted to resolve this for mobile devices by using text-justify: inter-word;, but unfortunately, it did not work. @media sc ...

Modifying email alters the appearance of the input element

Utilizing labels as placeholder text behind input boxes with a transparent background, changing to white on :focus and when input value is > 0, I created a contact form. However, integrating PHP into the form recently caused styling issues. Although I m ...

Create a fixed content scroll effect with an inset box-shadow

I recently stumbled upon a solution at Stack Overflow that effectively created an inset box shadow beneath content. However, I encountered an issue when the outer container div needed to be scrolling due to overflow - the inner div with the box shadow woul ...

Modifying CSS properties in a component using Javascript: A step-by-step guide

Utilizing the vue-form-wizard component initially displays as follows: https://i.sstatic.net/jwWlP.png After customizing the styles to fit my requirements, I encountered two issues. First: The wizard is supposed to commence before the bullets and the pr ...

bottom of the page contains the solution

I am currently working on creating a print stylesheet for my website. On each page, there is a footer that needs to be positioned at the bottom of the printed page, but only if there is a spacing of 30pt between the main content and the footer. In cases wh ...

When loading HTML using JavaScript, the CSS within the HTML is not properly processing. Leveraging Bootstrap 5 might help resolve

Currently utilizing bootstrap 5 for my project. I have a setup in index.html where I am loading the contents of nav.html using JavaScript. However, I am facing an issue wherein the CSS styling for the navbar is not being applied when loaded via JS. Strange ...

Div element failing to scroll with excessive content

I'm currently working on a modal using Mui Modal and I've encountered an issue. Everything seems to be functioning correctly until I add more items to the cart. When the minHeight exceeds 500, it stops at 100vh and only displays 5 items, even if ...

Dots are used to indicate overflow of title in React Material UI CardHeader

Is there a way to add ellipsis dots to the title in my Cardheader when it exceeds the parent's width (Card width)? Here is what I have attempted so far: card: { width: 275, display: "flex" }, overflowWithDots: { textOverflow: &apo ...

Cufon: Hovering on links causes them to resize and remain in that new size

I've encountered an issue with text links in a paragraph that are being replaced using Cufon. When I hover over the links, the text inside them expands and remains that way even after moving the cursor away. The color change applied to the hover state ...

Personalized Tumblr-style button

Hey there, I've been working on creating a custom Tumblr-like button and tried adding an iframe above it to make it clickable. However, something seems to be off as it's not functioning properly. I'm still trying to wrap my head around how i ...

What is the best way to reduce the size of a Bootstrap card image back to its original dimensions when

I am currently experimenting with a bootstrap card using HTML, CSS, and Bootstrap. My main focus right now is on how to shrink the image when hovering over it. The .card-header-img has a fixed height of 150px that I do not want to modify. What I want to a ...