change which toggle is selected on page load - html

I'm trying to figure out a solution where i can select which toggle is displayed on page load. At the minute, when the page loads, it is set to Pay Annually. How would i change my code so that it is set to Pay Monthly on page load?. I want the ability to quickly swap them for a/b tests.
I've attached my CodePen also - CodePen
$(document).ready(function() {
var checkBoxes = $("input[name='toggle']");
toggle();
$("#toggle").click(function() {
toggle();
});
function toggle() {
if (checkBoxes.prop("checked")) {
$('#coreMonthlyText,#coreMonthlyPrice').show();
$('#coreAnnuallyText,#coreAnnuallyPrice').hide();
} else {
$('#coreMonthlyText,#coreMonthlyPrice').hide();
$('#coreAnnuallyText,#coreAnnuallyPrice').show();
}
}
});
.pricing-box {
background: red;
padding: 25px;
width: 30%;
}
.row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
}
.column {
display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1;
}
.toggle-switch {
cursor: pointer;
background-color: gray;
display: inline-block;
border: 0;
padding-left: 0;
padding-right: 0;
}
.toggle-switch input {
display: none;
}
.toggle-switch,
.toggle-switch span {
border-radius: 35px;
border-style: solid;
border-color: transparent;
padding-top: 0.75rem;
padding-bottom: 0.75rem;
}
.toggle-switch span {
border-width: 2px;
padding-left: 0.75rem;
padding-right: 0.75rem;
}
.toggle-switch input:checked+span+span,
.toggle-switch input+span {
border-color: #444;
background-color: white;
}
.toggle-switch input+span+span,
.toggle-switch input:checked+span {
background-color: transparent;
border-color: transparent;
}
#coreMonthlyText,
#coreMonthlyPrice,
#coreAnnuallyText,
#coreAnnuallyPrice {
display: none;
}
#proMonthlyText,
#proMonthlyPrice,
#proAnnuallyText,
#proAnnuallyPrice {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="pricing-box">
<div class="row">
<div class="column">
<div class="core">
<h2>Core</h2>
</div>
</div>
<div class="column">
<div id="coreAnnuallyPrice" class="coreAnnuallyPrice">
$2,399/yr<br /> Normally $3,588/yr
</div>
<div id="coreMonthlyPrice" class="coreMonthlyPrice">
$299/pm<br /> first 2 months free
</div>
</div>
</div>
<label for="toggle" class="toggle-switch">
<input class="toggle-button" id="toggle" type="checkbox" name="toggle" data-checked="coreAnnuallyPrice,coreAnnuallyText" data-not-checked="coreMonthlyPrice,coreMonthlyText">
<span>pay annually</span>
<span>pay monthly</span>
</label>
</div>

Related

Prevent the dropdown menu overlap the div below just push it

I have a dropDown menu and when the drop list is open is overlapping the div below, I wish to push the div below down when the dropdown is open, I've try with flex, grid, flexgrow, grid rows, positions relative/absolute, and I can't find any solution.
here is the HTML code:
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" />
</div>
</div>
and the CSS:
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
height: 100%;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
top: 5rem;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
padding-bottom: 140px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {display: block; }
and here is the code example working: https://codepen.io/raulcosalux/pen/VwzGyYO
kind regards,
Using absolute positioning will not regard for content underneath. With that being said, you have to use position: relative; on your dropdown menu in order to allow the input or any other content below to adjust when the menu opens.
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
height: 100%;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
position: sticky;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: relative;
background-color: #f1f1f1;
min-width: 160px;
padding-bottom: 140px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {display: block; }
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" />
</div>
</div>
Change the position of the dropdown container that holds the menu to relative, then remove the padding you have on it. Remove this => padding-bottom: 140px; and change this => .dropdown-content { position: absolute; } to .dropdown-content { position: relative; }, this will push the content down below the menu element and the padding will no longer cover its content.
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.container{
display: flex;
flex-direction: column;
height: 100vh;
}
.dropContainer{
display: block;
margin-bottom: 2rem;
}
.inputContainer{
display: block;
height: 100%;
top: 5rem;
}
/* dropDown Menu */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.show {
display: block;
}
<div class="container">
<div class="dropContainer">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
Home
About
Contact
</div>
</div>
</div>
<div class="inputContainer">
<label for="fname">First name: </label>
<input type="text" id="fname" name="fname" />
</div>
</div>
I also removed the height on the dropContainer as well.

Replace two div on a row without changing width of parent element

I am really struggling to move two div in a row.
I tried to display flex in row but when I do that the current width of my two div remain the same while I'd like not to change the final width of the parent element.
I also tried inline display but it does not work too...
I want to place the two div inside the div with class "statusDetails" on the same row without interfering the current width of the div with class "status".
the objective is to have something like the end of this screen:
Any help will be appreciated!
Thx,
EDIT: the fiddle example :
body {
background-color: #edebe9;
}
.ddl-container .ddl-list {
position: absolute;
display: flex;
flex-direction: column;
border-left: 3px solid #3286d5;
background-color: white;
z-index: 1;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container>div {
cursor: pointer;
border: solid 3px transparent;
font-size: 1.1rem;
}
.horizontal-icon-menu .ddl-container>div:hover {
color: black;
}
/* .ddl-container:hover */
.horizontal-icon-menu .ddl-container .ddl-list {
right: 0;
border-left: 0px;
background-color: white;
z-index: 1;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container:hover>div {
background-color: white;
}
.horizontal-icon-menu .ddl-container:hover .ddl-list div .changeColorOnHover:hover {
background-color: #629924;
color: white;
}
.solid-border-bottom {
border-bottom: solid 1px #5e5e5e;
padding: 0px !important;
}
.statusDetails {
box-sizing: content-box;
}
.status div {
padding: 0px !important;
}
.statusDetails div>span {
text-transform: uppercase;
}
.statusDetails div span:last-of-type {
text-transform: lowercase;
}
<main>
<div class="horizontal-icon-menu">
<div class="ddl-container">
<div class="icon-param"><span class="username">ystalio</span></div>
<div class="ddl-list">
<div class="solid-border-bottom">
<div class="changeColorOnHover">Profil</div>
<div class="changeColorOnHover">Boîte de réception</div>
<div class="changeColorOnHover">Préférences</div>
<div class="changeColorOnHover">Déconnexion</div>
</div>
<div class="status">
<div class="statusDetails">
<div><span>ping </span><span id="ping">10</span><span> ms</span></div>
<div><span>server </span><span id="server">0.1</span><span> ms</span></div>
</div>
<div class="signal">
test
</div>
</div>
</div>
</div>
</div>
</main>
Since you dont have a working example, I assume you only want to have two div side by side aligned.
I will suggest you using "Bootstrap Grid System" in this case;
Otherwise, for vanilla html and css:
try adding CSS:
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
}
.col-sm-5 {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
And HTML class tag for:
<div class="status row">
<div class="statusDetails col-sm-5">
<div><span>ping </span><span id="ping">10</span><span> ms</span></div>
<div><span>server </span><span id="server">0.1</span><span> ms</span></div>
</div>
<div class="signal col-sm-5">test</div>
</div>
See Snippet below:
body {
background-color: #edebe9;
}
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
}
.col-sm-5 {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
}
.ddl-container .ddl-list{
width: 300px;
position: absolute;
display: flex;
flex-direction: column;
border-left: 3px solid #3286d5;
background-color: white;
z-index: 1;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container > div {
cursor: pointer;
border: solid 3px transparent;
font-size: 1.1rem;
}
.horizontal-icon-menu .ddl-container > div:hover {
color:black;
}
/* .ddl-container:hover */
.horizontal-icon-menu .ddl-container .ddl-list {
right: 0;
border-left: 0px;
background-color: white;
z-index: 1;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
text-transform: capitalize;
}
.horizontal-icon-menu .ddl-container:hover > div {
background-color: white;
}
.horizontal-icon-menu .ddl-container:hover .ddl-list div .changeColorOnHover:hover {
background-color: #629924;
color: white;
}
.solid-border-bottom {
border-bottom: solid 1px #5e5e5e;
padding: 0px !important;
}
.statusDetails {
box-sizing: content-box;
}
.status div {
padding: 0px !important;
}
.statusDetails div > span {
text-transform: uppercase;
}
.statusDetails div span:last-of-type {
text-transform: lowercase;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="test.css">
</head>
<body>
<main>
<div class="horizontal-icon-menu">
<div class="ddl-container">
<div class="icon-param"><span class="username">ystalio</span></div>
<div class="ddl-list">
<div class="solid-border-bottom">
<div class="changeColorOnHover">Profil</div>
<div class="changeColorOnHover">Boîte de réception</div>
<div class="changeColorOnHover">Préférences</div>
<div class="changeColorOnHover">Déconnexion</div>
</div>
<div class="status row">
<div class="statusDetails col-sm-5">
<div><span>ping </span><span id="ping">10</span><span> ms</span></div>
<div><span>server </span><span id="server">0.1</span><span> ms</span></div>
</div>
<div class="signal col-sm-5">
test
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>

Card Layout not setting correct in HTML

I am trying to create a Donation card for my site with the help of this. I am Almost done with code changes but unable to set the layout, it's not showing properly. All contents are overlapping. I tried to set a margin but that is not working.
$(function () {
// Whitelist buttons in popovers
var myDefaultWhiteList = $.fn.tooltip.Constructor.Default.whiteList
myDefaultWhiteList.button = [];
// Customizer popover
var $tip = $('.btn-donate').popover({
trigger: 'manual', // We don't want popover to launch when we don't need it :)
html: true,
offset: '-100px, 0',
container: 'body',
content: function () {
return '<p>' + $(this).data('description') + '</p><button class="btn btn-sm btn-dismiss white-text z-depth-0 pr-0">Got it</button>';
},
template: '<div class="popover popover-blue" role="tooltip"><div class="arrow"></div><div class="popover-body"></div></div>'
});
// Manually show popover
$tip.popover('show');
// Handle popover dismiss
$('.btn-dismiss').on('click', function () {
$tip.popover('hide');
});
});
body{
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
flex-direction: column;
background: #F0F0F0;
}
:root {
--yt-blue: #ea5b18; /* This is a custom color used by YouTube */
}
/* Custom card header */
.card-header {
display: flex;
position: relative;
justify-content: space-between;
padding-left: 16px !important;
align-items: center;
height: 48px;
overflow: hidden;
}
.donate-icon {
display: flex;
align-self: stretch;
align-items: center;
position: relative;
padding-right: 1.2rem;
float: right;
background: #ea5b18;
}
.donate-icon:before {
content: "";
position: absolute;
display: block;
width: 48px;
height: 48px;
transform: rotate(45deg) translate(-50%,50%);
background: #ea5b18;
}
.donate-icon i {
color: #187415;
background: #fff;
padding: 8px;
z-index: 1;
border-radius: 50%;
}
.avatar {
max-width: 50px;
}
.fundraiser {
display: flex;
align-items: flex-start;
}
.fundraiser .name {
font-size: 1rem;
}
.fundraiser .creator {
font-size: 1rem;
}
.fundraiser .details {
flex: 1;
}
/* Ugly workaroung - sorry :( */
.btn-donate, .btn-donate:hover, .btn-donate:active, .btn-donate:focus {
background: var(--yt-blue);
position: relative;
color: #fff;
}
.sum {
text-align: center;
font-weight: 500;
}
.card-footer a {
font-size: .785rem;
font-weight: 500;
}
/* Popover styles */
.popover-blue {
background: var(--yt-blue);
border-radius: 1;
}
.popover-blue .arrow:after {
border-bottom-color: var(--yt-blue) !important;
}
.popover-blue .popover-body {
color: #fff;
font-size: 1rem;
}
.btn-dismiss {
float: right;
box-shadow: none;
}
<div class="card mt-4 mx-auto" style="max-width: 25rem;">
<div class="card-header p-0">
<span class="d-inline-block card-title mb-0">Donate now</span>
<span class="donate-icon">
<i class="fas fa-hand-holding-heart"></i>
</span>
</div>
<div class="card-body">
<div class="fundraiser">
<img src="https://t3.ftcdn.net/jpg/04/06/35/70/360_F_406357077_MWIAoFRKa7qmoLhr44pTraEzmF5rTFhf.jpg" class="avatar" />
<div class="details px-2">
<h3 class="name mb-0"><strong>Magic Logic</strong></h3>
<span class="creator text-muted">paypal.me/MagicLogic</span>
</div><a href="https://www.paypal.com/paypalme/MagicLogic" title="Donate">
<button class="btn btn-md btn-donate z-depth-0" data-toggle="popover" data-placement="bottom"
data-description="You can buy me a cup of Coffee or something via PayPal.">Donate</button></a>
</div>
Trying to create something like this:
You almost had it. Just needed to update the layout details in your Flexbox containers. This should get you going in the right direction. I will leave it up to you to figure out where you went wrong with displaying the circular hand with heart icon in the top right corner.
Secondly, you didn't provide the <script> tag to include jQuery in your project or a <link> to Bootstrap. Which the page you provided here uses to create the tooltip. After adding the jQuery <script>'s right before the closing <body> tag and including the Bootstrap <link> in the <head>, the tooltip displays correctly.
$(function () {
// Whitelist buttons in popovers
var myDefaultWhiteList = $.fn.tooltip.Constructor.Default.whiteList
myDefaultWhiteList.button = [];
// Customizer popover
var $tip = $('.btn-donate').popover({
trigger: 'manual', // We don't want popover to launch when we don't need it :)
html: true,
offset: '-100px, 0',
container: 'body',
content: function () {
return '<p>' + $(this).data('description') + '<button class="btn btn-sm btn-dismiss white-text z-depth-0 pr-0">Got it</button></p>';
},
template: '<div class="popover popover-blue" role="tooltip"><div class="arrow"></div><div class="popover-body"></div></div>'
});
// Manually show popover
$tip.popover('show');
// Handle popover dismiss
$('.btn-dismiss').on('click', function () {
$tip.popover('hide');
});
});
body{
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
flex-direction: column;
background: #F0F0F0;
}
:root {
--yt-blue: #ea5b18; /* This is a custom color used by YouTube */
}
/* Custom card header */
.card-header {
display: flex;
position: relative;
justify-content: space-between;
padding-left: 16px !important;
align-items: center;
height: 48px;
overflow: hidden;
background: rgb(249, 249, 249);
border: .1rem solid lightgray;
}
.card-title {
padding: .25rem .6rem;
}
.donate-icon {
display: flex;
align-self: stretch;
align-items: center;
position: relative;
padding-right: 1.2rem;
float: right;
background: #ea5b18;
}
.donate-icon:before {
content: "";
position: absolute;
display: block;
width: 48px;
height: 48px;
transform: rotate(45deg) translate(-50%,50%);
background: #ea5b18;
}
.donate-icon i {
color: #187415;
background: #fff;
padding: 8px;
z-index: 1;
border-radius: 50%;
}
.avatar {
max-width: 50px;
}
.fundraiser {
display: flex;
align-items: center;
background: #fff;
border-radius: .1rem;
}
.fundraiser .details.px-2 {
margin: 0 1rem 0 .5rem;
}
.fundraiser .name {
font-size: 1rem;
margin: .15rem 0;
}
.fundraiser .creator {
font-size: 1rem;
color: #555;
}
.fundraiser .details {
flex: 1;
}
.btn-donate {
margin-top: .1rem;
padding: .75rem 1.25rem;
border: none;
text-transform: uppercase;
font-size: .8rem !important;
border-radius: .1rem;
background: #ea5b18 !important;
color: #fff !important;
}
.btn-donate, .btn-donate:hover, .btn-donate:active, .btn-donate:focus {
position: relative;
color: #fff;
cursor: pointer;
}
.sum {
text-align: center;
font-weight: 500;
}
.card-footer a {
font-size: .785rem;
font-weight: 500;
}
/* Popover styles */
.popover-blue {
border-radius: 1;
}
.popover-blue .arrow:after {
border-bottom-color: var(--yt-blue) !important;
}
.popover-blue .popover-body {
color: #fff;
background-color: #ea5b18;
font-size: 1rem;
height: 6rem;
}
.btn-dismiss {
margin-top: 1.5rem;
color: #fff !important;
float: right;
box-shadow: none;
}
.bs-popover-top > .arrow::after {
border-top-color: #ea5b18 !important;
}
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="card mt-4 mx-auto" style="max-width: 25rem;">
<div class="card-header p-0">
<span class="d-inline-block card-title mb-0">Donate now</span>
<span class="donate-icon">
<i class="fas fa-hand-holding-heart"></i>
</span>
</div>
<div class="card-body">
<div class="fundraiser">
<img src="https://t3.ftcdn.net/jpg/04/06/35/70/360_F_406357077_MWIAoFRKa7qmoLhr44pTraEzmF5rTFhf.jpg" class="avatar" />
<div class="details px-2">
<h3 class="name mb-0"><strong>Magic Logic</strong></h3>
<span class="creator text-muted">paypal.me/MagicLogic</span>
</div><a href="https://www.paypal.com/paypalme/MagicLogic" title="Donate">
<button class="btn btn-md btn-donate z-depth-0" data-toggle="popover" data-placement="bottom"
data-description="You can buy me a cup of Coffee or something via PayPal.">Donate</button></a>
</div>
<!-- You must include the jQuery and Bootstrap scripts -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>

Jquery Add class only one clicked element

Hi i am going to create small app, using jquery, but I have problem and can't solve it, when i will click on number box i want to select only one, but now it selects multiple boxes, for example if i click on 36 and then click to 41 it will select both of them, i want to select last one :/ any solution?
$(".checkbox_child").click(function(){
$(this).toggleClass("clickedcolor")
})
.checkbox_child:not(:first-child){
margin-left: 15px;
}
.checkbox_child span{
font-family: firagoregular;
font-size: 24px;
}
.clickedcolor{
color: #056304;
border-color: #056304;
}
.checkbox_main_header p{
font-family: firagomedium;
color: #707070;
opacity: 1;
font-size: 24px;
}
.checkbox_main_header p{
margin: 0 0 18px 0;
}
.checkbox_child{
display: flex;
flex-wrap: wrap;
width: 61px;
height: 48px;
background: #FFFFFF 0% 0% no-repeat padding-box;
border: 1px solid #A1A1A1;
border-radius: 10px;
opacity: 1;
justify-content: space-around;
align-items: center;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="costum_checkbox_main_parent">
<div class="checkbox_child"><span>36</span></div>
<div class="checkbox_child"><span>37</span></div>
<div class="checkbox_child"><span>38</span></div>
<div class="checkbox_child"><span>39</span></div>
<div class="checkbox_child"><span>40</span></div>
<div class="checkbox_child"><span>41</span></div>
<div class="checkbox_child"><span>42</span></div>
<div class="checkbox_child"><span>43</span></div>
</div>
</div>
You can use the following:
$(".checkbox_child").click(function() {
$(".clickedcolor").not($(this)).removeClass("clickedcolor")
$(this).toggleClass("clickedcolor")
})
I've also added a background color to clickedcolor just for the visual effect
Demo
$(".checkbox_child").click(function() {
$(".clickedcolor").not($(this)).removeClass("clickedcolor")
$(this).toggleClass("clickedcolor")
})
.checkbox_child:not(:first-child) {
margin-left: 15px;
}
.checkbox_child span {
font-family: firagoregular;
font-size: 24px;
}
.clickedcolor {
color: #056304;
background-color:blue!important;
border-color: #056304;
}
.checkbox_main_header p {
font-family: firagomedium;
color: #707070;
opacity: 1;
font-size: 24px;
}
.checkbox_main_header p {
margin: 0 0 18px 0;
}
.checkbox_child {
display: flex;
flex-wrap: wrap;
width: 61px;
height: 48px;
background: #FFFFFF 0% 0% no-repeat padding-box;
border: 1px solid #A1A1A1;
border-radius: 10px;
opacity: 1;
justify-content: space-around;
align-items: center;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="costum_checkbox_main_parent">
<div class="checkbox_child"><span>36</span></div>
<div class="checkbox_child"><span>37</span></div>
<div class="checkbox_child"><span>38</span></div>
<div class="checkbox_child"><span>39</span></div>
<div class="checkbox_child"><span>40</span></div>
<div class="checkbox_child"><span>41</span></div>
<div class="checkbox_child"><span>42</span></div>
<div class="checkbox_child"><span>43</span></div>
</div>
</div>

Menu toggle with options inside using only CSS

I'm trying to create a menu with options inside. I'm using only CSS with checkbox and radio inputs.
By changing one of the options, I also want the menu to close. I tried this using label inside label, but it doesn't work.
My prototype code:
input {
display: none;
}
label {
cursor: pointer;
}
label span:hover {
font-weight: 600;
}
.opener .menu {
background-color: #f3f3f3;
display: flex;
flex-direction: column;
color: #4d4d4d;
padding: 12px 4px;
width: 270px;
}
#menu:checked~.opener .menu {
display: none;
}
#menu~.opener>span:nth-of-type(1) {
display: none;
}
#menu:~.opener>span:nth-of-type(2) {
display: block;
}
#menu:checked~.opener>span:nth-of-type(1) {
display: block;
}
#menu:checked~.opener>span:nth-of-type(2) {
display: none;
}
.box {
height: 50px;
width: 50px;
margin: 20px 0;
}
#red:checked~.box {
background-color: red;
}
#blue:checked~.box {
background-color: blue;
}
#green:checked~.box {
background-color: green;
}
<input id="menu" type="checkbox"></input>
<input id="red" type="radio" name="opcoes" checked></input>
<input id="blue" type="radio" name="opcoes"></input>
<input id="green" type="radio" name="opcoes"></input>
<label class="opener" for="menu"><span>Open</span><span>Close</span>
<div class="menu">
<label for="red"><span>red</span></label>
<label for="blue"><span>blue</span></label>
<label for="green"><span>green</span></label>
</div>
</label>
<div class="box"></div>
Or you can check here: https://codepen.io/anon/pen/JxzPKR
Is there a way to close the menu when you click on one of the options without JavaScript?
Sometimes, contrary to popular opinion, it's just more dev friendly to use Javascript.
There is too much conditional logic for this to be a pure CSS solution. There are ~3 if-then-else conditions you would have to satisfy, while keeping the styles cascading. I think the most arduous task to satisfy is that you have a toggle header, in addition to other controls toggling it.
This will inherently get more complex and convoluted the more components you add. But here is an example using :target. This is a work-around and provides a solution to the question at hand. You won't be able to 'toggle' the menu this way so I had to add the header under the elements so it can be accessed via some kind of sibling selector:
.menu {
position: relative;
width: 45%;
}
input[type="radio"] {
position: absolute;
opacity: 0;
height: 0;
width: 0;
}
a:any-link {
all: unset;
}
.menu-header {
position: absolute;
top: 0;
padding: 5px 10px;
color: white;
width: 100%;
background-color: cornflowerblue;
}
.menu-header a {
font-weight: bold;
cursor: pointer;
color: white;
font-size: 22px;
}
.menu-header .close {
display: none;
}
#menu-body {
display: none;
flex-flow: column nowrap;
position: absolute;
top: 34px;
background-color: rgba(220,220,220,1);
height: 100px;
color: black;
width: 100%;
padding: 10px;
}
.menu-header a,
#menu-body label {
cursor: pointer;
}
#menu-body:not(:target) {
display: none;
}
#menu-body:not(:target) + .menu-header > a:not(.close) {
display: inline-block;
}
#menu-body:target {
display: flex;
}
#menu-body:target + .menu-header > a {
display: none;
}
#menu-body:target + .menu-header > a.close {
display: inline-block;
}
<div class="menu">
<div id="menu-body">
<input id="red" type="radio" name="opcoes" checked/>
<label for="red">Red</label>
<input id="blue" type="radio" name="opcoes"/>
<label for="blue">Blue</label>
<input id="green" type="radio" name="opcoes"/>
<label for="green">Green</label>
</div>
<div class="menu-header">≡ Open≡ Close</div>
</div>
You should consider accessability using this method, or at minimum, how this effects site navigation.
Edit: A demo in regards to discussion in comments:
.menu {
position: relative;
width: 45%;
}
input[type="radio"] {
position: absolute;
opacity: 0;
height: 0;
width: 0;
}
a:any-link {
all: unset;
}
#menu-header {
position: absolute;
top: 0;
padding: 5px 10px;
color: white;
width: 100%;
background-color: cornflowerblue;
}
#menu-header a {
font-weight: bold;
cursor: pointer;
color: white;
font-size: 22px;
}
#menu-header .close {
display: none;
}
#menu-body {
display: none;
flex-flow: column nowrap;
position: absolute;
top: 34px;
background-color: rgba(220,220,220,1);
height: 100px;
color: black;
width: 100%;
padding: 10px;
}
.menu-header a,
#menu-body label {
cursor: pointer;
}
#menu-body:not(:target) {
display: none;
}
#menu-body:not(:target) ~ .menu-header > a:not(.close) {
display: inline-block;
}
#menu-body:target {
display: flex;
}
#menu-body:target ~ #menu-header > a {
display: none;
}
#menu-body:target ~ #menu-header > a.close {
display: inline-block;
}
#red:target ~ .box {
background-color: red;
}
#blue:target ~ .box {
background-color: blue;
}
#green:target ~ .box {
background-color: green;
}
.box {
background-color: black;
width: 75px; height : 75px;
}
<div class="menu">
<input id="red" type="radio" name="opcoes" checked/>
<input id="blue" type="radio" name="opcoes"/>
<input id="green" type="radio" name="opcoes"/>
<div id="menu-body">
Red
Blue
Green
</div>
<div class="box"></div>
<div id="menu-header">
≡ Open
≡ Close
</div>
</div>