I am trying to create a skill bar where the background color of the progress slides in but the label for the Skill bar stays in the same place.
.skill-container * {
box-sizing: border-box;
}
.skill-container {
width: 100%;
border-radius: 5px;
background-color: lightgray;
margin: 20px 0;
overflow: hidden;
}
.skill-container .skill {
display: inline-block;
text-align: left;
color: white;
padding: 10px 0 10px 4px;
border-radius: inherit;
background-color: #312E81;
white-space: nowrap;
position: relative;
animation: animateLeft 1s ease-out;
}
#keyframes animateLeft {
from {
left: -100%
}
to {
left: 0
}
}
.skill-container .skill.skill-level-70 {
width: 70%
}
<div class="skill-container">
<span class="skill skill-level-70">CSS</span>
</div>
So far the animation works well, but the only thing I need to figure out is how to keep the text (CSS) on the left and animate the sliding of the background color to show the progress
Use a pseudo element for the background:
.skill-container .skill {
color: white;
background-color: lightgray;
margin: 5px 0;
padding: 10px 0 10px 4px;
overflow: hidden;
border-radius: 5px;
white-space: nowrap;
position: relative;
z-index:0;
}
.skill-container .skill::before {
content: "";
position: absolute;
background-color: #312E81;
border-radius: inherit;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
animation: animateLeft 1s ease-out;
}
#keyframes animateLeft {
from {
transform: translateX(-100%);
}
}
.skill-container .skill.skill-level-70::before {
width: 70%
}
.skill-container .skill.skill-level-40::before {
width: 40%
}
.skill-container .skill.skill-level-100::before {
width: 100%
}
<div class="skill-container">
<div class="skill skill-level-100">CSS</div>
<div class="skill skill-level-70">HTML</div>
<div class="skill skill-level-40">PHP</div>
</div>
You can optimize with CSS variables:
.skill-container .skill {
color: white;
background-color: lightgray;
margin: 5px 0;
padding: 10px 0 10px 4px;
overflow: hidden;
border-radius: 5px;
white-space: nowrap;
position: relative;
z-index:0;
}
.skill-container .skill::before {
content: "";
position: absolute;
background-color: #312E81;
border-radius: inherit;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
width:var(--l,0%);
animation: animateLeft 1s ease-out;
}
#keyframes animateLeft {
from {
transform: translateX(-100%);
}
}
<div class="skill-container">
<div class="skill" style="--l:100%">CSS</div>
<div class="skill" style="--l:70%">HTML</div>
<div class="skill" style="--l:40%">PHP</div>
</div>
Related
When I hover over the square, I want the text "MENU" to go and "Google" and "Youtube" to appear. I gave the opacity value for it. "MENU" text disappears but other texts are not visible. Why is Youtube and Google text not showing?
I gave visibility: visible and visibility: hidden instead of opacity but I still get the same result. Am i selecting the wrong div's?
CSS body {
background-color: aquamarine;
}
.square {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform: scale(4);
}
.div1::after {
position: absolute;
content: "MENU";
right: 27px;
top: 40px;
}
.square:hover div:nth-child(1) {
opacity: 0;
}
.div2::after {
content: "- Google";
position: absolute;
bottom: 25px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(2) {
opacity: 1;
}
.div3::after {
content: "- Youtube";
position: absolute;
bottom: 2px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(3) {
opacity: 1;
}
HTML
<div class="square">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
If you have added content using after , then add after in those hover also to work the way you want.
That is use .square:hover div:nth-child(2):after instead of .square:hover div:nth-child(2) only
It works like this see below snippet :
body {
background-color: aquamarine;
}
.square {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform: scale(4);
}
.div1::after {
position: absolute;
content: "MENU";
right: 27px;
top: 40px;
}
.square:hover div:nth-child(1) {
opacity: 0;
}
.div2::after {
content: "- Google";
position: absolute;
bottom: 25px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(2):after {
opacity: 1;
}
.div3::after {
content: "- Youtube";
position: absolute;
bottom: 2px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(3):after {
opacity: 1;
}
<div class="square">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
I changed your code a bit. See if this does what you need:
I added transform-origin: top left; to prevent the scaling from happening in all directions which caused some of the element to be displayed outside of the viewport.
I got rid of the :after pseudo-elements as they did not contribute to the desired outcome and only complicated things (in my opinion).
CSS body {
background-color: aquamarine;
}
.options {
height: 100px;
margin-top: 5px;
display: none;
}
.options>div {
border: 2px solid gray;
margin-bottom: 4px;
}
.square {
width: 100px;
height: 100px;
border: 1px solid gray;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform-origin: top left;
transform: scale(4);
}
.menu {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.square:hover .options {
display: block;
font-size: 10px;
padding: 2px;
}
.square:hover .menu {
display: none;
}
<div class="square">
<div class="menu">Menu</div>
<div class="options">
<div class="div2">Google</div>
<div class="div3">You Tube</div>
</div>
</div>
In my code, the left border should be removed after .6s even when the cursor is still(hover) on the button
.button {
position: relative;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
padding: 10px 20px;
text-decoration: none;
color: inherit;
font-size: 20px;
}
.button::after {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
height: 0%;
border-left: 1.5px solid black;
transition: 0.6s;
}
.button:hover:after {
transition: .6s;
height: 100%;
/*After hover(after.6s), height should be 0%*/
}
You can use callback function to fetch the end of a transition/animation.
Check out this article:
https://betterprogramming.pub/detecting-the-end-of-css-transition-events-in-javascript-8653ae230dc7
As suggested by #prettyInPink, Here is how you can use keyframes.
.button {
position: relative;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
padding: 10px 20px;
text-decoration: none;
color: inherit;
font-size: 20px;
}
.button::after {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
height: 0%;
border-left: 1.5px solid black;
transition: 0.6s;
}
.button:hover:after {
/**
Added 1.2s to smoothly hide the border
From 0%-50% - .6s
From 50%-100% - .6s
**/
animation: borderAnim 1.2s ease-in-out forwards;
}
#keyframes borderAnim {
0% {
opacity: 1;
height: 0%;
}
50% {
opacity: 1;
height: 100%;
}
100% {
height: 100%;
opacity: 0;
}
}
<button class="button">My Button</button>
I'm using a loader in my application, but I can't manage to properly centre it.
As you are going to see it's slightly moved to left side of the screen.
Here's the fiddle: Loader
Here's the HTML code:
<div class="loader">
<div class="loader__hexagon loader__hexagon--value"></div>
<div class="loader__hexagon loader__hexagon--value"></div>
<div class="loader__hexagon loader__hexagon--value"></div>
</div>
Here's the SCSS code:
.loader-graph-default{
background-color: black;
display: none;
}
.loader-graph-loading{
display: inline;
position: absolute;
z-index: 100;
height: 100%;
width: 100%;
}
.loader {
background: none;
position: relative;
width: 60px;
height: 60px;
margin: auto;
text-align: center;
&__hexagon {
position: absolute;
width: 12px;
height: 20px;
margin: 5px;
transform: rotate(30deg);
animation: fade 1s infinite;
animation-delay: 0s;
background: white;
&--value {
background: #009ECB;
}
&:first-of-type {
top: 20px;
left: -12px;
animation-delay: .4s;
}
&:last-of-type {
top: 20px;
left: 12px;
animation-delay: .2s;
}
&:before {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 12px;
height:20px;
background: inherit;
transform: rotate(-62deg);
}
&:after {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 12px;
height: 20px;
background: inherit;
transform: rotate(62deg);
}
}
}
#keyframes fade{
0%{
opacity: 1;
}
50%{
opacity: .1;
}
100%{
opacity: 1;
}
}
If you go to the fiddle and you inspect the div with the class "loader" you can see that it's not centred.
What am I missing?
when you rotate a div, of course it changes it centre point, so i just repositioned it.
.loader-graph-default{
background-color: black;
display: none;
}
.loader-graph-loading{
display: inline;
position: absolute;
z-index: 100;
height: 100%;
width: 100%;
}
.loader {
background: none;
position: relative;
width: 60px;
height: 60px;
margin: auto;
text-align: center;
&__hexagon {
position: absolute;
width: 12px;
height: 20px;
margin: 5px;
transform: rotate(30deg);
animation: fade 1s infinite;
animation-delay: 0s;
/*background: $uiColor;*/
background: white;
/*
&--carbon {
background: $carbon;
}
&--value {
background: $value;
}
&--research {
background: $research;
}
&--quality {
background: $quality;
}
*/
&--value {
background: #009ECB;
}
&:first-of-type {
top: 20px;
right: 50%;
margin-left: 3px;
animation-delay: 0.4s;
}
&:last-of-type {
top: 20px;
left: 50%;
animation-delay: 0.2s;
margin-left: 6px;
}
&:nth-child(2) {
left: 50%;
margin-left: -6px;
}
&:before {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 12px;
height:20px;
background: inherit;
transform: rotate(-62deg);
}
&:after {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 12px;
height: 20px;
background: inherit;
transform: rotate(62deg);
}
}
}
#keyframes fade{
0%{
opacity: 1;
}
50%{
opacity: .1;
}
100%{
opacity: 1;
}
}
<div class="loader">
<div class="loader__hexagon loader__hexagon--value"></div>
<div class="loader__hexagon loader__hexagon--value"></div>
<div class="loader__hexagon loader__hexagon--value"></div>
</div>
Fiddle
You can set loader width 60px to 48px to resolve this. check updated snippet below..
.loader-graph-default {
background-color: black;
display: none;
}
.loader-graph-loading {
display: inline;
position: absolute;
z-index: 100;
height: 100%;
width: 100%;
}
.loader {
background: none;
position: relative;
width: 48px;
height: 60px;
margin: auto;
text-align: center;
left: 12px;
}
.loader__hexagon {
position: absolute;
width: 12px;
height: 20px;
margin: 5px;
transform: rotate(30deg);
animation: fade 1s infinite;
animation-delay: 0s;
background: white;
}
.loader__hexagon--value {
background: #009ECB;
}
.loader__hexagon:first-of-type {
top: 20px;
left: -12px;
animation-delay: 0.4s;
}
.loader__hexagon:last-of-type {
top: 20px;
left: 12px;
animation-delay: 0.2s;
}
.loader__hexagon:before {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 12px;
height: 20px;
background: inherit;
transform: rotate(-62deg);
}
.loader__hexagon:after {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 12px;
height: 20px;
background: inherit;
transform: rotate(62deg);
}
#keyframes fade {
0% {
opacity: 1;
}
50% {
opacity: 0.1;
}
100% {
opacity: 1;
}
}
<div class="loader">
<div class="loader__hexagon loader__hexagon--value"></div>
<div class="loader__hexagon loader__hexagon--value"></div>
<div class="loader__hexagon loader__hexagon--value"></div>
</div>
You have added left:-12px to the first of div with class "loader__hexagon loader__hexagon--value", which shifts the whole block to the left by -12px.
Also the width of the Loader is not 60px.
The style should be as given below :
.loader__hexagon:first-of-type {
top: 20px;
animation-delay: 0.4s;}
Add a style for second child:
.loader__hexagon:nth-child(2) {
left: 12px; }
Edit style of third child:
.loader__hexagon:last-of-type {
top: 20px;
left: 23px;
animation-delay: 0.2s; }
Reduce the width of the loader to 45px:
.loader {
background: none;
position: relative;
width: 45px;
height: 60px;
margin: auto;
text-align: center; }
You are using absolute positioning on your hexagons, that's why they are not centered, try a different approach such as display: inline-block with adjusted margins (some space inbetween) for bottom hexagons.
&__hexagon {
margin: 0 auto;
}
&:first-of-type {
display: block;
}
&:nth-child(2) {
margin-right: 4px;
display: inline-block;
}
&:last-of-type {
margin-left: 4px;
display: inline-block;
}
fiddle
I've made a simple css key frame animation that occurs when the page is loaded. However, the page background-image sticks to the text. You can see my problem here
https://codepen.io/gavdraws/pen/OmpEjK
Any ideas what I'm doing wrong?
Cheers
You have applied a background-image to .home and the text elements have class .home, so each of them has a background-image.
I think you want that background on the element that wraps the text elements (.pageCont) - not every .home element.
/* - - - - - Nav Icons - - - - - */
/* Profile */
$(document).ready(function(){
$("#top").hover(function() {
$("#profile").css("background-image", "url(img/nav-icons/Profile-light.png)");
}, function() {
$("#profile").css("background-image", "url(img/nav-icons/Profile-dark.png)");
});
});
/* CV */
$(document).ready(function(){
$("#left").hover(function() {
$("#cv").css("background-image", "url(img/nav-icons/CV-light.png)");
}, function() {
$("#cv").css("background-image", "url(img/nav-icons/CV-dark.png)");
});
});
/* Contact */
$(document).ready(function(){
$("#bottom").hover(function() {
$("#contact").css("background-image", "url(img/nav-icons/Contact-light.png)");
}, function() {
$("#contact").css("background-image", "url(img/nav-icons/Contact-dark.png)");
});
});
/* Work */
$(document).ready(function(){
$("#right").hover(function() {
$("#work").css("background-image", "url(img/nav-icons/Work-light.png)");
}, function() {
$("#work").css("background-image", "url(img/nav-icons/Work-dark.png)");
});
});
html, body {
height:100%;
width: 100%;
margin:0;
padding:0;
}
h2{
font-family: 'Lato', sans-serif;
font-size: 33pt;
font-style: bold;
text-transform: uppercase;
}
h2.home{
color: #EDEDED;
}
p{
font-family: 'Lato', sans-serif;
font-size: 12pt;
}
p.home{
color: #EDEDED;
}
/*.preloader {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: black;
z-index: 2000;
background-image: url(../gfx/logo/logo.gif) !important;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}*/
/*#line{
position: relative;
top: 50%;
bottom: 50%;
}*/
.frame {
position: absolute;
z-index: 1000;
}
.frame.rightFrame {
top: 0px;
right: 0px;
border-right: 45px solid #EDEDED;
border-top: 45px solid transparent;
border-bottom: 45px solid transparent;
height: 100%;
box-sizing: border-box;
}
.frame.rightFrame:hover{
border-right: 45px solid #F1612F;
cursor: pointer;
}
.frame.leftFrame {
top: 0px;
left: 0px;
border-left: 45px solid #EDEDED;
border-top: 45px solid transparent;
border-bottom: 45px solid transparent;
height: 100%;
box-sizing: border-box;
}
.frame.leftFrame:hover{
border-left: 45px solid #F1612F;
cursor: pointer;
}
.frame.topFrame {
top: 0px;
left: 0px;
border-top: 45px solid #EDEDED;
border-left: 45px solid transparent;
border-right: 45px solid transparent;
height: 0px;
width: 100%;
box-sizing: border-box;
}
.frame.topFrame:hover{
border-top: 45px solid #F1612F;
cursor: pointer;
}
.frame.bottomFrame {
bottom: 0px;
left: 0px;
border-bottom: 45px solid #EDEDED;
border-left: 45px solid transparent;
border-right: 45px solid transparent;
height: 0px;
width: 100%;
box-sizing: border-box;
}
.frame.bottomFrame:hover{
border-bottom: 45px solid #F1612F;
cursor: pointer;
}
.pageCont{
position: absolute;
top: 45px;
left: 45px;
right: 45px;
bottom: 45px;
z-index: 950;
overflow: hidden;
}
/* - - - - - Icons formatting - - - - - */
.menuIcon {
z-index: 1001;
cursor: pointer;
}
/* Profile */
.menuIcon#profile {
position: relative;
margin: 0 auto;
width: 45px;
height: 45px;
background-image: url(../img/nav-icons/Profile-dark.png);
background-repeat: no-repeat;
}
#profile:hover ~ .topFrame {
border-top: 45px solid #F1612F !important;
}
#profile:hover {
background-image: url(../img/nav-icons/Profile-light.png) !important;
}
/* CV */
.menuIcon#cv {
top: 50%;
margin-top: -15px;
position: absolute;
width: 45px;
height: 45px;
background-image: url(../img/nav-icons/CV-dark.png);
background-repeat: no-repeat;
}
#cv:hover ~ .leftFrame {
border-left: 45px solid #F1612F !important;
}
#cv:hover {
background-image: url(../img/nav-icons/CV-light.png) !important;
}
/* Contact */
.menuIcon#contact {
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
bottom: 0 !important;
width: 45px;
height: 45px;
background-image: url(../img/nav-icons/Contact-dark.png);
background-repeat: no-repeat;
}
#contact:hover ~ .bottomFrame {
border-bottom: 45px solid #F1612F !important;
}
#contact:hover {
background-image: url(../img/nav-icons/Contact-light.png) !important;
}
/* Work */
.menuIcon#work {
top: 50%;
right: 0;
margin-top: -15px;
position: absolute;
width: 45px;
height: 45px;
background-image: url(../img/nav-icons/Work-dark.png);
background-repeat: no-repeat;
}
#work:hover ~ .rightFrame {
border-right: 45px solid #F1612F !important;
}
#work:hover{
background-image: url(../img/nav-icons/Work-light.png) !important;
}
.pageCont{
background-image: url("http://www.codeandpepper.com/assets/gfx/start/slide_3.jpg") !important;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: top left;
}
.profile-pic{
position: relative;
margin-top: 30px !important;
width: 150px;
height: auto;
text-align: center;
animation: fadeuptwo 0.8s ease-out forwards;
/* Safari and Chrome */
-webkit-animation: fadeuptwo 0.8s;
}
.centre-div{
text-align: center;
position: relative;
margin: 0 auto !important;
margin-top: 50px !important;
width: 420px;
height: 80%;
animation: fadeup 0.9s ease-out forwards;
/* Safari and Chrome */
-webkit-animation: fadeup 0.9s;
}
#keyframes fadeup {
from {
top: 200px;
opacity: 0;
}
to {
top: 0px;
opacity: 1
}
}
#-webkit-keyframes fadeup {
/* Safari and Chrome */
from {
top: 200px;
opacity: 0;
}
to {
top: 0px;
opacity: 1;
}
}
#keyframes fadeuptwo {
from {
top: 200px;
opacity: 0;
}
to {
top: 0px;
opacity: 1
}
}
#-webkit-keyframes fadeuptwo {
/* Safari and Chrome */
from {
top: 200px;
opacity: 0;
}
to {
top: 0px;
opacity: 1;
}
}
a {
color: #F1612F;
display: inline-block;
position: relative;
text-decoration: none;
cursor: pointer;
}
a:after {
background-color: currentColor;
bottom: 0;
content: '';
display: inline-block;
height: 2.5px;
left: 0;
position: absolute;
right: 0;
-moz-transition: left 0.15s ease-out,right 0.15s ease-out;
-o-transition: left 0.15s ease-out,right 0.15s ease-out;
-webkit-transition: left 0.15s ease-out,right 0.15s ease-out;
transition: left 0.15s ease-out,right 0.15s ease-out;
}
a:hover:after {
left: 50%;
right: 50%;
-moz-transition: left 0.15s ease-in,right 0.15s ease-in;
-o-transition: left 0.15s ease-in,right 0.15s ease-in;
-webkit-transition: left 0.15s ease-in,right 0.15s ease-in;
transition: left 0.15s ease-in,right 0.15s ease-in;
}
/* Responsive: Small Desktop */
#media (max-width: 640px) {
}
/* Responsive: Mobile */
#media (max-width: 640px) {
.frame{
display: none !important;
}
.pageCont{
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.menuIcon{
display: none !important;
}
.centre-div{
width: 90%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<!--<div class="preloader"></div>-->
<div class="menuIcon" id="profile"></div>
<div class="menuIcon" id="cv"></div>
<div class="menuIcon" id="work"></div>
<div class="menuIcon" id="contact"></div>
<div class="frame rightFrame" id="right"></div>
<div class="frame leftFrame" id="left"></div>
<div class="frame topFrame" id="top"></div>
<div class="frame bottomFrame" id="bottom"></div>
<div class="pageCont home">
<div class="centre-div">
<img class="profile-pic" src="img/me_1#2x.png">
<h2 class="home">Hi, I'm Gavin.</h2>
<p class="home">
A graphic and UX designer with excellent communication and design skills with a proven record of delivering creative and innovative design solutions. Welcome to my online Portfolio.
</p>
<p class="home">
I have passion for both digital and print design, with a forward-thinking mentality and innovative spark. Please feel free to have a <a>look around</a> and <a>say hello</a>.
</p>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/gavinfriel.js" type="text/javascript"></script>
</body>
I would be interested to know if you can make a modal pop-up window just using HTML and CSS without JQuery.
Does anyone know such a simple example?
Thanks in advance!
A modal with only HTML and CSS no jQuery or javascript
body {
color: #333333;
font-family: 'Helvetica', arial;
height: 80em;
}
.wrap {
padding: 40px;
text-align: center;
}
hr {
clear: both;
margin-top: 40px;
margin-bottom: 40px;
border: 0;
border-top: 1px solid #aaaaaa;
}
h1 {
font-size: 30px;
margin-bottom: 40px;
}
p {
margin-bottom: 20px;
}
.btn {
background: #428bca;
border: #357ebd solid 1px;
border-radius: 3px;
color: #fff;
display: inline-block;
font-size: 14px;
padding: 8px 15px;
text-decoration: none;
text-align: center;
min-width: 60px;
position: relative;
transition: color .1s ease;
/* top: 40em;*/
}
.btn:hover {
background: #357ebd;
}
.btn.btn-big {
font-size: 18px;
padding: 15px 20px;
min-width: 100px;
}
.btn-close {
color: #aaaaaa;
font-size: 30px;
text-decoration: none;
position: absolute;
right: 5px;
top: 0;
}
.btn-close:hover {
color: #919191;
}
.modal:before {
content: "";
display: none;
background: rgba(0, 0, 0, 0.6);
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10;
}
.modal:target:before {
display: block;
}
.modal:target .modal-dialog {
-webkit-transform: translate(0, 0);
-ms-transform: translate(0, 0);
transform: translate(0, 0);
top: 20%;
}
.modal-dialog {
background: #fefefe;
border: #333333 solid 1px;
border-radius: 5px;
margin-left: -200px;
position: fixed;
left: 50%;
top: -100%;
z-index: 11;
width: 360px;
-webkit-transform: translate(0, -500%);
-ms-transform: translate(0, -500%);
transform: translate(0, -500%);
-webkit-transition: -webkit-transform 0.3s ease-out;
-moz-transition: -moz-transform 0.3s ease-out;
-o-transition: -o-transform 0.3s ease-out;
transition: transform 0.3s ease-out;
}
.modal-body {
padding: 20px;
}
.modal-header,
.modal-footer {
padding: 10px 20px;
}
.modal-header {
border-bottom: #eeeeee solid 1px;
}
.modal-header h2 {
font-size: 20px;
}
.modal-footer {
border-top: #eeeeee solid 1px;
text-align: right;
}
/*ADDED TO STOP SCROLLING TO TOP*/
#close {
display: none;
}
<div class="wrap">
<h1>Modal - Pure CSS (no Javascript)</h1>
<hr />
Modal!
</div>
<!-- Modal -->
<div class="modal" id="modal-one" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-header">
<h2>Modal in CSS?</h2>
× <!--CHANGED TO "#close"-->
</div>
<div class="modal-body">
<p>One modal example here! :D</p>
</div>
<div class="modal-footer">
Nice! <!--CHANGED TO "#close"-->
</div>
</div>
</div>
</div>
<!-- /Modal -->
Yes, it is possible.
You can use the :target pseudo selector to show a modal.
Here's an example including some transitions as well (code combined from shehary's codepen example and http://tympanus.net/Development/ModalWindowEffects):
body {
background-color: #e74c3c;
}
a {
background-color: #c0392b;
color: #fff;
text-align: center;
width: 200px;
height: 50px;
line-height: 50px;
text-decoration: none;
border-radius: 2px;
}
a:hover {
background-color: #a5281b;
}
body > a {
display: block;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.md-modal {
position: fixed;
top: 50%;
left: 50%;
width: 50%;
max-width: 630px;
min-width: 320px;
height: auto;
z-index: 2000;
visibility: hidden;
transform: translateX(-50%) translateY(-50%);
}
.md-modal:target {
visibility: visible;
}
.md-overlay {
position: fixed;
width: 100%;
height: 100%;
visibility: hidden;
top: 0;
left: 0;
z-index: 1000;
opacity: 0;
background: rgba(143,27,15,0.8);
transition: all 0.3s;
}
.md-modal:target ~ .md-overlay {
opacity: 1;
visibility: visible;
}
/* Content styles */
.md-content {
color: #fff;
background: #e74c3c;
position: relative;
border-radius: 3px;
margin: 0 auto;
}
.md-content h3 {
margin: 0;
padding: 0.4em;
text-align: center;
font-size: 2.4em;
font-weight: 300;
opacity: 0.8;
background: rgba(0,0,0,0.1);
border-radius: 3px 3px 0 0;
}
.md-content > div {
padding: 15px 40px 30px;
margin: 0;
font-weight: 300;
font-size: 1.15em;
}
.md-content > div p {
margin: 0;
padding: 10px 0;
}
.md-content > div ul {
margin: 0;
padding: 0 0 30px 20px;
}
.md-content > div ul li {
padding: 5px 0;
}
.md-content a {
display: block;
margin: 0 auto;
font-size: 0.8em;
}
/* Effect */
.md-modal .md-content {
-webkit-transform: scale(0.7);
-moz-transform: scale(0.7);
-ms-transform: scale(0.7);
transform: scale(0.7);
opacity: 0;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.md-modal:target .md-content {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
opacity: 1;
}
MODAL
<div class="md-modal" id="modal">
<div class="md-content">
<h3>Modal Dialog</h3>
<div>
<p>This is a modal window.</p>
<a class="md-close" href="#">Close me!</a>
</div>
</div>
</div>
<div class="md-overlay"></div>
If you don't feel comfortable using visibility: hidden you can use display: none instead. But you better remove the transitions in that case (visibility can be used in a transition, display can't).