Fix div to bottom of parent - html

i have the following HTML/CSS:
<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">X</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">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">öffnen</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>Checkout</button>
</div>
</div>
</div>
</div>
CSS:
.cart-preview .body {
visibility: visible;
position: fixed;
height: 100%;
top: 0;
width: 400px;
z-index: 100;
background-color: #fff;
transition: right 1s linear;
right: -400px;
}
.cart-preview .body.open {
visibility: visible;
transition: right 1s linear;
right: 0px;
}
.cart-preview .body .shooping-cart-body {
font-family: 'sans-serif';
width: 100%;
text-align: center;
}
.cart-preview .body .close{
float: left;
}
.cart-preview .body .shooping-cart-header{
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: 20px;
}
.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: right;
}
.cart-preview .body .products-container .color-circle:before {
content: ' \25CF';
font-size: 30px;
}
.cart-preview .body .checkout {
height: 100%;
width: 100%;
}
.product-quantity-details .quantity{
border: 2px solid black;
margin: 0 10px;
background: white;
width: 36px;
height: 36px;
font-size: 15px;
line-height: 15px;
color: black;
width: auto;
height: auto;
}
.product-quantity-details .quantity:after{
content: 'x'
}
.cart-preview .body .checkout>button {
position: absolute;
background: black;
text-align: center;
color: white;
bottom: 50px;
height: 20px;
width: 205px;
left: 25%;
}
.taxes {
position: relative;
margin-bottom: 5px;
left: 0;
}
.cart-total {
position: absolute;
bottom: 100px;
width: 100%;
}
.taxes {
position: absolute;
bottom: 300px;
width: 100%;
}
.cart-total .value {
float: right;
}
.cart-total .value:after {
content:'€'
}
.cart-total .label {
float: left;
}
.taxes .value {
float: right;
}
.taxes .label {
float: left;
}
.cart-preview.cart-overview {
width: 100%;
position: inherit;
}
.cart-preview.cart-overview .body {
display: block;
position: inherit;
width: 100%;
}
.cart-preview .header > :first-child {
float: left;
}
.cart-preview .header > :last-child {
float: right;
}
.cart-preview .header::after,
.cart-preview .cart-totals > div::after {
clear: both;
content: "\A0";
}
.cart-preview .body {
border: 1px solid #808080;
padding: 2px;
}
The JavaScript simply toggles the .open class for the body.
Now I want to stick the last div to the bottom of the body, so the product-container div is scrollable on overflow and the checkout is always visible.
However, neither the scrolling nor the chechkout divs position are working.
Could someone help me with these two things?

Please try this and provide feedback so, that answer can be improved more.
.cart-preview .body {
position: fixed;
height: 100%;
top: 0;
width: 400px;
z-index: 100;
background-color: #fff;
transition: right 1s linear;
}
.cart-preview .body.open {
visibility: visible;
transition: right 1s linear;
right: 0px;
}
.cart-preview .body .shooping-cart-body {
font-family: 'sans-serif';
width: 100%;
text-align: center;
}
.cart-preview .body .close{
float: left;
}
.cart-preview .body .shooping-cart-header{
text-align: center;
}
.cart-preview .body .products-container {
position: relative;
max-height: 400px;
height: auto;
width: 100%;
margin-top: 15px;
overflow: auto;
}
.product {
display: flex;
}
.product>div {
width: 50%;
}
.product .prodcut-image {
margin-right: 20px;
}
.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: right;
}
.cart-preview .body .products-container .color-circle:before {
content: ' \25CF';
font-size: 30px;
}
.product-quantity-details .quantity{
border: 2px solid black;
margin: 0 10px;
background: white;
width: 36px;
height: 36px;
font-size: 15px;
line-height: 15px;
color: black;
width: auto;
height: auto;
}
.product-quantity-details .quantity:after{
content: 'x'
}
.cart-preview .body .checkout>button {
position: relative;
background: black;
text-align: center;
color: white;
height: 20px;
width: 205px;
}
.taxes {
position: relative;
}
.cart-total .value {
float: right;
}
.cart-total .value:after {
content:'€'
}
.cart-total .label {
float: left;
}
.taxes .value {
float: right;
}
.taxes .label {
float: left;
}
.cart-preview.cart-overview {
width: 100%;
position: inherit;
}
.cart-preview.cart-overview .body {
display: block;
position: inherit;
width: 100%;
}
.cart-preview .header > :first-child {
float: left;
}
.cart-preview .header > :last-child {
float: right;
}
.cart-preview .header::after,
.cart-preview .cart-totals > div::after {
clear: both;
content: "\A0";
}
.cart-preview .body {
border: 1px solid #808080;
padding: 2px;
}

Related

Place horizontal line in middle between two divs

i have the following HTML/CSS/JS:
<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">X</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">open</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>Checkout</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;
}
.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;
}
.product-quantity-details{
align-items: center;
display: inline-flex;
}
.product-details{
display: flex;
flex-direction: column;
align-items: flex-start
}
and JavaScript:
function toggleClass() {
document.getElementById('shopping-cart-body').classList.toggle('open');
}
Now I want to achieve to have the <hr> within the div with the class checkout to be placed always at the middle of the space between the taxes and the total sum.
How can I achieve this? I tried height: 50% and top: 50%.
I summed this up in a codepen:
https://codepen.io/anon/pen/EeyEPg
Update:
I just learned how to achieve the effect with a div, so i need to align this new div between the two other divs, so I updated the codepen.
The <hr> tag has a different meaning in HTML5 than previous versions of HTML. W3Schools has a very good description of this, but basically it used to be a visual element while now it's a structural element. It symbolizes a thematic break between two different sections of content.
Based on your question, I'm assuming you're trying to achieve the visual effect. You don't need the <hr> tag for this at all! Just use border-bottom like so:
div {
border-bottom: 1px solid #000;
padding-bottom: 10px;
}
I suggest to use border-bottom instead of an <hr> tag, like the 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">X</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">open</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>Checkout</button>
</div>
</div>
</div>
</div>

Align divs along image vertically

I have the following HTML/CSS/JS summed up in a codepen:
https://codepen.io/anon/pen/gdwLGm
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">X</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">open</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>Checkout</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;
}
.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-left: 20px;
margin-right: 10px;
}
.product img {
width: 100%;
height: auto;
}
.name-header{
text-align: left;
}
.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'
}
.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;
}
.product-quantity-details{
align-items: center;
display: inline-flex;
}
.product-details{
display: flex;
flex-direction: column;
align-items: flex-start
}
#blockcart-modal {
position: fixed;
background-color: hsla(0, 0%, 100%, .1);
top: 0;
left: 0;
bottom: 0;
right: 0;
text-align: center
}
#blockcart-modal > div {
padding: 20px;
display: inline-block;
min-width: 50%;
min-height: 400px;
margin-top: 200px;
text-align: left;
background-color: #fff;
z-index: 100;
border: 1px solid #ccc
}
and the JavaScript (only contains one function):
function toggleClass() {
document.getElementById('shopping-cart-body').classList.toggle('open');
}
So the goal is to align the items right of the picuture. The name (div with class name-header should always be at the 'top' level of the picture, the quantity (div with class product-quantity-details should be at the 'half' and the price (div with class price-open should be at the bottom. The alignment within the elements is fine, just the positioning is not working the way I want.
What I tried: I tried using position: absolute; for the divs to align and then using top:0; for the name, bottom:0; for the price and top: 50%; for the quantity details. This was not really working.
Can someone help me here?
Here is my solution, Open the snippet in full screen mode
I increased the height of the image to 300px for testing purpose only.
justify-content:space-between; will align the items by distributing space equally between children.
In your case name will be on top, product details in middle and price at the bottom
Add this to ur CSS
.product-details{
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content:space-between;
}
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-left: 20px;
margin-right: 10px;
}
.product img {
width: 100%;
height: 300px; /*For testing purpose*/
}
.name-header{
text-align: left;
}
.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'
}
.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;
}
.product-quantity-details{
align-items: center;
display: inline-flex;
}
.product-details{
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content:space-between;
}
#blockcart-modal {
position: fixed;
background-color: hsla(0, 0%, 100%, .1);
top: 0;
left: 0;
bottom: 0;
right: 0;
text-align: center
}
#blockcart-modal > div {
padding: 20px;
display: inline-block;
min-width: 50%;
min-height: 400px;
margin-top: 200px;
text-align: left;
background-color: #fff;
z-index: 100;
border: 1px solid #ccc
}
<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">X</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">open</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>Checkout</button>
</div>
</div>
</div>
</div>
Add these two things too
.cart-preview .header {
float: left;
}
.cart-preview .body {
float: left;
}

Float left not working in div

i have the following HMTML/CSS:
<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">X</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">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">öffnen</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>Checkout</button>
</div>
</div>
</div>
</div>
The following set of CSS rules is defined:
.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: 100;
background-color: #fff;
transition: right 1s linear;
right: -400px;
}
.cart-preview .body.open {
visibility: visible;
transition: right 1s linear;
right: 0px;
}
.cart-preview .body .shooping-cart-body {
font-family: 'sans-serif';
width: 100%;
text-align: center;
}
.cart-preview .body .close{
float: left;
}
.cart-preview .body .shopping-cart-header{
font-family: 'IBMPlexSans-Bold.woff'
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: 20px;
}
.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: gray;
}
.product-quantity-details .quantity{
float: left;
border: 2px solid black;
margin: 0 10px;
background: white;
width: 36px;
height: 36px;
font-size: 15px;
line-height: 15px;
color: black;
}
.product-quantity-details .quantity:after{
content: 'x'
}
.cart-preview .body .checkout>button {
position: absolute;
background: black;
text-align: center;
vertical-align: middle;
color: white;
top: 15%;
line-height: 14px;
bottom: 50px;
height: 20px;
width: 205px;
left: 25%;
}
.checkout .taxes{
position: absolute;
top: 5%;
}
.checkout .cart-total{
position: absolute;
top: 10%;
float: left;
}
.cart-total .value {
float: right;
}
.cart-total .value:after {
content:'€'
}
.cart-total .label {
float: left;
}
.taxes .value {
float: right;
}
.taxes .label {
float: left;
}
JavScript:
function toggleClass() {
document.getElementById('shopping-cart-body').classList.toggle('open');
}
I don't get the content within the div product-details algined in one horizontal line next to the image. I tried using float: left and left:0. Can someone help me to get the content aligned next to the image and all starting letters are in one line horitontally?
I pasted it into a codepen:
https://codepen.io/seppl2202/pen/QVNdXd
Here is the link https://codepen.io/anon/pen/vzGgqq with the CSS .
The Css that needs to be modified is
.product-quantity-details{
display: flex;
flex-direction: column;
align-items: center;
}
.product-details{
display: inline-flex;
}
The inline-flex will align the items to a single line for .product-details and the align-items: center; should align the contents in the center perfectly, the color and quantity field.

CSS class for fly in transition for javaScript

I need your help using CSS3 transitions. I have some contend I want to fly in from the right to its defined position when hovering. This can be achieved using the CSS in the :hover rule.
However, I want to call this effect from a JavaScript function, so I need your help.
Here is the Code:
#blockcart-wrapper .cart-preview .header {
border: none;
}
#blockcart-wrapper .cart-preview .header .cart-icon {
width: 25px;
height: 28px;
}
.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 {
display: none;
width: 400px;
background-color: #fff;
right: 0;
}
.cart-preview:hover .body {
display: block;
position: absolute;
}
.cart-preview.cart-overview {
width: 100%;
position: inherit;
}
.cart-preview.cart-overview .body {
display: block;
position: inherit;
width: 100%;
}
.cart-preview .header > :first-child {
float: left;
}
.cart-preview .header > :last-child {
float: right;
}
.cart-preview .header::after,
.cart-preview .cart-totals > div::after {
clear: both;
content: "\A0";
}
.cart-preview .body {
border: 1px solid #808080;
padding: 2px;
}
.cart-preview ul {
margin: 0;
padding: 0;
margin-top: 20px;
margin-bottom: 20px;
}
.cart-preview li {
list-style: none;
margin-bottom: 15px;
}
.cart-preview li > * {
display: inline-block;
vertical-align: top;
}
.cart-preview li .product-quantity {
color: #666;
width: 10%;
}
.cart-preview .product-quantity::after {
content: 'x';
}
.cart-preview li .product-name {
width: 50%;
}
.cart-preview li .product-price {
width: 20%;
}
.cart-preview li .remove-from-cart {
text-indent: 100%;
display: inline-block;
overflow: hidden;
vertical-align: middle;
text-decoration: none;
color: inherit;
font-weight: bold;
width: 2em;
white-space: nowrap;
float: right;
}
.cart-preview li .remove-from-cart::before {
content: 'X';
text-indent: 0px;
border: 1px solid #ccc;
border-radius: 100%;
width: 1em;
height: 1em;
padding: 2px;
text-align: center;
background-color: #333;
color: #fff;
float: left;
}
.cart-preview .cart-totals .label {
float: left;
}
.cart-preview .cart-totals .value {
float: right;
}
.cart-preview .cart-totals > div {
clear: both;
border-bottom: 1px solid #ccc;
}
.cart-preview .cart-totals > div:not(:last-child) {
margin-bottom: 5px;
}
.cart-totals .label {
font-weight: bold;
}
#blockcart-modal {
position: fixed;
background-color: rgba(255,255,255,0.1);
top: 0;
left: 0;
bottom: 0;
right: 0;
text-align: center;
}
#blockcart-modal > div {
padding: 20px;
display: inline-block;
min-width: 50%;
min-height: 400px;
margin-top: 200px;
text-align: left;
background-color: #fff;
z-index: 100;
border: 1px solid #ccc;
}
<div id="blockcart-wrapper">
<div class="blockcart cart-preview">
<div class="header">
<a rel="nofollow" href="#">
<img class="cart-icon" src="https://fakeimg.pl/50x50/?text=cart+icon">
</a>
</div>
<div class="body">
<ul>
</ul>
<div class="cart-subtotals">
<div class="products">
<span class="label">Partial sum</span>
<span class="value">0</span>
</div>
<div class="">
<span class="label"></span>
<span class="value"></span>
</div>
<div class="shipping">
<span class="label">Shipping</span>
<span class="value">0</span>
</div>
<div class="">
<span class="label"></span>
<span class="value"></span>
</div>
</div>
<div class="cart-total">
<span class="label">Total sum</span>
<span class="value">0</span>
</div>
</div>
</div>
</div>
So I want to achieve, that the div with class body flies in from the right to its determined position using an own class so I can toggle the class by a JavaScript if a certain external event is triggered and the class should only contain the transition effect, so the browser does the 'reverse transition' when the hover is stopped or the class is removed by a JavaScript function.
Can you help me here?
The css should be just like you would do if using :hover, just instead of :hover add a class to the selector (a.hovered), and use js mouseover and mouseout events to toggle this class.
CSS -
div.body.hovered {
right: 300px; /*or however you meant to do the transition*/
}
JS -
var elements = document.getElementsByClass('body');
elements.addEventListener("mouseover", function( event ) {
this.classList.add('hovered');
});
elements.addEventListener("mouseout", function( event ) {
this.classList.remove('hovered');
});

Can not put text over an image

I am trying to put text over an image, but when I give the text parametr left: it's cut in half.
HTML:
<div class="c-subcat-item">
<div class="pro-img-wrap">
<div class="pro-img-wrap-in">
<div class="img-middle-center">
<a class="img-middle-wrap" href="/Wines/Product/1417">
<img src="/Images/bottle-red.jpg" alt="Produkt">
</a>
</div>
</div>
</div>
<div class="subcat-item-details">
<div class="product-desc-container">
<div class="">
<a class="item-name" href="/Wines/Product/1417">Avilla</a>
<div class="clearfix"></div>
<div class="item-our-price">
<span class="item-sold-out">Chwilowo niedostępny</span>
</div>
<div class="item-detail-price">
<span class="item-price-value">45,00 zł </span>
</div>
</div>
<div class="div-empty-margin"></div>
</div>
<div class="clearfix"></div>
<span class="item-more">
<a class="item-more" href="/Wines/Product/1417">Zobacz więcej</a>
</span>
<div class="div-empty-margin"></div>
<div class="add-to-cart">
</div>
</div>
</div>
CSS:
body {
background-color: #fffff7;
color: #666;
font-family: 'Roboto Condensed',sans-serif;
font-size: 10px;
height: 100%;
margin: 0;}
html, body, .page-wrapper {
width: 100%;
min-width: 1024px;
margin-left: auto;
margin-right: auto;}
.page-wrapper {
height: 100%;
}
.page-content-wrapper {
min-height: 100%;
text-align: center;
}
.main {
display: inline-block;
margin: 20px auto 0;
margin-bottom: 61px;
position: relative;
text-align: left;
width: 965px;
}
.wrapper {
float: left;
margin-bottom: 20px;
width: 100%;
}
.content {
float: left;
width: 100%;
}
.content-main-wrapper1 {
float: left;
width: 100%;
}
.content-main-wrapper2 {
float: left;
position: relative;
right: 767px;
width: 100%;
}
.content-wo-padding {
float: left;
left: 768px;
position: relative;
width: 726px;
}
.pro-img-wrap {
float: left;
}
.c-subcat-item {
float: left;
padding: 20px;
position: relative;
width: 726px;
}
.pro-img-wrap-in {
border: 1px solid #e8e5e5;
float: left;
height: 240px;
overflow: hidden;
width: 160px;
display: table;
}
.img-middle-center {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
background: #fff;
display: table-cell;
float: none;
height: 100%;
width: 100%;
text-align: center;
vertical-align: middle;
}
.subcat-item-details {
float: right;
height: 242px;
width: 544px;
position: relative;
}
.product-desc-container {
overflow: hidden;
position: relative;
}
h2.item-name, a.item-name {
color: #333;
float: left;
font-size: 16px;
font-weight: bold;
line-height: 15px;
margin: 2px 0 5px 0;
padding: 0;
width: 100%;
text-transform: uppercase;
}
.clearfix {
clear: both;
}
.item-our-price {
float: left;
margin-top: 10px;
width: 100%;
}
.item-our-price span.item-sold-out {
position: relative;
color: #f00;
background-color: #fff;
padding: 10px;
border: solid 1px #f00;
font-size: 1.3em;
cursor: default;
left: -60px;
}
You can check it here
Remove overflow: hidden; from class .product-desc-container
body {
background-color: #fffff7;
color: #666;
font-family: 'Roboto Condensed',sans-serif;
font-size: 10px;
height: 100%;
margin: 0;}
html, body, .page-wrapper {
width: 100%;
min-width: 1024px;
margin-left: auto;
margin-right: auto;}
.page-wrapper {
height: 100%;
}
.page-content-wrapper {
min-height: 100%;
text-align: center;
}
.main {
display: inline-block;
margin: 20px auto 0;
margin-bottom: 61px;
position: relative;
text-align: left;
width: 965px;
}
.wrapper {
float: left;
margin-bottom: 20px;
width: 100%;
}
.content {
float: left;
width: 100%;
}
.content-main-wrapper1 {
float: left;
width: 100%;
}
.content-main-wrapper2 {
float: left;
position: relative;
right: 767px;
width: 100%;
}
.content-wo-padding {
float: left;
left: 768px;
position: relative;
width: 726px;
}
.pro-img-wrap {
float: left;
}
.c-subcat-item {
float: left;
padding: 20px;
position: relative;
width: 726px;
}
.pro-img-wrap-in {
border: 1px solid #e8e5e5;
float: left;
height: 240px;
overflow: hidden;
width: 160px;
display: table;
}
.img-middle-center {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
background: #fff;
display: table-cell;
float: none;
height: 100%;
width: 100%;
text-align: center;
vertical-align: middle;
}
.subcat-item-details {
float: right;
height: 242px;
width: 544px;
position: relative;
}
.product-desc-container {
position: relative;
}
h2.item-name, a.item-name {
color: #333;
float: left;
font-size: 16px;
font-weight: bold;
line-height: 15px;
margin: 2px 0 5px 0;
padding: 0;
width: 100%;
text-transform: uppercase;
}
.clearfix {
clear: both;
}
.item-our-price {
float: left;
margin-top: 10px;
width: 100%;
}
.item-our-price span.item-sold-out {
position: relative;
color: #f00;
background-color: #fff;
padding: 10px;
border: solid 1px #f00;
font-size: 1.3em;
cursor: default;
left: -60px;
}
<div class="c-subcat-item">
<div class="pro-img-wrap">
<div class="pro-img-wrap-in">
<div class="img-middle-center">
<a class="img-middle-wrap" href="/Wines/Product/1417"> <img src="/Images/bottle-red.jpg" alt="Produkt">
</a>
</div>
</div>
</div>
<div class="subcat-item-details">
<div class="product-desc-container">
<div class="">
<a class="item-name" href="/Wines/Product/1417">Avilla</a>
<div class="clearfix"></div>
<div class="item-our-price">
<span class="item-sold-out">Chwilowo niedostępny</span>
</div>
<div class="item-detail-price">
<span class="item-price-value">45,00 zł </span>
</div>
</div>
<div class="div-empty-margin"></div>
</div>
<div class="clearfix"></div>
<span class="item-more">
<a class="item-more" href="/Wines/Product/1417">Zobacz więcej</a>
</span>
<div class="div-empty-margin"></div>
<div class="add-to-cart">
</div>
</div>
</div>
Remove overflow:hidden from .product-desc-container that's the reason for the text not visible over the image
remove overflow:hidden from .product-desc-container
see here : jsfiddle
code
.product-desc-container {
/* overflow: hidden; */
position: relative;
}