custom hover effect position issue - html

I am trying to position a button 10px off the horizontal center of the screen. This is the button code. The button uses some fancy hovering effect, which doesn't move with the button. How can I put the button 10px off the horizontal center of the screen?
body {
background-color: green;
}
.button-2 {
width: 140px;
height: 50px;
border: 2px solid white;
float: left;
text-align: center;
cursor: pointer;
position: relative;
box-sizing: border-box;
overflow: hidden;
margin: 0 0 40px 50px;
}
.button-2 a {
font-family: arial;
font-size: 16px;
color: white;
text-decoration: none;
line-height: 50px;
transition: all .5s ease;
z-index: 2;
position: relative;
}
.eff-2 {
width: 140px;
height: 50px;
top: -50px;
background: white;
position: absolute;
transition: all .5s ease;
z-index: 1;
}
.button-2:hover .eff-2 {
top: 0;
}
.button-2:hover a {
color: #666;
}
.watch-video-position {}
<div class="watch-video-position">
<div class="button-2 watch-video-position">
<div class="eff-2 watch-video-position"></div>
CLICK ME
</div>
</div>

I have made some changes in the css to class button-2.
.button-2 {
float: none;
margin: 0 auto;
top: 10px;
}
body {
background-color: green;
}
.button-2 {
border: 2px solid white;
box-sizing: border-box;
cursor: pointer;
float: none;
height: 50px;
margin: 0 auto;
overflow: hidden;
position: relative;
text-align: center;
top: 10px;
width: 140px;
}
.button-2 a {
font-family: arial;
font-size: 16px;
color: white;
text-decoration: none;
line-height: 50px;
transition: all .5s ease;
z-index: 2;
position: relative;
}
.eff-2 {
width: 140px;
height: 50px;
top: -50px;
background: white;
position: absolute;
transition: all .5s ease;
z-index: 1;
}
.button-2:hover .eff-2 {
top: 0;
}
.button-2:hover a {
color: #666;
}
.watch-video-position {}
<div class="watch-video-position">
<div class="button-2 watch-video-position">
<div class="eff-2 watch-video-position"></div>
CLICK ME
</div>
</div>

You need to use this:
.top {
position: relative;
}
.top .button-2 {
position: absolute;
left: 50%;
margin-left: -70px;
}
Make sure you add the unique class top to the first <div> and use that to position. You can also use margin and padding on the .top.
body {
background-color: green;
}
.button-2 {
width: 140px;
height: 50px;
border: 2px solid white;
float: left;
text-align: center;
cursor: pointer;
position: relative;
box-sizing: border-box;
overflow: hidden;
margin: 0 0 40px 50px;
}
.button-2 a {
font-family: arial;
font-size: 16px;
color: white;
text-decoration: none;
line-height: 50px;
transition: all .5s ease;
z-index: 2;
position: relative;
}
.eff-2 {
width: 140px;
height: 50px;
top: -50px;
background: white;
position: absolute;
transition: all .5s ease;
z-index: 1;
}
.button-2:hover .eff-2 {
top: 0;
}
.button-2:hover a {
color: #666;
}
.top {
position: relative;
padding-top: 25px;
}
.top .button-2 {
position: absolute;
left: 50%;
margin-left: -70px;
}
<div class="top watch-video-position">
<div class="button-2 watch-video-position">
<div class="eff-2 watch-video-position"></div>
CLICK ME
</div>
</div>

try centering its parent and shifting it within its parent:
body {
background-color: green;
text-align: center;
}
.outer {
width: 200px;
margin: auto;
background-color: blue;
}
.button-2 {
width: 140px;
height: 50px;
border: 2px solid white;
cursor: pointer;
position: relative;
box-sizing: border-box;
overflow: hidden;
margin: 0 0 40px 50px;
}
.button-2 a {
font-family: arial;
font-size: 16px;
color: white;
text-decoration: none;
line-height: 50px;
transition: all .5s ease;
z-index: 2;
position: relative;
}
.eff-2 {
width: 140px;
height: 50px;
top: -50px;
background: white;
position: absolute;
transition: all .5s ease;
z-index: 1;
}
.button-2:hover .eff-2 {
top: 0;
}
.button-2:hover a {
color: #666;
}
.watch-video-position {}
<div class="watch-video-position outer">
<div class="button-2 watch-video-position">
<div class="eff-2 watch-video-position"></div>
CLICK ME
</div>
</div>

try width 90% of div.button-2 and set border and padding to anchor.
body {
background-color: green;
}
.button-2 {
width: 90%;
height: 50px;
float: left;
text-align: center;
cursor: pointer;
position: relative;
box-sizing: border-box;
overflow: hidden;
margin: 0 0 40px 50px;
}
.button-2 a {
font-family: arial;
font-size: 16px;
color: white;
text-decoration: none;
line-height: 50px;
transition: all .5s ease;
z-index: 2;
position: relative;
border: 2px solid white;
padding:15px;
}
.eff-2 {
width: 140px;
height: 50px;
top: -50px;
background: white;
position: absolute;
transition: all .5s ease;
z-index: 1;
}
.button-2:hover .eff-2 {
top: 0;
}
.button-2:hover a {
color: #666;
}
.top {
position: relative;
padding-top: 25px;
}
.top .button-2 {
position: absolute;
left: 50%;
margin-left: -70px;
}
<div class="top watch-video-position">
<div class="button-2 watch-video-position">
<div class="eff-2 watch-video-position"></div>
CLICK ME
</div>
</div>

Related

Converting animated button style from css to styled-componenet

While browsing net looking for a button style to apply to my register form's button, i found this nice animated button code, but it's in a simple HTML & CSS. i tried to convert theses to styled-component but i can't manage to make it 100% the same as it looks in codepen. Can you correct my code to make it similar to the original ones?
HTML :
<div class="wrapper">
<span>Hover Me!</span>
</div>
CSS :
.wrapper{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
a{
display: block;
width: 200px;
height: 40px;
line-height: 40px;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #333;
border: 2px solid #333;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all .35s;
}
a span{
position: relative;
z-index: 2;
}
a:after{
position: absolute;
content: "";
top: 0;
left: 0;
width: 0;
height: 100%;
background: #ff003b;
transition: all .35s;
}
a:hover{
color: #fff;
}
a:hover:after{
width: 100%;
}
My try JSX :
const Button = styled.button`
display: block;
width: 200px;
height: 40px;
line-height: 40px;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #333;
border: 2px solid teal;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all 0.35s;
`;
const Span = styled.span`
&:after {
position: absolute;
content: "CREATE";
top: 0;
left: 0;
width: 0;
height: 100%;
background: teal;
transition: all 0.35s;
cursor: pointer;
}
&:hover {
color: white;
}
&:hover:after {
width: 100%;
}
`;
const Register = () => {
return (
<div>
<Button>
<Span>CREATE</Span>
</Button>
</div>
);
};
export default Register;
you put the &:after, &:hover and &:hover:after on the span and not on the button element.
try:
const Button = styled.button`
display: block;
width: 200px;
height: 40px;
line-height: 40px;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #333;
border: 2px solid teal;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all 0.35s;
&:after {
position: absolute;
content: "CREATE";
top: 0;
left: 0;
width: 0;
height: 100%;
background: teal;
transition: all 0.35s;
cursor: pointer;
}
&:hover {
color: white;
}
&:hover:after {
width: 100%;
}
`;
const Span = styled.span`
position: relative;
z-index: 2;
`;

cannot add my slidemenu to my mainfile css/html

i made a slidermenu, but i failed some stuff. I dont know how to make it sticky. but the biggest problem is that it looks wheird when i add it to my main file. it works fine when i run the slidebar on a clear page but when i implemnt it into this file it looks crazy. the sysmbols r not infront of the text anymore.
can anyone tell me how i can add the slidermenu to this file right
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="../js/jquery-3.5.1.min.js"></script>
<link rel="stylesheet" href="../css/stylesearch.css">
<link rel="icon" href="../images/logo.ico">
<link rel="stylesheet" href="../css/slidebar.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Search</title>
</head>
<body>
<div id="background-box" onclick="tag()"></div>
<div class="container" id="tag-box">
<div><a class="close-box" onclick="tag(), getValue()">×</a></div>
<br>Selectable Tags:</br>
</div>
<nav>
<script src="../js/slidebar.js"></script>
<img class="image-size" src="../images/logo.png">
<div class="bars"><i class="fa fa-bars fa-4x" id="scale" onclick="slidebar()"></i></div>
<a><img class="image-size" src="../images/menu.png" onclick=""></a>
<button id="btnabout" onclick="tag()">Tags</button>
<div class="search_box"><input type="text" name="box" id="search_text" placeholder="Search by name" class="form-control" /></div>
<div id="background-boxtitle" onclick="tag()"></div>
</nav>
<section class="sec1">
<div class="slidebar" id="slidebar"><?php include '../db/slidebar.php'; echo $slidebarbutton;?></div>
</section>
<section class="sec2">
<script src="../js/search.js"></script>
<div id="result"></div>
<div style="clear:both"></div>
</section>
<section class="sec3">
</section>
</body>
</html>
:root {
--slidermenu-color: #303030;
}
#slidebar{
position:absolute;
left:-15%;
width: 15%;
height: 100%;
transition: .5s;
background: var(--slidermenu-color);
overflow: scroll;
overflow-x: hidden;
}
#slidebar.active{
left: 0%;
}
#slidebarlock{
position: absolute;
left: -100%;
width: 85%;
height: 100%;
background: transparent;
transition: .5s;
}
#slidebarlock.active{
left: 15%;
}
.slidebarbutton {
background-color: #303030;
border: none;
color: white;
text-align: left;
text-decoration: none;
display: inline-block;
font-size: 30px;
cursor: pointer;
padding: 20px 0px;
width: 100%;
}
.slidebarbutton:hover{
background-color: #494949;
}
.bars:hover{
cursor: pointer;
}
.slidebarbutton div i{
padding-left:20px;
padding-right: 40px;
}
#slidebar::-webkit-scrollbar {
width: 5px;
}
#slidebar::-webkit-scrollbar-track {
background: var(--slidermenu-color);
}
#slidebar::-webkit-scrollbar-thumb {
background: transparent;
}
#slidebar:hover::-webkit-scrollbar-thumb{
background: black;
opacity: .8;
border-radius: 30px;
}
body{
margin: 0;
padding: 0;
font-family: sans-serif;
background: #222;;
}
header{
padding: 10px 100px;
box-sizing: border-box;
}
section{
width: 100%;
height: 100vh;
}
section.sec1{
width: 100%;
height: 50px;
}
div.gallery:hover {
border: 2px solid #404040;
background: #404040;
}
div.gallery {
margin: 5px;
border: 2px solid #222;
float: left;
width: 215px;
height: 400px;
color: #fff;
}
div.gallery img {
width: 100%;
height: 80%;
}
div.desc {
padding: 15px;
text-align: center;
}
section.sec3{
padding: 100px;
box-sizing: border-box;
height: auto;
}
section.sec3 h2{
font-size: 3em;
margin:0;
padding: 0;
color: #fff;
}
nav{
width: 100%;
height: 120px;
background: url(../images/bg1.jpg);
position: sticky;
top: 0px;
}
nav ul{
display: flex;
}
.image-size{
position: absolute;
top: 10%;
right: 1%;
height: 40px;
}
.search_box{
position: absolute;
top: 20%;
left: 50%;
transform: translate(-150%, -50%);
height: 20px;
}
.search_box input[type="text"]{
width: 300%;
padding: 20px;
padding-right: 60px;
box-sizing: border-box;
background: rgba(0,0,0,0.3);
border: 2px solid #fff;
border-radius: 10px;
font-size: 18px;
color: #fff;
outline: none;
}
.fa-search{
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 25px;
color: #fff;
font-size: 25px;
}
::-webkit-input-placeholder {
color: #fff;
}
::-moz-placeholder {
color: #fff;
}
:-ms-input-placeholder {
color: #fff;
}
#media screen and (max-width: 425px){
.search_box{
width: 95%;
}
}
#tag-box{
position: absolute;
top: -120%;
left: 20%;
width: 60%;
height: 500px;
background: #000;
transition: .5s;
opacity: 0.9;
border-radius: 30px;
}
#tag-box.active{
top: 25%;
}
.container{
max-width: 60%;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
}
.container div{
margin: 5px;
}
.container div a{
font-size: 2em;
margin:0;
padding: 0;
color: #fff;
cursor: pointer;
}
.container div a:hover{
color: #f00;
}
.container div label{
cursor: pointer;
}
.container div label input[type="checkbox"]{
display: none;
}
.container div label span{
position: relative;
display: inline-block;
background: #424242;
color: #fff;
padding: 5px 10px;
color: 555;
text-shadow: 0 1px 4px rgba(0,0,0,.5);
border-radius: 15px;
font-size: 12px;
transition: 0.5s;
user-select: none;
overflow: hidden;
border: 2px solid #FFA500;
}
.container div label span:before{
content: '';
position: absolute;
top: absolute;
top: 0;
left: 0;
width: 100%;
height: 50%
}
.container div label input[type="checkbox"]:checked ~ span{
background: #FFA500;
color: #fff;
border: 2px solid #FFA500;
box-shadow: 0 2px 15px #FFA500;
}
#background-box {
position: absolute;
top: -120%;
left: 0%;
width: 100%;
height: 100%;
background: #000;
opacity: 0;
}
#background-box.active{
top: 0%;
}
#background-boxtitle {
position: absolute;
top: -120%;
left: 0%;
width: 100%;
height: 100%;
background: #000;
opacity: 0;
}
#background-boxtitle.active{
top: 0%;
}
#scale{
transition: .5s;
color:white;
transform: translate(22px, 16px);
}
#scale.active{
transition: .5s;
transform: translate(22px, 16px) rotate(90deg);
}

width 100% causes horizontal scrollbar

I've created a page with HTML and CSS, the problem is horizontal scrollbar is showing up although as far as I've checked there is no element with width over 100% or inappropriate padding or margin.
here is the complete HTML and CSS code: https://jsfiddle.net/m11nsbag/9/
#keyframes modalAnimation {
from {
top: 90vh;
}
to {
top: 95vh;
background-color: darkcyan;
box-shadow: 5px 5px 25px #747474;
}
}
#headerImage {
width: 100vw;
height: 100vh;
overflow: hidden;
position: fixed;
padding: 0px;
margin: 0px;
z-index: -10000000;
}
#main-nav>li {
width: 9vw;
height: 7vh;
color: #ffffff;
float: right;
text-align: center;
line-height: 7vh;
margin: 0px;
font-size: medium;
z-index: 100;
list-style-type: none;
transition: 0.25s;
}
#main-nav {
background-color: rgba(245, 255, 249, 0.5);
width: 100%;
height: 7vh;
position: fixed;
z-index: 100;
float: right;
transition: all 0.25s;
}
/*
#main-nav:hover {
background-color: rgba(0,129,129,1);
} */
#main-nav>li:hover {
background-color: rgb(232, 255, 92);
}
#wall {
background-color: #d2d2d2;
width: 100%;
height: 100vh;
z-index: -10;
}
* {
margin: 0px;
padding: 0px;
}
#main-nav>li>a {
color: #000;
text-decoration: none;
}
.modalLayout {
opacity: 0;
}
.modalLayout:target {
position: fixed;
background-color: rgba(0, 0, 0, 0.5);
width: 100vw;
height: 100vh;
opacity: 1;
transition: all 0.4s;
z-index: 200;
}
.modal {
text-align: center;
padding: 6% 1% 1.7% 1%;
width: 30vw;
height: 20vh;
margin: 30vh 35vw;
background-color: crimson;
position: fixed;
transition: all 0.4s;
z-index: 10;
border-radius: 10px;
box-shadow: 2px 2px #484848;
}
.closeBtn {
font-size: 35px;
position: absolute;
top: 25vh;
right: 33vw;
float: right;
color: #fff;
font-weight: bold;
text-decoration: none;
z-index: 1000;
cursor: pointer;
margin-right: 5px;
transition: all 0.4s;
}
.mainPageButton>div {
display: none;
}
.mainPageButton:hover>div {
display: block;
transition: all 0.25s;
}
.mainPageButton>div>div {
width: 15vw;
height: 8vh;
background-color: #d2d2d2;
color: #000;
font-size: medium;
float: top;
border-bottom: black 1px solid;
list-style-type: none;
position: relative;
line-height: 8vh;
}
.mainPageButton>div>div>a {
text-decoration: none;
color: #fff;
font-size: medium;
text-align: center;
list-style-type: none;
background-color: #d2d2d2;
padding-right: 2px;
}
.mainMenu {
position: absolute;
top: 88vh;
z-index: 0;
margin-right: 1vw;
}
.mainMenu>div {
width: 15vw;
height: 10vh;
border-bottom: black solid 2px;
margin-bottom: 3vh;
background-color: white;
transition: all .3s;
text-align: center;
line-height: 10vh;
}
.mainMenu>div:hover {
width: 17vw;
height: 12vh;
background-color: #ffcfce;
}
.mainMenu>div>a {
font-size: x-large;
color: #000;
cursor: pointer;
text-decoration: none;
}
.about {
width: 20vw;
height: 40vh;
background-color: #94ffca;
border-radius: 5px;
position: absolute;
top: 88vh;
left: 0;
float: left;
font-size: larger;
padding: 1vw;
transition: all 0.3s;
margin-left: 4px;
overflow: auto;
}
.about:hover {
transform: translate(5px);
background-color: rgba(148, 255, 202, 0.5);
}
#modalcontainer {
background-color: rgba(256, 256, 256, 0.75);
top: 80vh;
position: absolute;
width: 100vw;
height: 200%;
z-index: -10;
border-top-left-radius: 50px;
border-top-right-radius: 50px;
}
#modalswall {
width: 50vw;
height: 150vh;
background-color: #0d213c;
position: absolute;
top: 85vh;
right: 20vw;
z-index: -5;
border-radius: 8px;
box-shadow: 20px 20px 25px grey;
filter: opacity(90%);
}
.bodyModals {
background-color: #acd7ff;
top: 90vh;
width: 35vw;
height: 25vh;
right: 28vw;
position: relative;
z-index: 5;
border-radius: 10px;
transition: all .5s;
margin-bottom: 10vh;
}
.bodyModals:hover {
-webkit-animation: modalAnimation;
-webkit-animation-duration: 3s;
-webkit-animation-direction: alternate;
-webkit-animation-iteration-count: infinite;
}
.bodyModals>p {
padding: 1vw;
font-size: large;
}
#wrapper {
margin-bottom: 170vh;
position: relative;
}
#footer {
position: relative;
width: 100vw;
min-height: 25vh;
bottom: 0;
background-color: #0d213c;
}
#footer>p {
font-size: large;
text-align: center;
color: #fff;
padding: 10px 0px;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
I think there maybe a padding or margin which I'm overlooking but I've been looking at it for several hours and tried almost anything.
thanks for your sincere help.
Update: I changed all the 100vw with 100% and the problem was fixed.
Vertical scrollbars are included in vw units.
So when there's a vertical scrollbar, 100vw is wider than the viewport (without scrollbars).
One suggestion is to change #modalcontainer to width:100% instead of width:100vw.
#keyframes modalAnimation {
from {
top: 90vh;
}
to {
top: 95vh;
background-color: darkcyan;
box-shadow: 5px 5px 25px #747474;
}
}
#headerImage {
width: 100vw;
height: 100vh;
overflow: hidden;
position: fixed;
padding: 0px;
margin: 0px;
z-index: -10000000;
}
#main-nav>li {
width: 9vw;
height: 7vh;
color: #ffffff;
float: right;
text-align: center;
line-height: 7vh;
margin: 0px;
font-size: medium;
z-index: 100;
list-style-type: none;
transition: 0.25s;
}
#main-nav {
background-color: rgba(245, 255, 249, 0.5);
width: 50%;
height: 7vh;
position: fixed;
z-index: 100;
float: right;
transition: all 0.25s;
}
/*
#main-nav:hover {
background-color: rgba(0,129,129,1);
} */
#main-nav>li:hover {
background-color: rgb(232, 255, 92);
}
#wall {
background-color: #d2d2d2;
width: 50%;
height: 100vh;
z-index: -10;
}
* {
margin: 0px;
padding: 0px;
}
#main-nav>li>a {
color: #000;
text-decoration: none;
}
.modalLayout {
opacity: 0;
}
.modalLayout:target {
position: fixed;
background-color: rgba(0, 0, 0, 0.5);
width: 100vw;
height: 100vh;
opacity: 1;
transition: all 0.4s;
z-index: 200;
}
.modal {
text-align: center;
padding: 6% 1% 1.7% 1%;
width: 30vw;
height: 20vh;
margin: 30vh 35vw;
background-color: crimson;
position: fixed;
transition: all 0.4s;
z-index: 10;
border-radius: 10px;
box-shadow: 2px 2px #484848;
}
.closeBtn {
font-size: 35px;
position: absolute;
top: 25vh;
right: 33vw;
float: right;
color: #fff;
font-weight: bold;
text-decoration: none;
z-index: 1000;
cursor: pointer;
margin-right: 5px;
transition: all 0.4s;
}
.mainPageButton>div {
display: none;
}
.mainPageButton:hover>div {
display: block;
transition: all 0.25s;
}
.mainPageButton>div>div {
width: 15vw;
height: 8vh;
background-color: #d2d2d2;
color: #000;
font-size: medium;
float: top;
border-bottom: black 1px solid;
list-style-type: none;
position: relative;
line-height: 8vh;
}
.mainPageButton>div>div>a {
text-decoration: none;
color: #fff;
font-size: medium;
text-align: center;
list-style-type: none;
background-color: #d2d2d2;
padding-right: 2px;
}
.mainMenu {
position: absolute;
top: 88vh;
z-index: 0;
margin-right: 1vw;
}
.mainMenu>div {
width: 15vw;
height: 10vh;
border-bottom: black solid 2px;
margin-bottom: 3vh;
background-color: white;
transition: all .3s;
text-align: center;
line-height: 10vh;
}
.mainMenu>div:hover {
width: 17vw;
height: 12vh;
background-color: #ffcfce;
}
.mainMenu>div>a {
font-size: x-large;
color: #000;
cursor: pointer;
text-decoration: none;
}
.about {
width: 20vw;
height: 40vh;
background-color: #94ffca;
border-radius: 5px;
position: absolute;
top: 88vh;
left: 0;
float: left;
font-size: larger;
padding: 1vw;
transition: all 0.3s;
margin-left: 4px;
overflow: auto;
}
.about:hover {
transform: translate(5px);
background-color: rgba(148, 255, 202, 0.5);
}
#modalcontainer {
background-color: rgba(256, 256, 256, 0.75);
top: 80vh;
position: absolute;
width: 100%;
height: 200%;
z-index: -10;
border-top-left-radius: 50px;
border-top-right-radius: 50px;
}
#modalswall {
width: 50vw;
height: 150vh;
background-color: #0d213c;
position: absolute;
top: 85vh;
right: 20vw;
z-index: -5;
border-radius: 8px;
box-shadow: 20px 20px 25px grey;
filter: opacity(90%);
}
.bodyModals {
background-color: #acd7ff;
top: 90vh;
width: 35vw;
height: 25vh;
right: 28vw;
position: relative;
z-index: 5;
border-radius: 10px;
transition: all .5s;
margin-bottom: 10vh;
}
.bodyModals:hover {
-webkit-animation: modalAnimation;
-webkit-animation-duration: 3s;
-webkit-animation-direction: alternate;
-webkit-animation-iteration-count: infinite;
}
.bodyModals>p {
padding: 1vw;
font-size: large;
}
#wrapper {
margin-bottom: 170vh;
position: relative;
}
#footer {
position: relative;
width: 50vw;
min-height: 25vh;
bottom: 0;
background-color: #0d213c;
}
#footer>p {
font-size: large;
text-align: center;
color: #fff;
padding: 10px 0px;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
<ul id="main-nav">
<li class="mainPageButton">
<div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
</div>
</li>
<li>
</li>
<li>
</li>
</ul>
<img src="http://ghmahdi.ir/wp-content/uploads/header.jpg" id="headerImage">
<div id="wrapper">
<div id="aboutMe" class="modalLayout">
<div>
×
</div>
<div class="modal"></div>
</div>
<div id="contactUS" class="modalLayout">
<div>
×
</div>
<div class="modal"></div>
</div>
<div class="mainMenu">
<div> </div>
<div></div>
<div></div>
<div></div>
</div>
<div class="about"></div>
<div id="modalswall"></div>
<div class="bodyModals"> </div>
<div class="bodyModals"></div>
<div class="bodyModals"></div>
<div id="modalcontainer"> </div>
</div>
<div id="footer">
</div>
For interest, also see:
Bug 133271
viewport units in case of 'overflow:auto'

position: relative; interrupts css opacity in web page

When adding position: relative; to the code the background popup window won't get any opacity - what is the reason for that? I don't understand why centering the web page should affect background opacity.
Thanks for anyone that can help!!
<html>
<head>
<style>
body {
background-color: white;
width: 960px;
margin: auto;
position: relative;
}
.one {
background: black;
-webkit-border-radius: 12;
-moz-border-radius: 12;
border-radius: 12px;
font-family: Book Antiqua;
color: #ffffff;
font-size: 60px;
text-align: center;
width: 75px;
height: 75px;
overflow:hidden;
float:left;
position:absolute;
transition: .5s ease;
top: 120px;
left: 140px;
text-align: center;
text-vertical-align: middle;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.8);;
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 h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: orange;
}
.popup .content {
max-height: 30%;
overflow: auto;
}
</style>
</head>
<body>
<a class="one" id="one" href="#popup1" onclick="changeZIndex(this)">1</a>
<div id="popup1" class="overlay">
<div class="popup">
<h2>Here i am</h2>
<a class="close" href="#">×</a>
<div class="content">
1
</div>
</div>
</div>
</body>
</html>
Link
Add height to the html and body element
CSS
html,
body
{
height: 100%;
}
CSS Errors
.one
{
background: black;
-webkit-border-radius: 12;
-moz-border-radius: 12;
border-radius: 12px;
font-family: Book Antiqua;
color: #ffffff;
font-size: 60px;
text-align: center;
width: 75px;
height: 75px;
overflow: hidden;
float: left;
position: absolute;
transition: .5s ease;
top: 120px;
left: 140px;
text-align: center;
/* incorrect value
text-vertical-align: middle;
*/
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.8);
/*
transition: opacity 500ms;
*/
transition: opacity 0.5s;
visibility: hidden;
opacity: 0;
}

background image isn't loading properly

I tried to add a background image to the span but, for some reason, it doesn't seem to be properly loading. The jsfiddle is below.
P.S-I know its kinda straight "it doesn't works question" just got stuck for a while couldn't find a answer
http://jsfiddle.net/whnb3yf2/46/
<div class="learn">
<a>Learn More</a>
<span></span>
</div>
.learn
{
width: 200px;
height: 60px;
font-family: 'Open Sans',sans-serif;
background-color: transparent;
border:2px solid #fff;
position: relative;
text-align: center;
font-size: 18pt;
line-height:60px;
overflow: hidden;
}
.learn a
{
color: white;
display: block;
transition: all 0.2s ease-in-out;
}
.learn:hover {
background-color: white;
}
.learn:hover a
{
color: black;
margin-left: -20px;
}
.learn span
{
background:url(https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-arrow-forward-128.png) center;
display: block;
width: 9px;
height: 16px;
position: absolute;
top: 22px;
left: 110%;
transition: all 0.2s ease-in-out;
}
.learn:hover span{
left: 80%;
}
body {
background-color: black;
}
You need to add background-size: 9px 16px; to your .learn span rule.
.learn {
width: 200px;
height: 60px;
font-family: 'Open Sans',sans-serif;
background-color: transparent;
border:2px solid #fff;
position: relative;
text-align: center;
font-size: 18pt;
line-height:60px;
overflow: hidden;
}
.learn a {
color: white;
display: block;
transition: all 0.2s ease-in-out;
}
.learn:hover {
background-color: white;
}
.learn:hover a {
color: black;
margin-left: -20px;
}
.learn span {
background:url(https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-arrow-forward-128.png) center center;
background-size: 9px 16px;
display: block;
width: 9px;
height: 16px;
position: absolute;
top: 22px;
left: 110%;
transition: all 0.2s ease-in-out;
}
.learn:hover span{
left: 80%;
}
body {
background-color: black;
}
<div class="learn">
<a>Learn More</a>
<span></span>
</div>
The issue you are having is that the background image for the button is too small. You can fix that by setting the background size equal to that of the button. For more information on the background-size attribute, check out http://www.w3schools.com/cssref/css3_pr_background-size.asp
.learn {
width: 200px;
height: 60px;
font-family: 'Open Sans',sans-serif;
background-color: transparent;
border:2px solid #fff;
position: relative;
text-align: center;
font-size: 18pt;
line-height:60px;
overflow: hidden;
}
.learn a {
color: white;
display: block;
transition: all 0.2s ease-in-out;
}
.learn:hover {
background-color: white;
}
.learn:hover a {
color: black;
margin-left: -20px;
}
.learn span {
background:url(https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-arrow-forward-128.png) center center;
background-size: 9px 15px;
display: block;
width: 9px;
height: 16px;
position: absolute;
top: 22px;
left: 110%;
transition: all 0.2s ease-in-out;
}
.learn:hover span{
left: 80%;
}
body {
background-color: black;
}
<div class="learn">
<a>Learn More</a>
<span></span>
</div>