Add a horizontal line between two div elements to create a visual division in the middle

Here is a snippet of my HTML/CSS/JS code:

<div id="blockcart-wrapper">
  <div class="blockcart cart-preview">
    <div class="header">
      <a rel="nofollow" href="#">
        <img class="cart-icon" src="https://via.placeholder.com/20x20" onclick="toggleClass()">

      </a>
    </div>
    <div class="body" id="shopping-cart-body">
      <div class="close"><a href="" onclick="toggleClass()">X</a></div>
      <ul>
      </ul>
      <div class="shopping-cart-header">CART</div>
      <div class="products-container">
        <div class="product">
          <span class="prodcut-image"><img src="https://via.placeholder.com/250x100"></span>
          <div class="product-details">
            <div class="name-header">This is a very long test name</div>
            <div class="product-quantity-details">
              <span class="quantity">QTY</span>
              <span class="color-circle"></span>
              <span class="color">COLOR</span>
            </div>
            <div class="price-open">
              <span class="product-price">XX.XX</span>
              <span class="product-link"><a href="#">open</a></span>
            </div>
          </div>
        </div>

      </div>
      <div class="checkout">
        <div class="taxes">
          <span class="label">Taxes</span>
          <span class="value">0</span>
          <hr>
        </div>
        <div class="cart-total">
          <span class="label">Total</span>
          <span class="value">0</span>
        </div>
        <button><a href="#">Checkout</a></button>
      </div>
    </div>
  </div>
</div>

Here is the relevant CSS code:

.cart-preview {
float: right;
position: relative;
}

(cart-preview styles...)

.cart-preview .body .checkout>hr {
margin-top: 30px;
margin-left: auto;
margin-right: auto;
border-color: black;
}

(rest of CSS styling...)

Here is the JavaScript function used:

function toggleClass() {
  document.getElementById('shopping-cart-body').classList.toggle('open');
} 

I want to position the <hr> within the checkout class div such that it is centered vertically between the Taxes and Total elements. I tried using height: 50% and top: 50%, but it didn't work. You can view the codepen with my code here:
https://codepen.io/anon/pen/EeyEPg

Update:
I figured out how to achieve the desired effect with a new div. I need to align this new div between the two existing divs, so I made updates to the codepen.

Answer №1

In the world of HTML5, the <hr> tag serves a different purpose compared to its predecessors. According to W3Schools, it used to be a visual element but now acts as a structural one, indicating a thematic break between different sections of content.

It seems like you're aiming for a specific visual effect with your question. In that case, you can achieve it without using the <hr> tag at all! Simply apply a border-bottom style like this:

div {
  border-bottom: 1px solid #000;
  padding-bottom: 10px;
}

Answer №2

A better alternative to using the <hr> tag is to utilize the border-bottom property, as shown in the following example:

https://codepen.io/RACCH/pen/gdMeGQ

function toggleClass() {
  document.getElementById('shopping-cart-body').classList.toggle('open');
} 
.cart-preview {
float: right;
position: relative;
}

.cart-preview a,
.cart-preview a:hover,
.cart-preview a:visited {
text-decoration: none;
color: inherit;
}

.cart-preview .header {
display: block;
font-weight: bold;
border: 1px solid #808080;
padding: 5px;
cursor: pointer;
background-color: #fff;
}

.cart-preview .body {
visibility: visible;
position: fixed;
height: 100%;
top: 0;
width: 400px;
z-index: 101;
background-color: #fff;
transition: right 1s linear;
right: -400px;
}

.cart-preview .body.open {
visibility: visible;
transition: right 1s linear;
right: 0px;
}

.cart-preview .body .shopping-cart-body {
font-family: 'IBMPlexSerif';
width: 100%;
text-align: center;
}

.cart-preview .body .close{
margin-top: 20px;
margin-left: 20px;
font-size: 30px;
float: left;
}
.cart-preview .body .shopping-cart-header{
font-family: 'IBMPlexSans';
font-size: 45px;
margin-top: 40px;
text-align: center;
}
.cart-preview .body .products-container {
position: relative;
height: 100%;
width: 100%;
margin-top: 15px;
overflow: auto;
}

.product {
display: flex;
}

.product>div {
width: 50%;
}

.product .prodcut-image {
margin-right: 10px;
}

.product img {
width: 100%;
height: auto;
}

.cart-preview .body .products-container>.product-image {
position: absolute;
width: 50%;
left: 0;
}

.cart-preview .body .products-container>.product-details {
position: absolute;
width: 50%;
float: left;
}


.cart-preview .body .products-container .color-circle:before {
content: ' \25CF';
font-size: 30px;
}

.cart-preview .body .checkout {
position: absolute;
top: 80%;
height: 100%;
width: 100%;
background: white;
}

.product-quantity-details .quantity{
float: left;
text-align: center;
border: 2px solid black;
margin-right: 10px;
background: white;
width: 36px;
height: 36px;
font-size: 15px;
line-height: 33px;
color: black;
}

.cart-preview .product{
margin-top: 10px;
}

.product-quantity-details .quantity:after{
content: 'x'
}
.price-open .product-price:after{
  content: '€';
}
.cart-preview .body .checkout>button {
position: absolute;
background: black;
text-align: center;
vertical-align: middle;
border: none;
color: white;
top: 13%;
line-height: 14px;
bottom: 50px;
height: 40px;
width: 205px;
left: 25%;
}

.checkout .taxes{
position: absolute;
/* width: 100%; */
top: 5%;
}

.checkout .cart-total{
position: absolute;
width: 100%;
top: 10%;
float: left;
}

.cart-total .value {
margin-right: 20px;
float: right;
}
.cart-total .value:after {
content:'€'
}

.cart-total .label {
margin-left: 20px;
float: left;
}


.taxes .value {
/* margin-right: 20px; */
float: right;
}

.taxes .label {
/* margin-left: 20px; */
float: left;
}

.taxes>hr{
margin-top: 30px;
margin-left: 20px;
margin-right: 20px;
border-color: black;
}

.taxes {
  border-bottom: 1px solid black;
    margin: 0px 22px;
    width: calc(100% - 48px);
  padding-bottom: 2px;
}

.product-quantity-details{
align-items: center;
display: inline-flex;
}
.product-details{
display: flex;
flex-direction: column;
align-items: flex-start
}
<div id="blockcart-wrapper">
  <div class="blockcart cart-preview">
    <div class="header">
      <a rel="nofollow" href="#">
        <img class="cart-icon" src="https://via.placeholder.com/20x20" onclick="toggleClass()">

      </a>
    </div>
    <div class="body" id="shopping-cart-body">
      <div class="close"><a href="" onclick="toggleClass()">X</a></div>
      <ul>
      </ul>
      <div class="shopping-cart-header">CART</div>
      <div class="products-container">
        <div class="product">
          <span class="prodcut-image"><img src="https://via.placeholder.com/250x100"></span>
          <div class="product-details">
            <div class="name-header">This is a very long test name</div>
            <div class="product-quantity-details">
              <span class="quantity">QTY</span>
              <span class="color-circle"></span>
              <span class="color">COLOR</span>
            </div>
            <div class="price-open">
              <span class="product-price">XX.XX</span>
              <span class="product-link"><a href="#">open</a></span>
            </div>
          </div>
        </div>

      </div>
      <div class="checkout">
        <div class="taxes">
          <span class="label">Taxes</span>
          <span class="value">0</span>
          
        </div>
        <div class="cart-total">
          <span class="label">Total</span>
          <span class="value">0</span>
        </div>
        <button><a href="#">Checkout</a></button>
      </div>
    </div>
  </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

How can I achieve an endless scrolling text effect within a square on a webpage using CSS?

My header currently displays a horizontal infinite scroll of text, but I am looking to achieve a square pattern wrapping around the page. Can you provide guidance on how this can be accomplished? Below is the code snippet I am working with: .marquee { ...

Tips for showing placeholder text on Safari

I'm having an issue with the placeholder attribute in Safari. It seems to be working fine in all other browsers, but not in Safari. <textarea class="concerncommentArea" placeholder="Place your comment here"></textarea> Does anyone know h ...

Challenges arising from the use of 'position: absolute' in managing relationships between grandparents, parents, and children

Within my React project, all code is enclosed within the root div (grandparent). In my Project.js component, there is a separate div (parent) solely responsible for the background color. This component is then displayed in App.js without any additional d ...

HTML Buttons Remain Selected After Being Clicked

Currently working on a calculator app for a class project but I've hit a roadblock while setting up keyboard listeners. The keyboard functionality is fine, however, when it comes to clicking on buttons, specifically the non-keyboard functions, they re ...

Custom-designed background featuring unique styles

I have implemented the following code to create a continuous running banner: <style> #myimage { position: fixed; left: 0%; width: 100%; bottom: 0%; background:url("http://static.giga.de/wp-content/uploads/2014/08/tastatur-bild ...

Contemplating the Sequence of DOM Execution

In the world of html/javascript, the order of execution is typically serial, meaning that the browser reads the code line by line and interprets it accordingly. This is a common practice in most programming languages. Some javascript programmers prefer to ...

What is the best way to enlarge the text in an image input field?

One of the input fields I'm working with looks like this: <input type="image" name="submit" value="submit" src="images/searchb1.png" id="button1"/> I am trying to figure out how to enlarge the text Submit on that field using CSS. Any suggestio ...

Contrast the objects in views.py between two distinct model objects in Django

I am currently working on a feature that compares the skills required for different job postings (such as web development, marketing, etc) with the skills of a user who is logged in. If there is a match, the job posting will be displayed to the user. The ...

Ways to perfectly align an icon both horizontally and vertically in an <a> tag that covers the entire container

Looking to center an icon within an "a" tag that spans the entire div container? The goal is to make the entire container clickable for carousel navigation, rather than just the icon itself. Currently, I can achieve each desired effect separately. On the ...

Update the styling for the second list item within a specified unordered list class instantaneously

Looking to emphasize the second list item (li) within a selected dropdown list with a designated unordered list class of "chosen-results". <div class="chosen-container chosen-container-single select-or-other-select form-select required chosen-proc ...

Floating container leads to delays

My goal is to create a div that changes when I hover over it. However, when I move my mouse into the div, there seems to be some lagging and the content does not appear clearly. Below is the HTML and CSS code I have used: .unshow-txt:hover, .unshow-txt: ...

A distinctive web page featuring an engaging image backdrop: captivating content effortlessly scrolling beneath

On my website, I have implemented a background image with a fixed transparent header. When scrolling down, I want the main content to be hidden beneath the header. To achieve this effect, I used the -webkit-mask-image property. However, this approach affec ...

Are you able to develop a customized TestNG Listener to cater to your specific requirements?

I have developed a unique concept for a TestNG listener that meets my specific requirements. Essentially, I aim to design a custom listener that generates a report using a predefined HTML format. The crux of my idea revolves around declaring the listener ...

Ways to expand the div to fit the width of the text after it has been wrapped

I need a continuous underline to stretch across the remaining width after the text wraps in a table cell. Here is the desired effect: https://i.sstatic.net/XNNyj.png If the text wrapping changes, the underline width should adjust accordingly. This is w ...

Adjust the height of an element when the maximum height is set to none

I am trying to add animation to the opening of a menu on my website. This is achieved by adjusting the max-height property of the <div> element that represents the menu, as well as changing the display property. The max-height value is being changed ...

Take off the wrapping from the package

I need help with my code on how to remove the wrapper span tag without removing the text. <ul> <li> <a href="#"> </a> <ul> <li> <a href="#"> ...

What is the method to alter the fill of a circle using CSS when it is hovered over in JavaFX?

I am seeking assistance for a task involving a circle within an hBox. I would like the color of the circle to change when the mouse cursor hovers over it. Is there a way to accomplish this using JavaFX and CSS? If not, what is the recommended approach fo ...

Displaying the structure of a MongoDB database using Express and Angular in a tabular format

I am looking to present the data from MongoDB in a table format using HTML along with Node.js, Express.js, and Angular.js. Currently, my approach is as follows: route.js app.get('/superhero', function(req, res) { superhero.superhero_list(r ...

Guide to centering images with HTML and CSS

I've recently created a website with a homepage design that I'd like to tweak. Currently, the layout looks like this : https://i.stack.imgur.com/5UeUn.jpg My goal is to reposition the ficstore logo to the center and divide the bar into two halv ...

Error in Compiling HTML Elements Collection<<Element>

Currently, I am developing an eCommerce application that features a popup window for users when they click on "Add to Cart." This popup allows users to select product variations and quantities before adding the item to their cart. The popup consists of a s ...