Checkbox toggle square getting lost - html

I have been working on a custom-styled checkbox, but for some reason, the square when the toggle is checked is getting lost.
Anyone could please point out what I did wrong with this checkbox?
https://jsfiddle.net/d67k5uyq/6/
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>switch toggle menu using html css only</title>
</head>
<body>
<div class="container">
<div>
<input type="checkbox" class="toggle" id="default">
<label for="default" data-checked="Checked" data-unchecked="Unchecked"></label>
</div>
</div>
</body>
</html>
I believe is something to do with the before and after where I'm forgetting to set some value.
CSS
body{
background: #485461;
font-family: sans-serif;
height: 100vh;
overflow: hidden;
}
.container{
margin: 0 auto;
text-align: center;
padding-top: 30px;
color: white;
}
input[type=checkbox].toggle{
display: none;
}
input[type=checkbox].toggle + label{
display: inline-block;
height: 60px;
width: 200px;
position: relative;
font-size:20px;
border: 4px solid white;
padding: 0;
margin: 0;
cursor: pointer;
box-sizing: border-box;
transition: all 0.3s ease;
}
input[type=checkbox].toggle + label:before{
position: absolute;
top: 4px;
height: 44px;
width: 44px;
content: '';
transition: all 0.3s ease;
z-index: 3;
}
input[type=checkbox].toggle + label:after{
width: 140px;
text-align: center;
z-index: 2;
text-transform: uppercase;
position: absolute;
top: 50%;
transform: translateY(-50%);
text-overflow: ellipsis;
overflow: hidden;
}
input[type=checkbox].toggle:not(:checked) + label{
background-color: transparent;
text-align: right;
}
input[type=checkbox].toggle:not(:checked) + label:after{
content: attr(data-unchecked);
right: 0;
left: auto;
opacity: 1;
color: white;
}
input[type=checkbox].toggle:not(:checked) + label:before{
left: 4px;
background-color: white;
}
input[type=checkbox].toggle:checked + label{
text-align: left;
border-color: yellow;
}
input[type=checkbox].toggle:checked + label:after{
content: attr(data-checked);
left: 4px;
right: auto;
opacity: 1;
color: white;
}
input[type=checkbox].toggle:checked + label:before{
left: 144px;
border-color: yellow;
}

When the input is unchecked then the before pseudo element is given a background color of white.
When it is checked then it is given a color to the border, but the border has not been given any width.
Assuming you want a yellow bordered square the this snippet not only sets the border color but also solid and 1px width.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>switch toggle menu using html css only</title>
<style>
body {
background: #485461;
font-family: sans-serif;
height: 100vh;
overflow: hidden;
}
.container {
margin: 0 auto;
text-align: center;
padding-top: 30px;
color: white;
}
input[type=checkbox].toggle {
display: none;
}
input[type=checkbox].toggle+label {
display: inline-block;
height: 60px;
width: 200px;
position: relative;
font-size: 20px;
border: 4px solid white;
padding: 0;
margin: 0;
cursor: pointer;
box-sizing: border-box;
transition: all 0.3s ease;
}
input[type=checkbox].toggle+label::before {
position: absolute;
top: 4px;
height: 44px;
width: 44px;
content: '';
transition: all 0.3s ease;
z-index: 3;
}
input[type=checkbox].toggle+label::after {
width: 140px;
text-align: center;
z-index: 2;
text-transform: uppercase;
position: absolute;
top: 50%;
transform: translateY(-50%);
text-overflow: ellipsis;
overflow: hidden;
content: 'A';
}
input[type=checkbox].toggle:not(:checked)+label {
background-color: transparent;
text-align: right;
}
input[type=checkbox].toggle:not(:checked)+label::after {
content: attr(data-unchecked);
right: 0;
left: auto;
opacity: 1;
color: white;
}
input[type=checkbox].toggle:not(:checked)+label::before {
left: 4px;
background-color: white;
}
input[type=checkbox].toggle:checked+label {
text-align: left;
border-color: yellow;
}
input[type=checkbox].toggle:checked+label::after {
content: attr(data-checked);
left: 4px;
right: auto;
opacity: 0.5;
color: white;
}
input[type=checkbox].toggle:checked+label::before {
left: 144px;
border-color: yellow;
border-style: solid;
border-width: 1px;
}
</style>
</head>
<body>
<div class="container">
<div>
<input type="checkbox" class="toggle" id="default">
<label for="default" data-checked="Checked" data-unchecked="Unchecked"></label>
</div>
</div>
</body>
</html>

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;
`;

Black box appears at the bottom of website

I have a simple website.
When I test it offline by hosting it on localhost everything works fine.
However when I transfer the webpage to my hosting server and access it from the internet a black box appears at the bottom of the page as i scroll down. This does not happen when testing offline only online.
Stanger still if i rotate my screen to landscape and then back to portrait then the problem seems to go away , however if i reload the page it reappears.
Ps. I am accessing the website online using a mobile phone.
This is what the problem looks like
This is what problem looks like
This is how it looks after i rotate my screen to landscape and then portrait, this is the desired look
#import url('https://fonts.googleapis.com/css?family=Tw+Cen+MT+Condensed');
html, body {
overflow-x: hidden;
height: 100%;
}
body {
background: #fff;
padding: 0;
margin: 0;
font-family: 'Tw Cen MT Condensed', sans-serif;
overflow-y: scroll;
}
.header {
display: block;
margin: 0 auto;
list-style-type:none;
width: 100%;
max-width: 100%;
box-shadow: none;
background: whitesmoke;
position: fixed;
height: 135px !important;
overflow: hidden;
z-index: 10;
border-bottom-style: solid;
border-bottom-width: 2px;
}
.streamicon img {
width: 100px;
height: 100px;
left: 24px;
position: absolute;
top: 17px;
}
.headerlogo img {
width: 556px;
height: 92px;
left: 29%;
position: absolute;
top: 26px;
}
input[type="checkbox"]:checked ~ .footer {
transform: translateX(-100%);
}
input[type=checkbox] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
background-color: black;
}
.sidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
top: 44px;
left: 93.2%;
height: 22px;
width: 65px;
}
.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 5px;
width: 100%;
background-color: black;
}
.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 18px;
background-color: black;
}
.diagonal.part-1 {
position: relative;
transition: all 0.3s;
box-sizing: border-box;
float: left;
background-color: black;
}
.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 18px;
background-color: black;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
top: 17px;
margin-left: 1px;
}
input[type=checkbox]:checked ~ .sidebarIconToggle > .diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -12px;
}
.footer {
position: relative;
font-size: 35px;
font-weight: bold;
margin-top: 60px;
margin-left:4vw;
text-align: center;
transition: transform 250ms ease-in-out;
}
.footer a {
color: #0f98fe;
font-size: 35px;
text-decoration: none;
}
.footer div{
height:21px;
}
.footer img {
width: 50%;
margin-left: 2.5%;
padding-bottom: 32px;
position: static;
}
.footer #end {
margin-top: 400px;
height: 590px;
position: absolute;
border-top: 0px solid;
font-size:35px;
}
.footer #credit {
display: inline;
color: black;
text-decoration:none;
}
.footer span {
color: #0f98fe;
}
.footer #end div{
height:21px;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Impressions</title>
<link href="css/mobile.css" rel="stylesheet" />
</head>
<body>
<div>
<ul class="header">
<li class="streamicon"> <img src="sys_media/radio_tower_black.png" /></li>
<li class="headerlogo"> <img src="sys_media/MenuBar_Logo.png"></li>
</ul>
</div>
<input type="checkbox" class="openSidebarMenu" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
<div class="spinner diagonal part-1"></div>
<div class="spinner horizontal"></div>
<div class="spinner diagonal part-2"></div>
</label>
<div class="footer">
<div id="end">
<img src="../sys_media/main_logo.png" /><br />
Copyright ©. 2021<br />
<div></div>
<a id="credit" href="www.elitewebsites.co.za">This website was designed by <span>www.elitewebsites.co.za</span></a>
</div>
</div>
</body>
</html>
body {
overflow-y: hidden;
height: 100%;
}
Add this to HTML tag also

How to change font color on hover?

I have a button animation on hover pseudo element. While the fill works fine, the font color does not change. I am sure this is something silly on my part, can't figure out where I am going wrong.
Will appreciate a lot is someone could point me in the right direction.
code pen example here
https://codepen.io/sabarishiyer/pen/RwaOJyO
code
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box
}
html {
font-family: Verdana, sans-serif, Arial;
font-size: 10px
}
body {
display: flex;
width: 100%;
height: 100vh;
align-items: center;
justify-content: center;
background-color: #272838
}
.button {
text-decoration: none;
color: aquamarine;
border: 3px solid aquamarine;
padding: 2rem 5rem;
font-size: 2.5rem;
position: relative;
/*To position pseudo elements relative to the button*/
transition: all 1s;
}
.button::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 0%;
height: 100%;
transition: all 1s;
color: aquamarine;
background-color: white;
}
.button::before {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 0%;
height: 100%;
transition: all 1s;
background-color: #fff;
color: aquamarine;
}
.button:hover {
color: #272838;
background-color: #fff;
}
.button:hover:before {
width: 100%;
}
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles.css" />
</head>
<body>
<a class="button" href="#">Learn more</a>
</body>
</html>
your problem is not the text color, it is the z-index. add this:
.button::after,
.button::before {
z-index: -1;
}
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box
}
html {
font-family: Verdana, sans-serif, Arial;
font-size: 10px
}
body {
display: flex;
width: 100%;
height: 100vh;
align-items: center;
justify-content: center;
background-color: #272838
}
.button {
text-decoration: none;
color: aquamarine;
border: 3px solid aquamarine;
padding: 2rem 5rem;
font-size: 2.5rem;
position: relative;
/*To position pseudo elements relative to the button*/
transition: all 1s;
}
.button::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 0%;
height: 100%;
transition: all 1s;
color: aquamarine;
background-color: white;
}
.button::before {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 0%;
height: 100%;
transition: all 1s;
background-color: #fff;
color: aquamarine;
z-index: -1;
}
.button:hover {
color: #272838;
background-color: #fff;
}
.button:hover:before {
width: 100%;
}
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles.css" />
</head>
<body>
<a class="button" href="#">Learn more</a>
</body>
</html>
Adding the z-index: -1 to .button should do the trick
use z-index: -1;
.button::before {
z-index: -1;
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 0%;
height: 100%;
transition: all 1s;
background-color: #fff;
color: aquamarine;
}

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);
}

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;
}