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');
});
Related
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;
}
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>
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;
}
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.
I would like to have a connecting vertical line between each circle. The "Sections" are dynamic in vertical height.
Here is the current SASS:
#import '../sass/sa.common';
$color: $sa-gray-4;
$colorActive: $sa-green;
$colorComplete: $sa-green;
.progress-indicator {
margin-bottom: 50px;
margin-top: 75px;
.step {
margin-top: 40px;
content: "";
display: table;
clear: both;
position: relative;
&:first-child {
margin-top: 0;
}
&:last-child {
div {
&.circle {
&:before {
display: none;
}
}
}
}
&.active {
div {
color: $colorActive;
&.circle {
border-color: $colorActive;
}
a {
color: $colorActive;
}
}
}
&.complete {
div {
color: $colorComplete;
&.circle {
border-color: $colorComplete;
&.filled {
background-color: $colorComplete;
color: $sa-white;
}
}
}
}
div {
color: $color;
display: table-cell;
float: left;
padding-top: 2px;
font-size: 16px;
font-weight: bold;
vertical-align: middle;
&.circle {
height: 30px;
width: 30px;
text-align: center;
border: 2px solid $color;
border-radius: 50%;
&:before {
content: "";
position: absolute;
z-index: 1;
margin-top: 26px;
left: 13px;
border: 1px solid $sa-gray-4;
height: 125%;
}
}
&.text {
padding-left: 10px;
padding-top: 5px;
ul {
margin: 0;
margin-top: 15px;
padding: 0;
list-style-type: none;
li {
a {
display: block;
margin-top: 5px;
&:first-child {
margin-top: 0;
}
}
}
}
}
}
}
}
CSS:
<style type="text/css">#charset "UTF-8";
.btn.btn-green {
background-color: #80b241;
color: #ffffff; }
.btn.btn-green:hover {
background-color: #88bc47; }
.btn.btn-gray-1 {
background-color: #595959;
color: #e7e5e1; }
.btn.btn-gray-1:hover {
background-color: #666666; }
.label.label-green {
background-color: #80b241;
color: #242424; }
.label.label-gray-1 {
background-color: #595959;
color: #ffffff; }
.btn.btn-green {
background-color: #80b241;
color: #ffffff; }
.btn.btn-green:hover {
background-color: #88bc47; }
.btn.btn-gray-1 {
background-color: #595959;
color: #e7e5e1; }
.btn.btn-gray-1:hover {
background-color: #666666; }
.label.label-green {
background-color: #80b241;
color: #242424; }
.label.label-gray-1 {
background-color: #595959;
color: #ffffff; }
.progress-indicator {
margin-bottom: 50px;
margin-top: 75px; }
.progress-indicator .step {
margin-top: 40px;
content: "";
display: table;
clear: both;
position: relative; }
.progress-indicator .step:before {
content: "";
position: absolute;
z-index: 1;
margin-top: 26px;
left: 13px;
border: 1px solid #ADABA6;
height: 125%; }
.progress-indicator .step:first-child {
margin-top: 0; }
.progress-indicator .step:last-child:before {
display: none; }
.progress-indicator .step.active div {
color: #80b241; }
.progress-indicator .step.active div.circle {
border-color: #80b241; }
.progress-indicator .step.active div a {
color: #80b241; }
.progress-indicator .step.complete div {
color: #80b241; }
.progress-indicator .step.complete div.circle {
border-color: #80b241; }
.progress-indicator .step.complete div.circle.filled {
background-color: #80b241;
color: #ffffff; }
.progress-indicator .step div {
color: #ADABA6;
display: table-cell;
float: left;
padding-top: 2px;
font-size: 16px;
font-weight: bold;
vertical-align: middle; }
.progress-indicator .step div.circle {
height: 30px;
width: 30px;
text-align: center;
border: 2px solid #ADABA6;
border-radius: 50%; }
.progress-indicator .step div.text {
padding-left: 10px;
padding-top: 5px; }
.progress-indicator .step div.text ul {
margin: 0;
margin-top: 15px;
padding: 0;
list-style-type: none; }
.progress-indicator .step div.text ul li a {
display: block;
margin-top: 5px; }
.progress-indicator .step div.text ul li a:first-child {
margin-top: 0; }
.category-selector {
margin-top: 30px; }
.category-selector .header {
border-bottom: 2px solid #80b241; }
.category-selector .header:before, .category-selector .header:after {
content: " ";
display: table; }
.category-selector .header:after {
clear: both; }
.category-selector .section-container:before, .category-selector .section-container:after {
content: " ";
display: table; }
.category-selector .section-container:after {
clear: both; }
.category-selector .section-container .section {
float: left;
height: 400px;
min-width: 150px;
overflow-y: scroll; }
.category-selector .section-container .section .item {
border-bottom: 1px solid #80b241;
cursor: pointer;
padding: 5px 10px 5px 5px; }
.category-selector .section-container .section .item:last-child {
border: 0; }
.category-selector .section-container .section .item.active {
background-color: #80b241;
color: #ffffff; }
</style>
And the Markup:
<div class="row">
<div class="col-lg-3">
<div class="progress-indicator">
<div class="step">
<div class="circle">1</div>
<div class="text">Select Category</div>
</div>
<div class="step active">
<div class="circle">2</div>
<div class="text">
Fill Out Listing
<ul>
<li>
Vital Fields
Image Url
Dimensions
</li>
</ul>
</div>
</div>
<div class="step">
<div class="circle">3</div>
<div class="text">Bulk Options</div>
</div>
<div class="step">
<div class="circle">4</div>
<div class="text">More Options</div>
</div>
</div>
<div class="text-center">
<button class="btn btn-default" style="margin-bottom: 10px;">
SAVE AS DRAFT
</button>
<button class="btn btn-gray-1">
MOVE TO PUBLISH QUEUE
</button>
</div>
</div>
<div class="col-lg-6">
<div class="category-selector">
<div class="header">
<div class="pull-left">
<h4>Select a Category</h4>
</div>
<div class="pull-right">
<button class="btn btn-green">Next</button>
</div>
</div>
<div class="section-container">
<div class="section">
<div class="item" [ngClass]="{active: selectedCategory && category.id === selectedCategory.id}" *ngFor="let category of topLevelCategories" (click)="getSubCategories(category)">
{{category.displayName}}
</div>
</div>
<div class="section" *ngIf="subCategories && subCategories.length > 0">
<div class="item" [ngClass]="{active: selectedSubCategory && subCategory.id === selectedSubCategory.id}" *ngFor="let subCategory of subCategories" (click)="getFields(subCategory)">
{{subCategory.displayName}}
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3">
Side Nav/Slide In
</div>
</div>
Not all browsers honor the display of ::before on elements with display:table. (I have a hunch you are experiencing this in FF? - In Chrome they're displayed). There are two possible fixes:
Either replace display:table with display:flex and display: table-cell with display: block...
...or use proper html elements (divs?) instead of pseudo-elements for lines.
Other notes you might find useful:
remove z-index from .step::before
change height:125% to height:calc(100% + {N}px) where {N} is the difference in px between the actual height of .circle and 40px (top margin of .step). Using this technique you can control exact size of line and match the gap between the circles down to the pixel, thus not needing to hide the extra line length.
Hope the above makes sense and helps. Don't forget to autoprefix.
Something like:
.step {
position: relative;
&:after {
content: "";
position: absolute;
top: 0;
left: 30px; // magic number, try until you get the right positioning
width: 1px;
height: 100%;
border-left: 2px solid $any-color-you-like;
}
}
Make some adjustments, and it should work as you need.