CSS only slidedown on checkbox check - css

I'm looking to create a slidedown effect on checkbox check without JS, so pure css. The problem is we can't use JS on this page.
I've look on so many websites, but they all say something different and most do use JS.
My HTML:
<label>
<input class="open-content" type="checkbox">
<div class="label-container">
<div style="color: #EC008C; font-size: 20px; font-weight: 700;">Open this tab</div>
<div style="font-size: 32px; font-weight: 700;">+</div>
</div>
<div class="content-open fade-new">Show this content with slidedown</div>
</label>
My CSS:
<style type="text/css">
.open-content:checked ~ .content-open {
visibility: visible!important; max-height: none!important;
padding: 20px 0px 20px 20px;
margin-top: 30px;
}
.fade-new {
transition: visbility 0.3s ease-in-out, max-height 0.3s ease-in-out;
}
.content-open {
max-height: 0px;
visibility: hidden;
background-color: #F5F5F5;
}
</style>
And how it looks:
But it isn't animated. I used opacity 0 to 1 and that works to make a nice animation, but I prefer sliding down if that is possible with checkbox + pure CSS. Does anyone know how to do this?

Yes, it is possible to create a pure CSS slide-down using the checkbox hack.
In this example I have separated the <label> from the <input> and linked them by:
giving the <input> an id
giving the <label> a matching for attribute
Working Example (Version 1):
This version slides down.
.open-content {
display: none;
}
.label-text {
position: relative;
display: block;
z-index: 12;
height: 32px;
line-height: 32px;
padding: 6px;
color: #EC008C;
font-size: 20px;
font-weight: 700;
background-color: rgb(255, 255, 255);
cursor: pointer;
}
.label-text::after {
content: '+';
display: inline;
color: rgb(0, 0, 0);
font-size: 32px;
font-weight: 700;
vertical-align: bottom;
}
.content {
position: relative;
display: inline-block;
z-index: 6;
padding: 6px;
background-color: #F5F5F5;
opacity: 0;
transform: translateY(-50px);
transition: all 0.6s linear;
}
.open-content:checked ~ .content {
opacity: 1;
transform: translateY(0);
}
<input id="open-content" class="open-content" type="checkbox">
<label class="label-text" for="open-content">
Open this tab
</label>
<div class="content">
<p>Show this content with slidedown</p>
</div>
Working Example (Version 2):
This version unfurls.
.open-content {
display: none;
}
.label-text {
position: relative;
display: block;
z-index: 12;
height: 32px;
line-height: 32px;
padding: 6px;
color: #EC008C;
font-size: 20px;
font-weight: 700;
background-color: rgb(255, 255, 255);
cursor: pointer;
}
.label-text::after {
content: '+';
display: inline;
color: rgb(0, 0, 0);
font-size: 32px;
font-weight: 700;
vertical-align: bottom;
}
.content {
position: relative;
display: inline-block;
z-index: 6;
padding: 6px;
height: 0;
background-color: #F5F5F5;
opacity: 0;
overflow: hidden;
transition: all 0.6s linear;
}
.open-content:checked ~ .content {
opacity: 1;
height: 120px;
}
<input id="open-content" class="open-content" type="checkbox">
<label class="label-text" for="open-content">
Open this tab
</label>
<div class="content">
<p>Show this content with slidedown</p>
<p>Show this content with slidedown</p>
<p>Show this content with slidedown</p>
</div>
Further Reading:
The "Checkbox Hack" (and things you can do with it) - CSS Tricks

i hope it help you
you also can use css animation
.fade-new{
height:0;
background:red;
opacity:0;
transition:1s;
}
.open-content:checked ~ .fade-new{
height:300px;
opacity:1;
transition:1s;
}
<label>
<input class="open-content" type="checkbox">
<div class="label-container">
<div style="color: #EC008C; font-size: 20px; font-weight: 700;">Open this tab</div>
<div style="font-size: 32px; font-weight: 700;">+</div>
</div>
<div class="content-open fade-new">Show this content with slidedown</div></span>
</label>

Related

Top part of my website disappears when I resize it vertically

I'm trying to create a responsive log in page for a college, but when I resize the window vertically the logo and basically the top part disappears.
Currently I'm designing for an iPhone 7 using the dev tools in Google Chrome to help me with the view. When I open the website on my Huawei phone and tap the password field the keyboard pushes the page up and the logo partially disappears. This does not happen on my iPhone.
I think the problem is somewhere in my div elements. Sorry if its a dumb question, I'm a beginner.
Website: https://borislav1333.000webhostapp.com/
body
{
margin: 0;
}
img
{
max-width: 300px;
position: absolute;
top: 60px;
left: 37px;
z-index: 1;
}
.container
{
width: 375px;
height: 667px;
background-color: white;
margin: auto;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-family: Georgia;
}
.form-back
{
width: 200px;
background-color: white;
z-index: 1;
margin: 0 auto;
padding: 45px;
position: absolute;
top: 80%;
left: 50%;
transform: translate(-50%, -80%);
text-align: center;
font-size: 18px;
}
input[type=text], input[type=password]
{
width: 100%;
padding: 10px;
margin: 8px 0px 8px;
border: solid 1px #aaa;
border-radius: 4px;
}
button
{
width: 100%;
height: 50px;
border: none;
border-radius: 30px;
border-color: white;
background-color: #e52791;
font-family: Georgia;
transition: background-color 0.7s ease-out;
}
button:hover
{
background-color: #02356a;
color: white;
transition: background-color 0.7s ease;
}
.submit
{
position: relative;
top: 30px;
}
::placeholder
{
font-family: georgia;
}
<div class="container">
<div class="img"><img src="logo.jpg"></div>
<div class="form-back">
<form action="message.html" onsubmit="return validation()">
<div>
<label for="accountNum">Metric Number</label><br>
<input type="text" id="accountNum" name="accountNum" placeholder="Metric Number..."><br>
</div>
<div>
<label for="surname">Password:</label><br>
<input type="password" id="surname" name="surname" placeholder="Password..."><br>
</div>
<div class="submit">
<button type="submit">Log In</button>
</div>
</div>
</div>
As per your code you have used position absolute value in many elements. I think this problem which you are facing is happening due to this absolute. I have updated your CSS code and added snippet below. Replace it and check, I wish you problem will be resolved :
body
{
margin: 0;
}
img
{
width: 100%;
max-width: 300px;
z-index: 1;
margin: 0 auto;
}
.container
{
margin: 0 auto;
font-family: Georgia;
text-align: center;
}
.form-back
{
width: 100%;
background:transparent;
margin: 0 auto;
padding: 45px;
text-align: center;
font-size: 18px;
}
input[type=text], input[type=password]
{
width: 100%;
padding: 10px;
margin: 8px 0px 8px;
border: solid 1px #aaa;
border-radius: 4px;
}
button
{
width: 100%;
height: 50px;
border: none;
border-radius: 30px;
border-color: white;
background-color: #e52791;
font-family: Georgia;
transition: background-color 0.7s ease-out;
}
button:hover
{
background-color: #02356a;
color: white;
transition: background-color 0.7s ease;
}
.submit
{
position: relative;
top: 30px;
}
::placeholder
{
font-family: georgia;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<div class="container">
<div class="img"><img src="https://borislav1333.000webhostapp.com/logo.jpg"></div>
<div class="form-back">
<form action="message.html" onsubmit="return validation()">
<div>
<label for="accountNum">Metric Number</label><br>
<input type="text" id="accountNum" name="accountNum" placeholder="Metric Number..."><br>
</div>
<div>
<label for="surname">Password:</label><br>
<input type="password" id="surname" name="surname" placeholder="Password..."><br>
</div>
<div class="submit">
<button type="submit">Log In</button>
</div>
</form>
</div>
</div>

css circle gets oval on browser zoom

I created radio buttons via css. Just styled on the pseudo-elements like this:
https://codepen.io/emily-green/pen/MWYQZqz
Here is the html
<label class="wrapper">
<input type="radio" />
<div class="label">Text</div>
</label>
<label class="wrapper wrapper--checked">
<input type="radio" />
<div class="label">Text</div>
</label>
Here is my css
input {
display: none
}
.wrapper {
font-family: "arial";
align-items: center;
color: #00f;
display: flex;
font-size: 12px;
font-weight: 600;
justify-items: center;
padding: .5rem 0 .5rem 1.3rem;
position: relative;
vertical-align: middle;
white-space: nowrap;
&::before,
&::after {
border-radius: 50%;
box-sizing: border-box;
content: '';
display: inline-block;
height: 14px;
left: 0;
position: absolute;
width: 14px;
}
&::before {
border: 2px solid #00f;
}
&::after {
background: #000;
transform: scale( 0 );
}
// checked
&--checked {
color: #000;
&::after {
transform: scale( .4 );
}
}
}
My problem:
When I zoom with the browser and on Windows Edge, the inner circle is misplaced or the outer circle gets oval. Does anyone have a solution for it?
I didn't found a solution for it so I changed it to an inline SVG. Inline because otherwise, the SVG get quite pixelated on some browsers

can't vertical align content within a row [duplicate]

This question already has answers here:
Bootstrap Vertical Center contents in row
(2 answers)
Closed 4 years ago.
I'm going crazy being unable to align some elements to the centre of a Bootstrap row. The only thing that seems to work is positioning some elements as absolute relative to the row, but I would like to avoid this as it would be an issue adjusting the horizontal gaps between objects when it comes to responsiveness.
Could you advice a more efficient way to vertically align all the content within the following row element? My code below:
PS. I'm using bootstrap 3.0 and SCSS
HTML
<div class="standard-container">
<div class="row title-menu-row">
<div class="col-md-4 title-menu-col">
<h1>Your predictions</h1>
</div>
<div class="col-md-7 title-menu-col">
<span class="badge badge-error pmd-ripple-effect">12</span>
<span>Not predicted yet</span>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
<label class="onoffswitch-label" for="myonoffswitch"></label>
</div>
</div>
<div class="col-md-1 title-menu-col icons">
<a href="#">
<span class="fa-layers fa-fw" style="">
<i class="fal fa-female" data-fa-transform="shrink-3 up-1 left-6"></i>
<i class="fal fa-male" data-fa-transform="shrink-3 down-1"></i>
</span>
</a>
<a href="#">
<i class="fal fa-table"></i>
</a>
</div>
</div>
SCSS
// --------------- Toggle switch ---------------
.onoffswitch {
position: relative; width: 48px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
height: 24px; padding: 0; line-height: 24px;
border: 2px solid #F1F1F5; border-radius: 24px;
background-color: #F1F1F5;
transition: background-color 0.3s ease-in;
}
.onoffswitch-label:before {
content: "";
display: block; width: 24px; margin: 0px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 22px;
border: 2px solid #F1F1F5; border-radius: 24px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label {
background-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label, .onoffswitch-checkbox:checked + .onoffswitch-label:before {
border-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label:before {
right: 0px;
}
//---------------all else -----------------
.standard-container {
padding: 0;
margin: 170px 0 0 155px;
.title-menu-row, .title-menu-col {
margin: 0;
padding: 0;
border: 1px solid red;
}
h1 {
color: rgba(117, 64, 238, 1);
margin: 0;
}
}
.title-menu-row {
margin-bottom: 100px !important;
vertical-align: top;
.title-menu-col {
}
.onoffswitch {
display: inline-block;
.onoffswitch-label {
margin: 0;
}
}
.icons {
}
.icon > a, .icons > a {
color: rgba(117, 64, 238, 1);
font-size: 20px;
}
.icon:first-child > a {
margin-right: 200px;
}
}
Here's a CodePen illustrating the issue.
https://codepen.io/alopez25/live/PRNayZ
Try -
display: flex;
align-items:center;
Here jsfiddle -
https://jsfiddle.net/5v35gvr7/1/
<div class="wrap">
<div class="inner-wrap">Hello</div>
<div class="inner-wrap">Hello</div>
</div>
.wrap{
height: 30px;
background: green;
display: flex;
align-items: center;
}
.inner-wrap{
margin: 0px 10px;
background: blue;
display: inline-block;
}
Created a sample fiddle from your code
Added a small css change
.container{
display: flex;
align-items: center;
width: 500px;
height: 100px;
border: 1px solid #888;
justify-content: center; //remove horizontal align by removing this
}
.onoffswitch {
position: relative; width: 48px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
height: 24px; padding: 0; line-height: 24px;
border: 2px solid #F1F1F5; border-radius: 24px;
background-color: #F1F1F5;
transition: background-color 0.3s ease-in;
}
.onoffswitch-label:before {
content: "";
display: block; width: 24px; margin: 0px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 22px;
border: 2px solid #F1F1F5; border-radius: 24px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label {
background-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label, .onoffswitch-checkbox:checked + .onoffswitch-label:before {
border-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label:before {
right: 0px;
}
.container{
display: flex;
align-items: center;
width: 500px;
height: 100px;
border: 1px solid #888;
justify-content: center;
}
.container>*{
margin: 0px 3px;
}
<div class="container">
<span class="badge badge-error pmd-ripple-effect">12</span>
<span>Not predicted yet</span>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
<label class="onoffswitch-label" for="myonoffswitch"></label>
</div>
</div>
Edit the Fiddle here

CSS - child checkbox should ignore parent checkbox css

I have a common CSS for checkboxes in my application. But I want to get rid of this custom stylish CSS in few places. it should display as a default checkbox, not a customized one.
And i don't want to touch the parent CSS. since we are using a 3rd party framework for styling.
I’ve tried adding the id to 'not' selector in the parent CSS. it worked unfortunately i cannot modify it. I need a alternate approach. Please refer below jsfiddle.
HTML:
<input type="checkbox" href="#" class="menu-open" id="menu-open"/>
<label>Custom Css - ok</label>
<br/>
<input type="checkbox" href="#" class="menu-open" id="menu-open1"/>
<label>Custom Css - ok</label>
<br/>
...<br/>
...
<br/>
<h5>Below checkbox should display as default (without styling)</h5>
<input type="checkbox" href="#" class="menu-open" id="normal"/>
<label>It should be default</label>
CSS
input[type="checkbox"] {
-webkit-appearance: none;
height: 1.618em;
width: 1.618em;
cursor: pointer;
position: relative;
-webkit-transition: .15s;
border-radius: 2em;
background-color: #900;
margin-right: 1em;
margin-top: .53em;
}
input[type="checkbox"]:checked + label{
background-color: green;
}
input[type="checkbox"]:not(:checked) + label{
color: blue;
}
input[type="checkbox"]:before,
input[type="checkbox"]:checked:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
line-height: 2.818em;
text-align: center;
color: #fff;
content: "'";
font-family: 'WebSymbolsRegular';
font-size: .618em;
}
input[type="checkbox"]:checked:before {
content: '.';
}
input[type="checkbox"]:hover:before {
background: rgba(255, 255, 255, 0.3);
}
http://jsfiddle.net/vh2nothv/2/
Just use class in your css.
http://jsfiddle.net/pratyush141/age91svr/
<input type="checkbox" href="#" class="menu-open" id="menu-open"/>
<label>Custom Css - ok</label>
<br/>
<input type="checkbox" href="#" class="menu-open" id="menu-open1"/>
<label>Custom Css - ok</label>
<br/>
<input type="checkbox" href="#" class="menu-open1" id="menu-open1"/>
<label>Custom Css - ok</label>
<br/>
...<br/>
...
<br/>
CSS
.menu-open {
-webkit-appearance: none;
/* Hides the default checkbox style */
height: 1.618em;
width: 1.618em;
cursor: pointer;
position: relative;
-webkit-transition: .15s;
border-radius: 2em;
background-color: #900;
margin-right: 1em;
margin-top: .53em;
}
.menu-open:checked + label{
background-color: green;
}
.menu-open:not(:checked) + label{
color: blue;
}
.menu-open:before,
input[type="checkbox"]:checked:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
line-height: 2.818em;
text-align: center;
color: #fff;
content: "'";
font-family: 'WebSymbolsRegular';
font-size: .618em;
}
.menu-open:checked:before {
content: '.';
}
.menu-open:hover:before {
background: rgba(255, 255, 255, 0.3);
}

How to make the footer stick to the bottom?

I was building a portfolio website purely out of html5 and css and I am stuck at sticking the footer at the bottom of the page.
Here are the codes:
contact.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>contact | sadman s.</title>
<link type="text/css" rel="stylesheet" href="stylesheet.css">
<link href='http://fonts.googleapis.com/css?family=Droid+Serif' rel='stylesheet' type='text/css'>
</head>
<body>
<header>
<h1>sadman s.</h1>
</header>
<!--NAVIGATION BAR-->
<nav>
<ul>
<li>h o m e</li>
<li>b l o g</li>
<li>p o r t f o l i o</li>
<li>a b o u t</li>
<li>c o n t a c t</li>
</ul>
</nav>
<!--NAVIGATION BAR ENDS-->
<!--BODY STARTS HERE-->
<body>
<form>
<label>Name</label>
<input name="name" placeholder="Name">
<label>Email</label>
<input name="email" type="email" placeholder="Email">
<label>Message</label>
<textarea name="message" placeholder="Your message"></textarea>
<input id="submit" name="submit" type="submit" value="SEND">
</form>
</body>
<!--BODY ENDS HERE-->
<!--FOOTER STARTS HERE-->
<footer>
<div id="footer_line"></div>
<!--FOOTER LINKS BAR-->
<nav>
<ul>
<li><span id="footer_bar">t w i t t e r</span></li>
<li><span id="footer_bar">i n s t a g r a m</span></li>
<li><span id="footer_bar">g i t h u b</span></li>
</ul>
</nav>
<!--FOOTER BAR ENDS-->
<p>copyright © 2014 - <span id="footer_link">sadman.de</span>. all rights reserved.</p>
</footer>
</html>
stylesheet.css
* {
margin: 0;
padding: 0;
font-family: Droid Serif;
}
body {
font-family: Droid Serif;
}
header {
font-family: Droid Serif;
font-weight: lighter;
font-size: 1.8em;
text-align: center;
text-transform: uppercase;
margin-top: 25px;
}
/*NAVIGATION BAR*/
nav {
position: relative;
list-style: none;
margin: 25px 0 40px 0;
padding: auto;
text-align: center;
font-family: Droid Serif;
text-transform: uppercase;
}
nav > ul > li {
display: inline;
}
nav > ul > li > a {
display: inline-block;
padding: 0 32px 0 32px;
color: #000;
text-decoration: none;
}
a:hover {
color: #00d8a3;
text-decoration: none;
transition: color 0.5s ease;
}
a:active {
color: #00d8a3 !important;
text-decoration: none;
}
/*BODY*/
h2 {
font-weight: 100;
text-align: center;
font-family: Droid Serif;
}
table {
border: 2px;
margin: -10px auto 15px auto;
}
td {
padding: 20px;
}
table tr td img {
-webkit-font-smoothing: antialiased;
opacity: 1;
-webkit-transition: opacity .3s ease-in-out;
-moz-transition: opacity .3s ease-in-out;
-o-transition: opacity .3s ease-in-out;
-ms-transition: opacity .3s ease-in-out;
transition: opacity .3s ease-in-out;
}
table tr td img:hover {
opacity: 0.7;
}
/*FOOTER*/
footer {
position: relative;
margin-left: auto;
margin-right: auto;
margin-top: auto;
margin-bottom: 15px;
width: 100%;
clear: both;
}
#footer_line {
width: 90%;
border: 1px solid #696969;
margin: auto;
}
p {
margin-top: 0px;
text-align: center;
font-size: 0.6em;
}
#footer_bar {
text-transform: lowercase;
}
#footer_link {
color: #00d8a3;
text-decoration: none;
}
#footer_link:hover {
color: #000000;
text-decoration: none;
}
/*CONTACT FORM*/
label {
display: none;
margin-top: 20px;
letter-spacing: 2px;
}
form {
width: 437px;
margin: 0 auto;
}
#form-div {
background-color: e1e1e1;
padding: 35px 35px 50px 35px;
width: 450px;
float: left;
position: absolute;
margin-top: 20px;
margin-left: -260px;
}
input, textarea {
width: 400px;
height: 27px;
background-color: #ffffff;
border: 1px solid #efefef;
padding: 10px;
margin-top: 3px;
font-size: 0.9em;
color: #696969;
}
textarea {
height: 100px;
}
input:focus, textarea:focus {
border: 3px solid #00d8a3;
}
#submit {
border-radius: 5px;
background-color: #00d8a3;
width: 400px;
height: 50px;
margin: 0 auto 56px auto;
font-size: 1.5em;
font-weight: bold;
}
Here is an image of my homepage, I want the footer to be at the bottom of the contact page like in the homepage. http://puu.sh/bzOUo/e1f2479945.jpg
Here is how it is showing up in the contact page right now: http://puu.sh/bzOWZ/ef02a73399.png
Also, if someone can help me align the "send" button in the contact page with the rest of the input boxes, it'd be really nice.
Try absolute position on footer
footer
{
position: absolute;
bottom: 0;
width: 100%;
}
Here is the Demo
hope this will work out. add this to your css code :
footer {
position:fixed;
bottom:0;
left:0;
width:100%;
height:60px;
}
footer * {
display:inline;
}

Resources