Jquery Add class only one clicked element - html

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>

Related

Flex items from navigationbar pushing down whole page when hovering over another flex item

So when I hover over the London flex item, the other flex items below push down the whole page. I want the flex items that drop down to instead overlay the content on the page.
I did not want o use a list because that seemed to be more annoying and I thought using flexbox would be easier and better. Though now I may have to go back to using a list.
I cant seem to find a solution and I dont know how to fix it. Any help or advice would be appriciated! (I'm also faily new to coding)
* {
box-sizing: border-box;
}
body {
font-family: Arial;
}
.container {
width: 100%;
border: 1px solid gray;
height: 100%;
min-height: calc(100vh - 67px);
background-color: rgb(228, 228, 228);
}
header {
padding: 1em;
color: white;
background-color: black;
text-align: center;
}
footer {
padding: 1em;
color: white;
background-color: black;
text-align: center;
}
.navbar {
display: flex;
margin-bottom: 0px;
justify-content: center;
padding: 1em;
padding-bottom: 0em;
padding-top: 1.5em;
}
.navbar a {
color: white;
padding: 14px 20px;
text-decoration: none;
padding: 2em;
padding-top: 1em;
padding-bottom: 1em;
background-color: #333;
border-radius: 5px;
margin: 20px;
margin-top: 10px;
margin-bottom: 10px;
transition: 0.2s;
}
.navbar a:hover {
background-color: whitesmoke;
color: black;
transform: scale(1.15);
}
.active-dropdown {
display: flex;
flex-wrap: wrap;
flex-direction:column;
}
.active-dropdown > .dropdown-sub{
display: none;
z-index: 1;
flex-direction: column; /* or row */
}
.active-dropdown:hover > .dropdown-sub {
display: flex;
}
.active-dropdown:hover > .dropdown-sub > .dropdown-option:hover{
background-color: #abcdef;
}
.active-dropdown a{
display: block;
background-color: #04AA6D !important;
color: white;
padding: 14px 20px;
text-decoration: none;
padding: 2em;
padding-top: 1em;
padding-bottom: 1em;
border-radius: 5px;
margin: 20px;
margin-top: 10px;
margin-bottom: 10px;
transition: 0.2s;
}
.active-dropdown a:hover {
color: white;
transform: scale(1.15);
}
.main {
padding: 1em;
display: flex;
flex-wrap: wrap;
}
.londontxt {
flex: 20%;
padding: 10px;
}
.pic {
flex: 20%;
padding: 10px;
}
.pic img {
margin-left: 10%;
width: 80%;
}
.pic h2 {
margin-left: 10%;
}
<!DOCTYPE html>
<html>
<head>
<title>City</title>
<link href="london.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container">
<header>
<h1>City Gallery</h1>
</header>
<div class="navbar">
<div class="active-dropdown">
<div class="dropdown-title">London</div>
<div class="dropdown-sub">
<div class="dropdown-option">option 1</div>
<div class="dropdown-option">option 2</div>
<div class="dropdown-option">option 3</div>
</div>
</div>
<a style="align-self: flex-start" href="#">Paris</a>
<a style="align-self: flex-start" href="#">Tokyo</a>
</div>
<div class="main">
<div class="londontxt">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous
city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia, its
history going back to its founding by the Romans, who named it Londinium.</p>
</div>
<div class="pic">
<h2>Bild 1</h2>
<img src="londonbridge.jpg" alt="">
</div>
<div class="pic">
<h2>Bild 2</h2>
<img src="londonbigben.jpg" alt="">
</div>
</div>
<footer>Copyright © 2022 Johannes</footer>
</body>
</html
You have to position the .dropdown-sub properly. Kindly add this CSS to your code.
.active-dropdown {
position: relative;
}
.active-dropdown > .dropdown-sub{
position: absolute;
top: 70px;
left: 15px;
background: #fff;
padding: 1rem;
}

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>

background-color doesn't work when using flexbox

I started using flexbox for my footers and now on all of my pages with forms the background-color is now the default white. Here is an example of one of my pages:
login.php
body {
background-color: #211e1e;
display: flex;
flex-direction: column;
height: 95vh;
}
h1 {
color: #99cc00;
text-align: center;
}
.content {
flex: 1 0 auto;
}
footer {
text-align: center;
font-weight: lighter;
color: #99cc00;
font-size: 10px;
flex-shrink: 0;
}
h3 {
position: absolute;
font-weight: bold;
color: #99cc00;
font-size: 15px;
width: 100%;
top: 91.5%;
}
.button {
background-color: #211e1e;
color: white;
font-size: 24px;
/*padding: 15px 50px;*/
transition-duration: .4s;
border: greenyellow;
width: 250px;
/* width of button */
height: 50px;
/* height of button */
}
.buttonColor:hover {
color: black;
background-color: greenyellow;
}
h1 {
text-align: center;
bottom: 25%;
}
content {
align-items: center;
justify-content: center;
}
.signin {
color: #99cc00;
margin: auto;
font-size: 24px;
}
.loginInput {
font-size: 24px;
}
.loginButton {
background-color: #211e1e;
color: white;
font-size: 24px;
padding: 10px 50px;
transition-duration: .4s;
border: greenyellow;
}
.loginButtonColor:hover {
color: black;
background-color: greenyellow;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="../../favicon.ico">
<meta charset="UTF-8">
<title>TapLovers</title>
<link rel="stylesheet" href="../background.css">
<link rel="stylesheet" href="login.css">
</head>
<body>
<div class=content>
<h1><img src="../../36x36-icon.png">apLovers</h1>
<form class="signin">
<input type="text" email="email" placeholder="Email" class="loginInput"><br>
<input type="text" password="password" placeholder="Password" class="loginInput"><br>
<input type="submit" name="submit" id="login" class="loginButton loginButtonColor" value="Login To TapLovers!" /><br><br>
<a href="../register/register.php">
<font color="#99cc00">Create a FREE TapLovers Account!</font>
</a>
</form>
</div>
<footer>
<h3><img src="../../favicon.ico">apLovers</h3><br>&copy 2018 TapLovers, All Rights Reserved
</footer>
</body>
</html>
Also I was trying to center my forms and my title using flexbox as well and I haven't gotten that working either. I'm not really sure what other details would be useful for this particular problem. If you need any more details just reply below and I'll answer them as they come out.
EDIT: The snippet that compiles on stack overflow shows my background just fine. What's more is if I use ctrl+shift+i on my page then the background works but if I just reload on my page then the background will turn white.
I did not see the issue with background fluctuations. I think it is a delay in the page load. I have added comments to help with the flexbox centering of items.
/*CSS reset of browser agent. Removes the horizontal scroll currently happening in page.*/
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: #211e1e;
display: flex;
flex-direction: column;
/* No need to restrict the height.
height: 95vh;*/
}
h1 {
color: #99cc00;
text-align: center;
}
.content {
flex: 1 0 auto;
/*make the content div flex so that the form can take the center alignment from flexbox properties. Add the centering here and avoid the margin: auto property */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
footer {
text-align: center;
font-weight: lighter;
color: #99cc00;
font-size: 10px;
flex-shrink: 0;
}
h3 {
position: absolute;
font-weight: bold;
color: #99cc00;
font-size: 15px;
width: 100%;
top: 91.5%;
}
.button {
background-color: #211e1e;
color: white;
font-size: 24px;
/*padding: 15px 50px;*/
transition-duration: .4s;
border: greenyellow;
width: 250px;
/* width of button */
height: 50px;
/* height of button */
}
.buttonColor:hover {
color: black;
background-color: greenyellow;
}
h1 {
text-align: center;
bottom: 25%;
}
/*Add flexbox style the inputs as blocks and remove <br> from HTML*/
.signin {
color: #99cc00;
font-size: 24px;
display: flex;
flex-direction: column;
}
.signin>* {
margin: 5px 0;
}
.loginInput {
font-size: 24px;
}
.loginButton {
background-color: #211e1e;
color: white;
font-size: 24px;
padding: 10px 50px;
/*Please check your animation ??
transition-duration: .4s;*/
/*add border size and transparency 1px solid*/
border: 1px solid greenyellow;
}
.loginButtonColor:hover {
color: black;
background-color: greenyellow;
}
<div class="content">
<h1><img src="../../36x36-icon.png">apLovers</h1>
<form class="signin">
<input class="loginInput" placeholder="Email" type="text"> <input class="loginInput" placeholder="Password" type="text"> <input class="loginButton loginButtonColor" id="login" name="submit" type="submit" value="Login To TapLovers!"> <font color="#99CC00">Create a FREE TapLovers Account!</font>
</form>
</div>
<footer>
<h3><img src="../../favicon.ico">apLovers</h3>
<p>© 2018 TapLovers, All Rights Reserved</p>
</footer>

<a> tag showing as a different size on chrome and firefox

My issue is with this code here, you can view it at lapismc.net. for whatever reason it displays differently in chrome than it does in Firefox.
The "w-" classes are from CandyUI.css.
The popup-button classes are below.
.popup {
height: 170px;
min-height: 170px;
background-color: #244753;
border-top: 5px black;
box-shadow: black 0 -1px 3px 0, black 0 1px 3px 0;
}
.popup-container {
height: 120px;
}
.popup-para {
font-family: Raleway, sans-serif;
color: white;
font-size: 16px;
}
.popup-button {
width: 250px;
margin-left: 7px;
font-family: Raleway, sans-serif;
color: white;
font-weight: 400;
text-align: center;
}
.popup-button.youtube {
background-color: #5069ed;
}
.popup-button.youtube:hover {
background-color: #4259c0;
}
.popup-button.facebook {
background-color: #3973ed;
}
.popup-button.facebook:hover {
background-color: #3062ce;
}
.popup-button.forums:hover {
background-color: #2776bb;
}
<div class="w-section w-hidden-medium w-hidden-small w-hidden-tiny popup">
<div class="w-container popup-container">
<h1 class="heading white popup-title">Keep Updated</h1>
<p class="popup-para">Check out our Media Portals</p>
Visit our Facebook Page
Send us an Email
Join our Discord Server
</div>
</div>
The buttons display like this in chrome
and like this in firefox and edge
Any and all help is appreciated, please keep in mind that I am primarily a Java developer and have limited knowledge of CSS. Thanks.
I would wrap the three buttons and use flexbox. I'd also make them full-width on narrow devices. Here's an example. It's a proof of concept. If you need help applying it to your code, consider adding a live snippet to your question, reproducing the problem.
.popup {
height: 170px;
min-height: 170px;
background-color: #244753;
border-top: 5px black;
box-shadow: black 0 -1px 3px 0, black 0 1px 3px 0;
display: inlin-block;
}
.popup-container {
height: 120px;
}
.popup-para {
font-family: Raleway, sans-serif;
color: white;
font-size: 16px;
}
.popup-button {
margin: 0 0 7px 7px;
font-family: Raleway, sans-serif;
color: white;
font-weight: 400;
text-align: center;
}
.popup-button.youtube {
background-color: #5069ed;
}
.popup-button.youtube:hover {
background-color: #4259c0;
}
.popup-button.facebook {
background-color: #3973ed;
}
.popup-button.facebook:hover {
background-color: #3062ce;
}
.popup-button.forums {
background-color: #3585ee;
}
.popup-button.forums:hover {
background-color: #2776bb;
}
.button-bar {
display: flex;
flex-wrap: wrap;
background-color: #244753;
padding: 7px 7px 0 0;
}
.button-bar > * {
padding: 1rem .5rem;
box-sizing: border-box;
flex: 1 0 calc(33.33% - 7px);
text-decoration: none;
}
#media (max-width: 768px) {
.button-bar {
flex-wrap: wrap;
}
.button-bar > * {
flex: 1 0 100%;
max-width: calc(100% - 7px);
}
}
<div class="w-section w-hidden-medium w-hidden-small w-hidden-tiny popup">
<div class="w-container popup-container">
<h1 class="heading white popup-title">Keep Updated</h1>
<p class="popup-para">Check out our Media Portals</p>
<div class="button-bar">
Visit our Facebook Page
Send us an Email
Join our Discord Server
</div>
</div>
</div>

CSS text alignment and formatting issues

I'd like to center vertically 2 lines of text in a box, but I have 2 questions:
What is the "cleanest" way to reduce the empty space between the main <p> (JOHN DOE) and the <p><span> (born in Japan). I can play with the padding/margin of the <span> line but I don't believe this would be the best approach. Is it?
What is the best way to center these 2 lines of text vertically no matter what the height of the green box is?
Thanks,
https://jsfiddle.net/qa6yzbk7/
<div class="container">
<div class="row">
<div class="col-md-4 intro-boxes white-smoke">
<p>Colum 1</p>
</div>
<div class="col-md-4 intro-boxes apple">
<p>John Doe</p>
<p><span>Born in Japan</span></p>
</div>
<div class="col-md-4 intro-boxes chateau-green">
<p>Jane Doe</p>
<p><span>Born in France</span></p>
</div>
</div>
</div>
CSS:
.chateau-green {
background: #469551;
}
.apple {
background: #6FB34F;
}
.white-smoke {
background: #F5F5F5;
}
.red {
background: red;
}
.green {
background: green;
}
.height-350px {
height: 350px;
background-image: url(http://placehold.it/1350x450/E1E9EC);
background-position: center center;
}
.intro-boxes {
height: 140px;
margin-bottom: 30px;
}
.intro-boxes p {
font-size: 36px;
color: #fff;
text-align: center;
text-transform: uppercase;
}
.intro-boxes p span {
font-size: 18px;
color: #fff;
text-align: center;
text-transform: lowercase;
}
Flexbox for centering....then using line-height and margin/padding resets.
I added borders for visual reference....I also took the span out of the p as it was unnecessary.
.apple {
background: #6FB34F;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.intro-boxes {
height: 140px;
margin-bottom: 30px;
}
.intro-boxes p {
font-size: 36px;
border: 1px solid grey;
color: #fff;
text-align: center;
text-transform: uppercase;
margin: 0;
padding: 0;
line-height: 1;
}
.intro-boxes span {
font-size: 18px;
border: 1px solid grey;
text-transform: lowercase;
color: white;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-4 intro-boxes apple">
<p>John Doe</p>
<span>Born in Japan</span>
</div>
</div>
</div>