I am working on a project that involves HTML, CSS, and JS code. Here is the structure of my code:
HTML:
<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/250x200"></span>
<div class="product-details">
<div class="name-header">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="#">öffnen</a></span>
</div>
</div>
</div>
<div class="product">
<span class="prodcut-image"><img src="https://via.placeholder.com/250x200"></span>
<div class="product-details">
<div class="name-header">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="#">öffnen</a></span>
</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>
CSS:
.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;
}
... (CSS code continues) ...
JS:
function toggleClass() {
document.getElementById('shopping-cart-body').classList.toggle('open');
}
I am facing an issue aligning the checkout
div relative to its parent and positioning its child elements absolutely. I want the checkout div to always have 20% of the parent's height with the child elements aligned accordingly. I need the button to have a margin from the bottom for example 30px. However, I couldn't get it to work using position: relative
for the .checkout
div.
I have created a codepen demonstrating this issue: https://codepen.io/anon/pen/BOLpdG
If anyone can help me with aligning the div properly, I would greatly appreciate it.