jQuery modal not setting horizontally middle - html

I have a simple jQuery modal. It works well, but I can't set it horizontally middle. I've tried many approach, but it not centering anyway. It creates problem when I want to use "max-width: 400". It create problem and go on one side. I want to make it like bootstrap modal. Max-width: 400 and will be centered horizontally also. Please look at my code.
// common close button
$('.mi-modal-toggle').click(function() {
$(this).closest(".mi-modal").toggleClass('modal-visible');
});
// explicit button per modal
$('.mi-modal-toggle').on('click', function(e) {
var modalid = $(this).data("modal-id");
$(`.mi-modal[data-modal-id='${modalid}']`).toggleClass('modal-visible');
});
.mi-modal {
position: fixed;
z-index: 10000; /* 1 */
top: 0;
left: 0;
visibility: hidden;
height: 100%;
box-sizing: border-box;
padding: 10%;
width: 80%; /* 94% + 3% +3% = 100% */
max-width: 400px;
}
.mi-modal.modal-visible {
visibility: visible;
}
.mi-modal-overlay {
position: fixed;
z-index: 10;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: hsla(0, 0%, 0%, 0.4);
visibility: hidden;
opacity: 0;
transition: visibility 0s linear 0.3s, opacity 0.3s;
box-sizing: border-box;
}
.mi-modal.modal-visible .mi-modal-overlay {
opacity: 1;
visibility: visible;
transition-delay: 0s;
}
.mi-modal-wrapper {
position: absolute;
z-index: 9999;
top: 3em;
width: 100%;
background-color: #fff;
box-shadow: 0 0 1.5em hsla(0, 0%, 0%, 0.35);
box-sizing: border-box;
margin: auto auto !important;
}
.mi-modal-transition {
transition: all 0.4s;
transform: translateY(-10%);
opacity: 0;
}
.mi-modal.modal-visible .mi-modal-transition {
transform: translateY(0);
opacity: 1;
}
.mi-modal-header,
.mi-modal-content {
padding: 1em;
}
.mi-modal-header {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: space-between;
position: relative;
background-color: #fff;
box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.06);
border-bottom: 1px solid #e8e8e8;
}
.mi-modal-close {
margin: -0.5rem -0.5rem -0.5rem auto;
color: #aaa;
background: #edcfa5;
border: 0;
font-size: 20px;
font-weight: 700;
position: absoloute;
box-sizing: content-box;
width: 1em;
height: 1em;
padding: 0.3em;
color: #000;
border: 0;
border-radius: 0.25rem;
opacity: .5;
}
.mi-modal-close:hover {
color: #777;
}
.mi-modal-heading {
font-size: 1.125em;
margin: 0px 8px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.mi-modal-content>*:first-child {
margin-top: 0;
}
.mi-modal-content>*:last-child {
margin-bottom: 0;
}
.mi-modal.modal-scroll .mi-modal-content {
max-height: 60vh;
overflow-y: scroll;
}
.mi-modal.modal-scroll .mi-modal-wrapper {
position: absolute;
z-index: 9999;
top: 2em;
left: 50%;
width: 32em;
margin-left: -16em;
background-color: #CDf;
box-shadow: 0 0 1.5em hsla(0, 0%, 0%, 0.35);
box-sizing: border-box;
}
.modal-footer {
display: flex;
flex-wrap: wrap;
flex-shrink: 0;
align-items: center; /* justify-content: flex-end; */
padding: 0.75rem;
border-top: 1px solid #dee2e6;
border-bottom-right-radius: calc(0.3rem - 1px);
border-bottom-left-radius: calc(0.3rem - 1px);
}
.modal-footer>* {
margin: 0.25rem;
}
<button class="mi-modal-toggle" data-modal-id="modal1">Show modal</button>
<div class="mi-modal" data-modal-id="modal1">
<div class="mi-modal-overlay mi-modal-toggle"></div>
<div class="mi-modal-wrapper mi-modal-transition">
<div class="mi-modal-header">
<h2 class="mi-modal-heading">This is a modal</h2>
<button class="mi-modal-close mi-modal-toggle">×</button>
</div>
<div class="mi-modal-body">
<div class="mi-modal-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit eum delectus, libero, accusantium dolores inventore obcaecati placeat cum sapiente vel laboriosam similique totam id ducimus aperiam, ratione fuga blanditiis maiores.</p>
</div>
</div>
<div class="modal-footer">
<button class="mi-btn btn-danger mi-ripple mi-ripple-light mi-modal-toggle">No</button>
<button class="mi-btn btn-info mi-ripple mi-ripple-light">Confirm</button>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Instead of wrestling with margin and padding for centering, just use the standard left position and -50% x-axis translation.
// common close button
$('.mi-modal-toggle').click(function() {
$(this).closest(".mi-modal").toggleClass('modal-visible');
});
// explicit button per modal
$('.mi-modal-toggle').on('click', function(e) {
var modalid = $(this).data("modal-id");
$(`.mi-modal[data-modal-id='${modalid}']`).toggleClass('modal-visible');
});
html,
body {
margin: 0;
padding: 0;
}
.mi-modal {
position: fixed;
z-index: 10000;
top: 0;
visibility: hidden;
height: 100%;
box-sizing: border-box;
width: 100%;
}
.mi-modal.modal-visible {
visibility: visible;
}
.mi-modal-overlay {
position: fixed;
z-index: 10;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: hsla(0, 0%, 0%, 0.4);
visibility: hidden;
opacity: 0;
transition: visibility 0s linear 0.3s, opacity 0.3s;
box-sizing: border-box;
}
.mi-modal.modal-visible .mi-modal-overlay {
opacity: 1;
visibility: visible;
transition-delay: 0s;
}
.mi-modal-wrapper {
position: absolute;
z-index: 9999;
top: 3em;
width: 100%;
max-width: 400px;
background-color: #fff;
box-shadow: 0 0 1.5em hsla(0, 0%, 0%, 0.35);
box-sizing: border-box;
left: 50%;
transform: translateX(-50%);
}
.mi-modal-transition {
transition: all 0.4s;
transform: translate(-50%, -10%);
opacity: 0;
}
.mi-modal.modal-visible .mi-modal-transition {
transform: translate(-50%, 0);
opacity: 1;
}
.mi-modal-header,
.mi-modal-content {
padding: 1em;
}
.mi-modal-header {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: space-between;
position: relative;
background-color: #fff;
box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.06);
border-bottom: 1px solid #e8e8e8;
}
.mi-modal-close {
margin: -0.5rem -0.5rem -0.5rem auto;
color: #aaa;
background: #edcfa5;
border: 0;
font-size: 20px;
font-weight: 700;
position: absoloute;
box-sizing: content-box;
width: 1em;
height: 1em;
padding: 0.3em;
color: #000;
border: 0;
border-radius: 0.25rem;
opacity: .5;
}
.mi-modal-close:hover {
color: #777;
}
.mi-modal-heading {
font-size: 1.125em;
margin: 0px 8px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.mi-modal-content>*:first-child {
margin-top: 0;
}
.mi-modal-content>*:last-child {
margin-bottom: 0;
}
.mi-modal.modal-scroll .mi-modal-content {
max-height: 60vh;
overflow-y: scroll;
}
.mi-modal.modal-scroll .mi-modal-wrapper {
position: absolute;
z-index: 9999;
top: 2em;
left: 50%;
width: 32em;
margin-left: -16em;
background-color: #CDf;
box-shadow: 0 0 1.5em hsla(0, 0%, 0%, 0.35);
box-sizing: border-box;
}
.modal-footer {
display: flex;
flex-wrap: wrap;
flex-shrink: 0;
align-items: center;
/* justify-content: flex-end; */
padding: 0.75rem;
border-top: 1px solid #dee2e6;
border-bottom-right-radius: calc(0.3rem - 1px);
border-bottom-left-radius: calc(0.3rem - 1px);
}
.modal-footer>* {
margin: 0.25rem;
}
<button class="mi-modal-toggle" data-modal-id="modal1">Show modal</button>
<div class="mi-modal" data-modal-id="modal1">
<div class="mi-modal-overlay mi-modal-toggle"></div>
<div class="mi-modal-wrapper mi-modal-transition">
<div class="mi-modal-header">
<h2 class="mi-modal-heading">This is a modal</h2>
<button class="mi-modal-close mi-modal-toggle">×</button>
</div>
<div class="mi-modal-body">
<div class="mi-modal-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit eum delectus, libero, accusantium dolores inventore obcaecati placeat cum sapiente vel laboriosam similique totam id ducimus aperiam, ratione fuga blanditiis maiores.</p>
</div>
</div>
<div class="modal-footer">
<button class="mi-btn btn-danger mi-ripple mi-ripple-light mi-modal-toggle">No</button>
<button class="mi-btn btn-info mi-ripple mi-ripple-light">Confirm</button>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

For center alignment of modal add the following css code
.mi-modal.modal-visible {
margin: auto;
inset: 0;
}
.mi-modal-wrapper.mi-modal-transition {
top: 50%;
left: 50%;
transform: translate(-50%, -50%) !important;
}
// common close button
$('.mi-modal-toggle').click(function() {
$(this).closest(".mi-modal").toggleClass('modal-visible');
});
// explicit button per modal
$('.mi-modal-toggle').on('click', function(e) {
var modalid = $(this).data("modal-id");
$(`.mi-modal[data-modal-id='${modalid}']`).toggleClass('modal-visible');
});
.mi-modal {
position: fixed;
z-index: 10000; /* 1 */
top: 0;
left: 0;
visibility: hidden;
height: 100%;
box-sizing: border-box;
padding: 10%;
width: 80%; /* 94% + 3% +3% = 100% */
max-width: 400px;
}
.mi-modal.modal-visible {
visibility: visible;
}
.mi-modal-overlay {
position: fixed;
z-index: 10;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: hsla(0, 0%, 0%, 0.4);
visibility: hidden;
opacity: 0;
transition: visibility 0s linear 0.3s, opacity 0.3s;
box-sizing: border-box;
}
.mi-modal.modal-visible .mi-modal-overlay {
opacity: 1;
visibility: visible;
transition-delay: 0s;
}
.mi-modal-wrapper {
position: absolute;
z-index: 9999;
top: 3em;
width: 100%;
background-color: #fff;
box-shadow: 0 0 1.5em hsla(0, 0%, 0%, 0.35);
box-sizing: border-box;
margin: auto auto !important;
}
.mi-modal-transition {
transition: all 0.4s;
transform: translateY(-10%);
opacity: 0;
}
.mi-modal.modal-visible .mi-modal-transition {
transform: translateY(0);
opacity: 1;
}
.mi-modal-header,
.mi-modal-content {
padding: 1em;
}
.mi-modal-header {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: space-between;
position: relative;
background-color: #fff;
box-shadow: 0 1px 2px hsla(0, 0%, 0%, 0.06);
border-bottom: 1px solid #e8e8e8;
}
.mi-modal-close {
margin: -0.5rem -0.5rem -0.5rem auto;
color: #aaa;
background: #edcfa5;
border: 0;
font-size: 20px;
font-weight: 700;
position: absoloute;
box-sizing: content-box;
width: 1em;
height: 1em;
padding: 0.3em;
color: #000;
border: 0;
border-radius: 0.25rem;
opacity: .5;
}
.mi-modal-close:hover {
color: #777;
}
.mi-modal-heading {
font-size: 1.125em;
margin: 0px 8px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.mi-modal-content>*:first-child {
margin-top: 0;
}
.mi-modal-content>*:last-child {
margin-bottom: 0;
}
.mi-modal.modal-scroll .mi-modal-content {
max-height: 60vh;
overflow-y: scroll;
}
.mi-modal.modal-scroll .mi-modal-wrapper {
position: absolute;
z-index: 9999;
top: 2em;
left: 50%;
width: 32em;
margin-left: -16em;
background-color: #CDf;
box-shadow: 0 0 1.5em hsla(0, 0%, 0%, 0.35);
box-sizing: border-box;
}
.modal-footer {
display: flex;
flex-wrap: wrap;
flex-shrink: 0;
align-items: center; /* justify-content: flex-end; */
padding: 0.75rem;
border-top: 1px solid #dee2e6;
border-bottom-right-radius: calc(0.3rem - 1px);
border-bottom-left-radius: calc(0.3rem - 1px);
}
.modal-footer>* {
margin: 0.25rem;
}
.mi-modal.modal-visible {
margin: auto;
inset: 0;
}
.mi-modal-wrapper.mi-modal-transition {
top: 50%;
left: 50%;
transform: translate(-50%, -50%) !important;
}
<button class="mi-modal-toggle" data-modal-id="modal1">Show modal</button>
<div class="mi-modal" data-modal-id="modal1">
<div class="mi-modal-overlay mi-modal-toggle"></div>
<div class="mi-modal-wrapper mi-modal-transition">
<div class="mi-modal-header">
<h2 class="mi-modal-heading">This is a modal</h2>
<button class="mi-modal-close mi-modal-toggle">×</button>
</div>
<div class="mi-modal-body">
<div class="mi-modal-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit eum delectus, libero, accusantium dolores inventore obcaecati placeat cum sapiente vel laboriosam similique totam id ducimus aperiam, ratione fuga blanditiis maiores.</p>
</div>
</div>
<div class="modal-footer">
<button class="mi-btn btn-danger mi-ripple mi-ripple-light mi-modal-toggle">No</button>
<button class="mi-btn btn-info mi-ripple mi-ripple-light">Confirm</button>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Related

Create simple CSS modal window

The goal is to create a simple and CSS-only modal window (popup), when the user clicks a link.
With no dependencies or any kind of script, and with as less code as possible.
.box {
width: 40%;
margin: 0 auto;
background: rgba(255,255,255,0.2);
padding: 35px;
border: 2px solid #fff;
border-radius: 20px/50px;
background-clip: padding-box;
text-align: center;
}
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 5s ease-in-out;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
<div class="box">
<a class="button" href="#popup1">Open</a>
</div>
<div id="popup1" class="overlay">
<div class="popup">
<h2>Here i am</h2>
<a class="close" href="#">×</a>
</div>
</div>
I created this simple modal window:
.exit-intent {
opacity: 0;
visibility: hidden;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-align: center;
background-color: rgba(255, 255, 255, .8);
z-index: 7;
display: flex;
flex-direction: column;
height: 100vh;
overflow-y: auto
}
.exit-intent {
position: fixed;
max-width: 500px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.9);
visibility: hidden;
opacity: 0;
z-index: 1;
}
.exit-intent:target {
visibility: visible;
opacity: 1;
}
.exit-intent-close {
position: absolute;
max-width: 500px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.9);
}
.exit-intent .close {
position: absolute;
right: 5px;
top: 5px;
padding: 5px;
color: #000;
font-size: 2em;
line-height: 0.6em;
font-weight: bold;
}
.exit-intent .close:hover {
color: #999;
}
.close-exit-intent {
background: rgba(0, 0, 0, 0.7);
cursor: default;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
visibility: hidden;
}
.exit-intent:target+.close-exit-intent {
opacity: 1;
visibility: visible;
}
Link
<div id="exit-intent" class="exit-intent">
×
<h2>Window</h2>
</div>

How to prevent absolutely positioned img from moving

So I have a flexbox with some elements and over the flexbox, I want to put a foreground which should be absolutely positioned. What I am trying to achieve is, that with window resize, the foreground will change its size but not its position. Currently, when the window is small, the image is moving up.
main div.heroBoxContainer {
display: flex;
display: -ms-flexbox;
height: inherit;
margin: 0 auto;
max-width: 1280px;
padding: 0;
position: relative;
z-index: 4;
align-items: center;
}
main div.heroBoxContainer .hGroup {
color: white;
display: block;
height: auto;
margin: 0 0 0 0;
width: 100%;
z-index: 5;
}
div.heroBoxContainer h1.heroHeadline,
div.heroBoxContainer h1.heroHeadline {
font-size: 2rem;
font-weight: 400;
line-height: 2.5rem;
margin: 0 0 0 10rem;
transform: skew(-6deg) rotate(-6deg);
}
div.heroBoxContainer p.subHeadline {
font-size: 4rem;
font-weight: bolder;
margin: 0rem 0 0 10rem;
transform: skew(-6deg) rotate(-6deg);
}
div.heroBoxContainer p.priceHeadline {
font-size: 4rem;
font-weight: bolder;
margin: 0rem 0 8rem 10rem;
color: rgba(255, 220, 58, 1);
transform: skew(-6deg) rotate(-6deg);
}
div img.heroForeground {
position: absolute;
top: 8vh;
right: 0;
max-width: 80%;
z-index: 2;
left: 15vw;
}
#carousel {
overflow: hidden;
white-space: nowrap;
width: 100vw;
height: 75vh;
position: relative;
}
.slide-image {
width: 100vw;
height: 75vh;
background-position: center;
display: inline-block;
background-size: cover;
position: relative;
}
<section id="carousel">
<div class="slide-image" id="slide1">
<div class="heroBoxContainer">
<img src="https://www.cheopstech.cz/wp-content/uploads/2017/06/placeholder-3.png" class="heroForeground">
<div class="hGroup">
<h1 class="heroHeadline">LOREM IPSUM<br> DOLOR SIT AMET</h1>
<p class="subHeadline">LOREM IPSUM:</p>
<p class="priceHeadline">LOREM IPSUM</p>
LOREM IPSUM
</div>
</div>
</div>
</section>
Your absolutely positioned img.heroForeground has it's top set to 8vh which will change as the window size changes during resize. This is leading to the unwanted shifting during window resize. Instead, center the element using transform/translate.
div img.heroForeground {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
…
}
Demo
main div.heroBoxContainer {
display: flex;
display: -ms-flexbox;
height: inherit;
margin: 0 auto;
max-width: 1280px;
padding: 0;
position: relative;
z-index: 4;
align-items: center;
}
main div.heroBoxContainer .hGroup {
color: white;
display: block;
height: auto;
margin: 0 0 0 0;
width: 100%;
z-index: 5;
}
div.heroBoxContainer h1.heroHeadline,
div.heroBoxContainer h1.heroHeadline {
font-size: 2rem;
font-weight: 400;
line-height: 2.5rem;
margin: 0 0 0 10rem;
transform: skew(-6deg) rotate(-6deg);
}
div.heroBoxContainer p.subHeadline {
font-size: 4rem;
font-weight: bolder;
margin: 0rem 0 0 10rem;
transform: skew(-6deg) rotate(-6deg);
}
div.heroBoxContainer p.priceHeadline {
font-size: 4rem;
font-weight: bolder;
margin: 0rem 0 8rem 10rem;
color: rgba(255, 220, 58, 1);
transform: skew(-6deg) rotate(-6deg);
}
div img.heroForeground {
position: absolute;
max-width: 80%;
z-index: 2;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
#carousel {
overflow: hidden;
white-space: nowrap;
width: 100vw;
height: 75vh;
position: relative;
}
.slide-image {
width: 100vw;
height: 75vh;
background-position: center;
display: inline-block;
background-size: cover;
position: relative;
}
<section id="carousel">
<div class="slide-image" id="slide1">
<div class="heroBoxContainer">
<img src="https://www.cheopstech.cz/wp-content/uploads/2017/06/placeholder-3.png" class="heroForeground">
<div class="hGroup">
<h1 class="heroHeadline">LOREM IPSUM<br> DOLOR SIT AMET</h1>
<p class="subHeadline">LOREM IPSUM:</p>
<p class="priceHeadline">LOREM IPSUM</p>
LOREM IPSUM
</div>
</div>
</div>
</section>
jsFiddle

Stop scrolling at the top of slider when click link href target id pure css

I have a pure css slider here but the problem is I dont want to scroll at the top of the slider when click the bullet and arrow navigation from the extra space.
Is there any way to achieve this with pure html or css?
I tried a href="#s3/" and a href="#s3!" but it's not working.
Looking for pure html and css solution since we have no script cms. Thanks
.wrapper {
overflow:scroll;
height:700px;
}
/* For visual purpose only */
.extra-space {
width: 100%;
height: 300px;
background: red;
line-height: 300px;
text-align: center;
}
/*slider*/
.CSSgal {
position: relative;
overflow: hidden;
/* Or set a fixed height */
}
/* SLIDER */
.CSSgal .slider {
height: 100%;
white-space: nowrap;
font-size: 0;
transition: 0.8s;
}
/* SLIDES */
.CSSgal .slider>* {
display: inline-block;
white-space: normal;
vertical-align: top;
height: 100%;
width: 100%;
background: none 50% no-repeat;
background-size: cover;
}
/* PREV/NEXT, CONTAINERS & ANCHORS */
.CSSgal .prevNext {
position: absolute;
z-index: 1;
top: 50%;
width: 100%;
height: 0;
}
.CSSgal .prevNext>div+div {
visibility: hidden;
/* Hide all but first P/N container */
}
.CSSgal .prevNext a {
text-align: center;
opacity: 0.7;
-webkit-transition: 0.3s;
transition: 0.3s;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
border-radius: 0;
position: absolute;
width: 30px;
height: 30px;
display: inline-block;
padding: 3px;
}
.CSSgal .prevNext .right {
right: 30px;
left: auto;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
background-image: none !important;
transition: all .3s;
}
.CSSgal .prevNext .left {
left: 30px;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-image: none !important;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
transition: all .3s;
}
.CSSgal .prevNext .left:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -76.5px -7px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext .right:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -49px -7.5px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext a:hover {
background-color: #ebebeb!important;
}
.CSSgal .prevNext a+a {
left: auto;
right: 0;
}
/* NAVIGATION */
.CSSgal .bullets {
position: absolute;
z-index: 2;
bottom: 0;
padding: 10px 0;
width: 100%;
text-align: center;
}
.CSSgal .bullets>a {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
background: #f8d000;
border: 2px solid #f8d000;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.CSSgal .bullets a span {
display: none;
}
.right {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
.left {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
}
.CSSgal .bullets>a+a {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
/* Dim all but first */
}
.CSSgal .bullets>a:hover {
background: #f8d000;
border: 2px solid #f8d000;
}
/* NAVIGATION BUTTONS */
/* ALL: */
.CSSgal>s:target~.bullets>* {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
}
/* ACTIVE */
#s1:target~.bullets>*:nth-child(1) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s2:target~.bullets>*:nth-child(2) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s3:target~.bullets>*:nth-child(3) {
background: #f8d000;
border: 2px solid #f8d000;
}
/* More slides? Add here more rules */
/* PREV/NEXT CONTAINERS VISIBILITY */
/* ALL: */
.CSSgal>s:target~.prevNext>* {
visibility: hidden;
}
/* ACTIVE: */
#s1:target~.prevNext>*:nth-child(1) {
visibility: visible;
}
#s2:target~.prevNext>*:nth-child(2) {
visibility: visible;
}
#s3:target~.prevNext>*:nth-child(3) {
visibility: visible;
}
/* More slides? Add here more rules */
/* SLIDER ANIMATION POSITIONS */
#s1:target~.slider {
transform: translateX(0%);
-webkit-transform: translateX(0%);
}
#s2:target~.slider {
transform: translateX(-100%);
-webkit-transform: translateX(-100%);
}
#s3:target~.slider {
transform: translateX(-200%);
-webkit-transform: translateX(-200%);
}
<div class="wrapper">
<section class="extra-space">
<h1>Extra space</h1>
</section>
<section class="mb-4">
<div class="container-fluid">
<div class="row">
<div class="col-12 p-0">
<div class="CSSgal">
<!-- Don't wrap targets in parent -->
<s id="s1"></s>
<s id="s2"></s>
<s id="s3"></s>
<div class="slider">
<div>
<a href="/en-ae/brands/troop-london/">
<img src="https://dummyimage.com/600x400/000/fff">
</a>
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
</div>
<div class="prevNext">
<div>
<a class="left" href="#s3"></a>
<a class="right" href="#s2"></a>
</div>
<div>
<a class="left" href="#s1"></a>
<a class="right" href="#s3"></a>
</div>
<div>
<a class="left" href="#s2"></a>
<a class="right" href="#s1"></a>
</div>
</div>
<div class="bullets">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
i manage to fix this by add s{display: none;} which hiding the id.
/*** the solution ***/
s{
display: none;
}
.wrapper {
overflow:scroll;
height:700px;
}
/* For visual purpose only */
.extra-space {
width: 100%;
height: 300px;
background: red;
line-height: 300px;
text-align: center;
}
/*slider*/
.CSSgal {
position: relative;
overflow: hidden;
/* Or set a fixed height */
}
/* SLIDER */
.CSSgal .slider {
height: 100%;
white-space: nowrap;
font-size: 0;
transition: 0.8s;
}
/* SLIDES */
.CSSgal .slider>* {
display: inline-block;
white-space: normal;
vertical-align: top;
height: 100%;
width: 100%;
background: none 50% no-repeat;
background-size: cover;
}
/* PREV/NEXT, CONTAINERS & ANCHORS */
.CSSgal .prevNext {
position: absolute;
z-index: 1;
top: 50%;
width: 100%;
height: 0;
}
.CSSgal .prevNext>div+div {
visibility: hidden;
/* Hide all but first P/N container */
}
.CSSgal .prevNext a {
text-align: center;
opacity: 0.7;
-webkit-transition: 0.3s;
transition: 0.3s;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
border-radius: 0;
position: absolute;
width: 30px;
height: 30px;
display: inline-block;
padding: 3px;
}
.CSSgal .prevNext .right {
right: 30px;
left: auto;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
background-image: none !important;
transition: all .3s;
}
.CSSgal .prevNext .left {
left: 30px;
position: absolute;
top: 50%;
width: 50px;
height: 50px;
border-radius: 50%;
background-image: none !important;
background-color: hsla(0, 0%, 92.2%, .6) !important;
z-index: 1;
cursor: pointer;
transition: all .3s;
}
.CSSgal .prevNext .left:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -76.5px -7px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext .right:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
background: url(https://new.brandsforless.ae/static/media/m-sprite.7b312d28.png) no-repeat;
background-size: 300px;
display: inline-block;
background-position: -49px -7.5px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.CSSgal .prevNext a:hover {
background-color: #ebebeb!important;
}
.CSSgal .prevNext a+a {
left: auto;
right: 0;
}
/* NAVIGATION */
.CSSgal .bullets {
position: absolute;
z-index: 2;
bottom: 0;
padding: 10px 0;
width: 100%;
text-align: center;
}
.CSSgal .bullets>a {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
background: #f8d000;
border: 2px solid #f8d000;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.CSSgal .bullets a span {
display: none;
}
.right {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
.left {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
}
.CSSgal .bullets>a+a {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
/* Dim all but first */
}
.CSSgal .bullets>a:hover {
background: #f8d000;
border: 2px solid #f8d000;
}
/* NAVIGATION BUTTONS */
/* ALL: */
.CSSgal>s:target~.bullets>* {
background-color: rgba(255, 255, 255, 0.5);
border: 2px solid #999;
}
/* ACTIVE */
#s1:target~.bullets>*:nth-child(1) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s2:target~.bullets>*:nth-child(2) {
background: #f8d000;
border: 2px solid #f8d000;
}
#s3:target~.bullets>*:nth-child(3) {
background: #f8d000;
border: 2px solid #f8d000;
}
/* More slides? Add here more rules */
/* PREV/NEXT CONTAINERS VISIBILITY */
/* ALL: */
.CSSgal>s:target~.prevNext>* {
visibility: hidden;
}
/* ACTIVE: */
#s1:target~.prevNext>*:nth-child(1) {
visibility: visible;
}
#s2:target~.prevNext>*:nth-child(2) {
visibility: visible;
}
#s3:target~.prevNext>*:nth-child(3) {
visibility: visible;
}
/* More slides? Add here more rules */
/* SLIDER ANIMATION POSITIONS */
#s1:target~.slider {
transform: translateX(0%);
-webkit-transform: translateX(0%);
}
#s2:target~.slider {
transform: translateX(-100%);
-webkit-transform: translateX(-100%);
}
#s3:target~.slider {
transform: translateX(-200%);
-webkit-transform: translateX(-200%);
}
<div class="wrapper">
<section class="extra-space">
<h1>Extra space</h1>
</section>
<section class="mb-4">
<div class="container-fluid">
<div class="row">
<div class="col-12 p-0">
<div class="CSSgal">
<!-- Don't wrap targets in parent -->
<s id="s1"></s>
<s id="s2"></s>
<s id="s3"></s>
<div class="slider">
<div>
<a href="/en-ae/brands/troop-london/">
<img src="https://dummyimage.com/600x400/000/fff">
</a>
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
<div>
<img src="https://dummyimage.com/600x400/000/fff">
</div>
</div>
<div class="prevNext">
<div>
<a class="left" href="#s3"></a>
<a class="right" href="#s2"></a>
</div>
<div>
<a class="left" href="#s1"></a>
<a class="right" href="#s3"></a>
</div>
<div>
<a class="left" href="#s2"></a>
<a class="right" href="#s1"></a>
</div>
</div>
<div class="bullets">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
</div>
</div>
</div>
</div>
</section>
</div>

How to fix to getting automatic flip on hover?

I think something is not letting me get flip on hovering over the card.
I have tried .card:hover .front:hover and so many other but it is not working. Sorry been awake for 3 days cant wrap it, and i have the project due in couple of hours. it must be something i have been missing, if i could get some help id appreciate it
<div class="card">
<input type="checkbox" id="card" class="more">
<div class="content">
<div class="front" style="background-image: url()">
<div class="inner">
<h2></h2>
</div>
</div>
<div class="back">
<div class="inner">
<div class="info">
<span>1</span>
</div>
<div class="info">
<span>2</span>
<div class="info">
<span>3</span>
</div>
<div class="description">
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptatem unde?</p>
<ul>
<li>Lorem ipsum dolor sit amet.</li>
<li>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</li>
<li>Lorem ipsum dolor sit amet consectetur.</li>
<li>Lorem ipsum dolor sit amet.</li>
</ul>
</div>
<div class="type">Card</div>
<div class="button">
<a href='https://www.google.com/'><button>Link To Google</button></a>
</div>
</div>
</div>
</div>
* {
box-sizing: border-box;
}
body {
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
font-family: 'Montserrat', sans-serif;
}
.wrapper {
display: flex;
flex-flow: row wrap;
justify-content: center;
}
.card {
width: 300px;
height: 280px;
perspective: 1500px;
}
.card:hover {
transition: rotateY(180deg);
}
.card .content {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.8s cubic-bezier(0.75, 0, 0.85, 1);
}
.front,
.back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
backface-visibility: hidden;
transform-style: preserve-3d;
border-radius: 6px;
}
.front .inner,
.back .inner {
height: 100%;
display: grid;
padding: 1.5em;
transform: translateZ(80px) scale(0.94);
}
.front {
background-color: #fff;
background-size: cover;
background-position: center center;
}
.front:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
border-radius: 6px;
backface-visibility: hidden;
background: linear-gradient(40deg, rgba(67, 138, 243, 0.7), rgba(255, 242, 166, 0.7));
}
.front .inner {
grid-template-rows: 5fr 1fr 1fr 2fr 1fr;
justify-items: center;
}
.front h2 {
grid-row: 2;
margin-bottom: 0.3em;
text-transform: uppercase;
letter-spacing: 3px;
color: #fff;
font-weight: 500;
text-shadow: 0 0 6px rgba(0, 0, 0, 0.1);
}
.back {
transform: rotateY(180deg);
background-color: #fff;
border: 2px solid #f0f0f0;
}
.back .inner {
grid-template-rows: 1fr 2fr 1fr 2fr 14fr 1fr 1fr;
grid-template-columns: repeat(4, auto);
grid-column-gap: 0.8em;
justify-items: center;
}
.back .info {
position: relative;
display: flex;
align-items: center;
color: #355cc9;
grid-row: 3;
}
.back .info:not(:first-of-type):before {
content: '';
position: absolute;
left: -0.9em;
height: 18px;
width: 1px;
background-color: #ccc;
}
.back .info span {
font-size: 2em;
font-weight: 700;
}
.back .info i {
font-size: 1.2em;
}
.back .info i:before {
background: linear-gradient(40deg, #355cc9, #438af3);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
}
.back .info .icon {
margin-left: 0.3em;
}
.back .info .icon span {
display: block;
margin-top: -0.25em;
font-size: 0.8em;
font-weight: 600;
white-space: nowrap;
}
.back .description {
grid-row: 5;
grid-column: 1/-1;
font-size: 0.70em;
border-radius: 5px;
font-weight: 600;
line-height: 1.4em;
overflow: auto;
color: #355cc9;
padding-right: 10px;
}
.back .button {
grid-column: 1/-1;
justify-self: center;
}
.button {
grid-row: -1;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 600;
cursor: pointer;
display: block;
padding: 0 1.5em;
height: 2em;
line-height: 2.0em;
min-width: 3em;
background-color: transparent;
border: solid 2px #fff;
color: #fff;
border-radius: 4px;
text-align: center;
left: 50%;
backface-visibility: hidden;
transition: 0.3s ease-in-out;
text-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
}
.button:hover {
background-color: #fff;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
text-shadow: none;
color: #355cc9;
}
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #859ddf;
}
::-webkit-scrollbar-thumb:hover {
background: #355cc9;
}
So the fixes are:
you're using card as ID in HTML but in css it was used as class. I have changed HTML to class="card".
Moreover, rotateY(180deg) works with transform property.
* {
box-sizing: border-box;
}
body {
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
font-family: 'Montserrat', sans-serif;
}
.wrapper {
display: flex;
flex-flow: row wrap;
justify-content: center;
}
.card {
width: 300px;
height: 280px;
perspective: 1500px;
}
.card:hover {
transition: width 2s, height 4s;
transform: rotateY(180deg);
}
.card .content {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.8s cubic-bezier(0.75, 0, 0.85, 1);
}
.front,
.back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
backface-visibility: hidden;
transform-style: preserve-3d;
border-radius: 6px;
}
.front .inner,
.back .inner {
height: 100%;
display: grid;
padding: 1.5em;
transform: translateZ(80px) scale(0.94);
}
.front {
background-color: #fff;
background-size: cover;
background-position: center center;
}
.front:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
border-radius: 6px;
backface-visibility: hidden;
background: linear-gradient(40deg, rgba(67, 138, 243, 0.7), rgba(255, 242, 166, 0.7));
}
.front .inner {
grid-template-rows: 5fr 1fr 1fr 2fr 1fr;
justify-items: center;
}
.front h2 {
grid-row: 2;
margin-bottom: 0.3em;
text-transform: uppercase;
letter-spacing: 3px;
color: #fff;
font-weight: 500;
text-shadow: 0 0 6px rgba(0, 0, 0, 0.1);
}
.back {
transform: rotateY(180deg);
background-color: #fff;
border: 2px solid #f0f0f0;
}
.back .inner {
grid-template-rows: 1fr 2fr 1fr 2fr 14fr 1fr 1fr;
grid-template-columns: repeat(4, auto);
grid-column-gap: 0.8em;
justify-items: center;
}
.back .info {
position: relative;
display: flex;
align-items: center;
color: #355cc9;
grid-row: 3;
}
.back .info:not(:first-of-type):before {
content: '';
position: absolute;
left: -0.9em;
height: 18px;
width: 1px;
background-color: #ccc;
}
.back .info span {
font-size: 2em;
font-weight: 700;
}
.back .info i {
font-size: 1.2em;
}
.back .info i:before {
background: linear-gradient(40deg, #355cc9, #438af3);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
}
.back .info .icon {
margin-left: 0.3em;
}
.back .info .icon span {
display: block;
margin-top: -0.25em;
font-size: 0.8em;
font-weight: 600;
white-space: nowrap;
}
.back .description {
grid-row: 5;
grid-column: 1/-1;
font-size: 0.70em;
border-radius: 5px;
font-weight: 600;
line-height: 1.4em;
overflow: auto;
color: #355cc9;
padding-right: 10px;
}
.back .button {
grid-column: 1/-1;
justify-self: center;
}
.button {
grid-row: -1;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 600;
cursor: pointer;
display: block;
padding: 0 1.5em;
height: 2em;
line-height: 2.0em;
min-width: 3em;
background-color: transparent;
border: solid 2px #fff;
color: #fff;
border-radius: 4px;
text-align: center;
left: 50%;
backface-visibility: hidden;
transition: 0.3s ease-in-out;
text-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
}
.button:hover {
background-color: #fff;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
text-shadow: none;
color: #355cc9;
}
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #859ddf;
}
::-webkit-scrollbar-thumb:hover {
background: #355cc9;
}
<div class="card">
<input type="checkbox" class="card" class="more">
<div class="content">
<div class="front">
<div class="inner">
<h2>Hello</h2>
</div>
</div>
<div class="back">
<div class="inner">
<div class="info">
<span>1</span>
</div>
<div class="info">
<span>2</span>
<div class="info">
<span>3</span>
</div>
<div class="description">
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptatem unde?</p>
<ul>
<li>Lorem ipsum dolor sit amet.</li>
<li>Lorem ipsum dolor sit, amet consectetur adipisicing elit.</li>
<li>Lorem ipsum dolor sit amet consectetur.</li>
<li>Lorem ipsum dolor sit amet.</li>
</ul>
</div>
<div class="type">Card</div>
<div class="button">
<a href='https://www.google.com/'><button>Link To Google</button></a>
</div>
</div>
</div>
</div>
Hope this helps!

Split diagonally div in 3 divs

Trying to achieve something as the image suggests, and not sure what would be the best approach because I want to play with the divs heights when hovering.
The container div must be 100% width, 100% height and the divs inside fully responsive.
Borders, pseudos or background wont work for this particular case.
html
<div class="container">
<div class="top"></div>
<div class="center">
<p>text text</p>
</div>
<div class="bottom"></div>
</div>
css
.container{
width: 100%;
height: 100vh;
overflow: hidden;
// transform: skewY(-45deg);
// transform: rotate(-45deg);
}
.top, .bottom {
width: 100%;
height: calc(50% - 20px);
}
.top {
background: black;
}
.bottom {
background: grey;
}
.center {
background: green;
height: 40px;
width: 100%;
}
p {
color: white;
line-height: 10px;
text-align: center;
}
In the jsfiddle you will find both rotate and skewY commented.
Hope it works for you.
If want pure CSS solution, you can try this.
It uses Area of Traingle and all other calculations.
I have given width: 300px;height:600px; to parent DIV and then done the calculations. You may need to change accordingly.
I use SCSS for writing my CSS, so its easy for me. Though I have tried to do more of calculation using calc to make it more CSS friendly.
.parent {
position: relative;
width: 300px;
overflow: hidden;
display: flex;
flex-direction: column;
height: 600px;
/* Not relevant. this was used to show a Guide-point of intersection of one of triangle's side.
&:before {
content: '';
width: 2px;
height: 2px;
background: #000;
position: absolute;
left: calc(50% - 1px);
top: -1px;
display: block;
}
&:after {
content: '';
width: 2px;
height: 2px;
background: #000;
position: absolute;
left: calc(50% - 1px);
bottom: -1px;
display: block;
}
*/
}
.child {
min-height: 20px;
padding: 15px;
transform: skewY(-30deg);
transition: all 0.2s ease;
display: flex;
align-content: center;
align-items: center;
}
.child:hover {
height: calc(100% - 40px);
}
.child:hover~.child {
height: 20px;
}
.child__inner {
transform: skewY(30deg);
color: #fff;
}
.child--top {
background: tomato;
height: calc(50% - 20px);
margin-top: calc((150px / 1.73)* -1);
padding-top: calc((150px / 1.73) * 2);
}
.child--middle {
background: DeepSkyBlue;
}
.child--bottom {
background: MediumSeaGreen;
height: calc(50% - 20px);
margin-bottom: calc((150px / 1.73)* -1);
padding-bottom: calc((150px / 1.73) * 2);
}
<div class="parent">
<div class="child child--top">
<div class="child__inner">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus, accusantium. Illo minima ipsa, at dignissimos perspiciatis nesciunt. Hic quae porro assumenda possimus fugit, velit eaque magni, reiciendis veritatis perspiciatis recusandae?
</div>
</div>
<div class="child child--middle">
<div class="child__inner">
</div>
</div>
<div class="child child--bottom">
<div class="child__inner">
</div>
</div>
</div>
If you want to check the SCSS, below is the code.
.parent {
position: relative;
width: 300px;
overflow: hidden;
display: flex;
flex-direction: column;
height: 600px;
/* Not relevant. this was used to show a Guide-point of intersection of one of triangle's side.
&:before {
content: '';
width: 2px;
height: 2px;
background: #000;
position: absolute;
left: calc(50% - 1px);
top: -1px;
display: block;
}
&:after {
content: '';
width: 2px;
height: 2px;
background: #000;
position: absolute;
left: calc(50% - 1px);
bottom: -1px;
display: block;
}
*/
}
.child {
min-height: 20px;
padding: 15px;
transform: skewY(-30deg);
transition: all 0.2s ease;
display: flex;
align-content: center;
align-items: center;
&:hover {
height: calc(100% - 40px);
}
&:hover ~ .child {
height: 20px;
}
&__inner {
transform: skewY(30deg);
color: #fff;
}
&--top {
background: tomato;
height: calc(50% - 20px);
margin-top: calc((150px / 1.73)* -1);
padding-top: calc((150px / 1.73) * 2);
}
&--middle {
background: DeepSkyBlue;
}
&--bottom {
background: MediumSeaGreen;
height: calc(50% - 20px);
margin-bottom: calc((150px / 1.73)* -1);
padding-bottom: calc((150px / 1.73) * 2);
}
}
Reference: Area of Traingle and Sides height/width
.gradient{ width: 250px; height: 500px;
background: -webkit-linear-gradient(-45deg, #000 0% , #000 45%, #53ff00 45%, #53ff00 50%, #7e7e7e 50%, #7e7e7e 100%);
background: -moz-linear-gradient(-45deg, #000 0% , #000 45%, #53ff00 45%, #53ff00 50%, #7e7e7e 50%, #7e7e7e 100%);
background: linear-gradient(-45deg, #000 0% , #000 45%, #53ff00 45%, #53ff00 50%, #7e7e7e 50%, #7e7e7e 100%);
}
<div class="gradient"></div>
You can also use linear gradient
Its so easy use border style:
#id1 {
background-color: #53ff00;
position: relative;
width:100px;
}
#id2 {
width: 0;
height: 0;
border-top: 100px solid #000;
border-right: 100px solid transparent;
}
#id3 {
width: 0;
height: 0;
border-bottom: 100px solid #969696;
border-left: 100px solid transparent;
margin-top:-65px
}
#top{
height: 50px;
background-color: #000;
width:100px;
}
#bottom{
height: 50px;
background-color: #969696;
margin-top: -4px;
width:100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="top"></div>
<div id="id1">
<div id="id2"></div>
<div id="id3"></div>
</div>
<div id="bottom"></div>
complete shape of CSS this link : The Shapes of CSS