CSS Display separate text on Hover or Click on Image - html

I'm trying to display a text message when the user hovers or clicks on a image. These messages will be: "Good" or "Great" different text for each image. For some reason I cannot get it to work, I can get it to work if I hovered over plain old text but not on the image. I've been pulling out my hair for 2 days now really need help with this.
<link rel='stylesheet' href='https://afeld.github.io/emoji-css/emoji.css'>
<style>
#import url("https://fonts.googleapis.com/css?family=Lato:400,700");
.rating-wrapper {
max-width: 400px;
margin: 80px auto;
background: #fff;
padding: 1em;
border-radius: 3px;
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.1);
}
.rating-wrapper .rating-label {
text-align: center;
font-weight: 700;
display: block;
}
.rating-wrapper .ratingItemList {
max-width: 300px;
margin: auto;
display: flex;
justify-content: space-between;
padding: 1em 0;
}
.rating-wrapper input.rating {
display: none;
}
.rating-wrapper label.rating {
padding: 5px 3px;
font-size: 32px;
opacity: 0.7;
filter: grayscale(1);
cursor: pointer;
}
.rating-wrapper label.rating:hover {
filter: grayscale(0.84);
transform: scale(1.1);
transition: 100ms ease;
}
.rating-wrapper input.rating:checked + label.rating {
filter: grayscale(0);
opacity: 1;
transform: scale(1.1);
}
.hide {
display: none;
}
.myDIV:hover + .hide {
display: block;
color: red;
}
</style>
<form class="rating-wrapper">
<label class="rating-label">How helpful was this?
<div class="ratingItemList">
<input class="rating rating-4" id="rating-4-2" type="radio" value="4" name="rating"/>
<label class="rating rating-4" for="rating-4-2"><i class="em em-grinning"></i></label>
<input class="rating rating-5" id="rating-5-2" type="radio" value="5" name="rating"/>
<label class="rating rating-5" for="rating-5-2"><i class="em em-star-struck"></i></label>
</div>
</label>
<label class="myDIV">Hover over me.</label>
<div class="hide"><br>I am shown when someone hovers over the image above.</div>
</form>

According to the Selector Reference I don't see any way to do this with CSS only. But it can be done with Javascript.
const divShow = document.querySelector('.hide');
function showUp(){
divShow.style.display = "block";
divShow.style.color = "red";
}
function hide(){
divShow.style.display = "none";
}
#import url("https://fonts.googleapis.com/css?family=Lato:400,700");
.rating-wrapper {
max-width: 400px;
margin: 80px auto;
background: #fff;
padding: 1em;
border-radius: 3px;
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.1);
}
.rating-wrapper .rating-label {
text-align: center;
font-weight: 700;
display: block;
position: relative;
}
.rating-wrapper .ratingItemList {
max-width: 300px;
margin: auto;
display: flex;
justify-content: space-between;
padding: 1em 0;
}
.rating-wrapper input.rating {
display: none;
}
.rating-wrapper label.rating {
padding: 5px 3px;
font-size: 32px;
opacity: 0.7;
filter: grayscale(1);
cursor: pointer;
}
.rating-wrapper label.rating:hover {
filter: grayscale(0.84);
transform: scale(1.1);
transition: 100ms ease;
}
.rating-wrapper input.rating:checked + label.rating {
filter: grayscale(0);
opacity: 1;
transform: scale(1.1);
}
.hide {
display: none;
}
<link rel='stylesheet' href='https://afeld.github.io/emoji-css/emoji.css'>
<form class="rating-wrapper">
<label class="rating-label">How helpful was this?
<div class="ratingItemList">
<input class="rating rating-4" id="rating-4-2" type="radio" value="4" name="rating"/>
<label onmouseover="showUp()" onmouseleave="hide()" class="rating rating-4" for="rating-4-2"><i class="em em-grinning"></i>
</label>
<input class="rating rating-5" id="rating-5-2" type="radio" value="5" name="rating"/>
<label onmouseover="showUp()" onmouseleave="hide()" class="rating rating-5" for="rating-5-2"><i class="em em-star-struck"></i></labe>
</div>
</label>
<label onmouseover="showUp()" onmouseleave="hide()" class="myDIV">Hello world</label>
<div class="hide"><br>I am shown when someone hovers over the image above.</div>
</form>

Related

How do I center text in this scenario?

I want to center the label vertically within the <li>, and add some padding to the label. How can I do this? Sorry if this is a dumb question, this is for a school project due tommorow.
TBH this is mostly stolen from this JSFiddle.
In context. In JSFiddle
:root{
--cream: #ECD9BA;
--wood: #824936;
--slate: #222C2A;
--white: #FFF;
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
background-clip: border-box;
}
.q-wrap{
display: flex;
justify-content: center;
}
.question {
width: 80%;
display: flex;
flex-direction: column;
list-style-type: none;
}
.question li {
width: 100%;
min-height: 5rem;
margin: .5rem 0;
padding: 2rem 0;
position: relative;
}
.question label,
.question input {
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.question input[type="radio"] {
opacity: 0;
}
.question input[type="radio"]:checked+label {
background-color: #E62222;
}
.question input[type="radio"].correct:checked+label {
background-color: #559905;
}
.question label {
font-size: 2rem;
font-weight: 900;
padding: 5px;
background-color: var(--wood);
color: var(--cream);
border: 2px solid var(--cream);
border-radius: 1rem;
cursor: pointer;
z-index: 90;
}
.question label:hover {
filter: brightness(110%)
}
.question input[type="radio"]:checked+label:hover{
filter: brightness(105%);
}
<div class="q-wrap">
<ul class="question">
<li>
<input type="radio" id="b2b" name="amount" />
<label for="b2b">B2B</label>
</li>
<li>
<input type="radio" id="p2p" class="correct" name="amount"/>
<label for="p2p">P2P</label>
</li>
<li>
<input type="radio" id="b2a" name="amount" />
<label for="b2a">B2A</label>
</li>
<li>
<input type="radio" id="c2c" name="amount" />
<label for="c2c">C2C</label>
</li>
</ul>
</div>
I tried adding padding-left: 2rem to .question label, but it doesn't work
Also, how do I make code snippets in Stack Overflow? I don't see the button for it, even though there are screenshots with it there.

Why is the element not centered in the checkbox?

Why is the element not centered in the checkbox?
Must be centered exactly in the middle of the checkbox.
when clicked, it should look like this:
Tried:
left: 50%; top: 50%; - does not seem to work.
I do not understand why horizontal scrolling appears when you click on the checkbox.
overflow-x: hidden; - not a solution
Code:
* {
box-sizing: border-box;
user-select: none;
}
section {
display: flex;
flex-direction: column;
padding: 0.5em;
}
input[type='checkbox'] {
height: 0;
width: 0;
}
input[type='checkbox']+label {
position: relative;
display: flex;
margin: .6em 0;
align-items: center;
color: #9e9e9e;
}
input[type='checkbox']+label>ins {
position: absolute;
display: block;
bottom: 0;
left: 2em;
height: 0;
width: 100%;
overflow: hidden;
text-decoration: none;
}
input[type='checkbox']+label>ins>i {
position: absolute;
bottom: 0;
font-style: normal;
color: #000;
}
input[type='checkbox']+label>span {
display: flex;
justify-content: center;
align-items: center;
margin-right: 0.8em;
width: 1.2em;
height: 1.2em;
background: transparent;
border: 2px solid #E6ECF0;
border-radius: 3px;
cursor: pointer;
transition: all 250ms cubic-bezier(.4, .0, .23, 1);
}
input[type='checkbox']:checked+label>ins {
height: 100%;
}
input[type='checkbox']:checked+label>span {
border: .5em solid #7726E5;
}
input[type='checkbox']:checked+label>span:before {
content: "";
position: absolute;
box-shadow: inset 0px 0px 0px 5px rgba(0, 0, 0, 0.75);
border-radius: 2px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Checkbox</title>
<meta name="viewport" content="width=device-width">
</head>
<body>
<section>
<input id='one' type='checkbox' />
<label for='one'>
<span></span>
Off with your head
<ins><i>Off with your head</i></ins>
</label>
<input id='two' type='checkbox' />
<label for='two'>
<span></span>
Dance ’til you’re dead
<ins><i>Dance ’til you’re dead</i></ins>
</label>
<input id='three' type='checkbox' />
<label for='three'>
<span></span>
Heads will roll
<ins><i>Heads will roll</i></ins>
</label>
<input id='four' type='checkbox' />
<label for='four'>
<span></span>
On the floor
<ins><i>On the floor</i></ins>
</label>
</section>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</body>
</html>
Honestly, it looks pretty well centered to me. The horizontal scroll appears because your black text (which you show on top of the grey text) is inside an element with 100% width, but its parent also contains the checkbox. I'd suggest just making the color of the original label darker, instead of using a second layer of text.
Here's an edit:
* { box-sizing: border-box; user-select: none; }
section{
display: flex;
flex-direction: column;
padding: 0.5em;
}
input[type='checkbox']{ height: 0; width: 0; }
input[type='checkbox'] + label{
position: relative;
display: flex;
margin: .6em 0;
align-items: center;
color: #9e9e9e;
}
input[type='checkbox'] + label > span{
display: flex;
justify-content: center;
align-items: center;
margin-right: 0.8em;
width: 1.2em;
height: 1.2em;
background: transparent;
border: 2px solid #E6ECF0;
border-radius: 3px;
cursor: pointer;
transition: all 250ms cubic-bezier(.4,.0,.23,1);
}
input[type='checkbox']:checked + label > span{
border: .5em solid #7726E5;
}
input[type='checkbox']:checked + label > span:before{
content: "";
position: absolute;
box-shadow: inset 0px 0px 0px 5px rgba(0,0,0,0.75);
border-radius: 2px;
}
input[type='checkbox']:checked + label {
color: unset;
}
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Checkbox</title>
<meta name="viewport" content="width=device-width">
</head>
<body>
<section>
<input id='one' type='checkbox' />
<label for='one'>
<span></span>
Off with your head
</label>
<input id='two' type='checkbox' />
<label for='two'>
<span></span>
Dance ’til you’re dead
</label>
<input id='three' type='checkbox' />
<label for='three'>
<span></span>
Heads will roll
</label>
<input id='four' type='checkbox' />
<label for='four'>
<span></span>
On the floor
</label>
</section>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</body>
</html>
If you want the white square in the middle of your checkbox to be wider (as it looks in your png), you should make the border smaller here:
input[type='checkbox']:checked + label > span{
border: .5em solid #7726E5;
}

Circumvent id selectors in a checkbox hack

I've posted about this project before. Twice, actually. And while the answers have helped me to better understand my situation, they haven't really been applicable to my situation. I blame myself because I was posting a skeletal version of the final code which didn't fully illustrate what I needed to accomplish.
Essentially: I need to integrate a relatively simple checkbox hack into a CMS, but the CMS strips id selectors. Hence, code that ought to look something like this:
<input type="checkbox" name="thisisaname" id="thisisanid"><label class="thisisanid" for="thisisanid">Type 1</label>
...ends up like this:
<input type="checkbox" name="thisisaname"><label class="thisisanid" for="thisisanid">Type 1</label>
Predictably, this breaks everything, and ostensibly any adaptation appears to be impossible. There is no CMS-specific alternative like ClientID=. Neither jQuery nor JavaScript are available to me (they're also stripped out by the CMS).
It's a case of something being extraordinarily simple to do, but being constrained by a CMS that multiplies the difficulty to the point where I'm uncertain if it's even possible. I am not a CSS maven. I know it only as much as I need to do these little projects for a few friends, and I apologize for posting about this yet again, but it's driving me crazy not knowing if this is something which ought to be shelved.
This is the code. Obviously, it's sloppy and it isn't in its fully-styled form, but it's close enough that I think it's a better example than what I've posted in the past:
#basesurround {
background: #000000cc;
margin: 0 auto;
width: 75%;
}
.information-wrap { display:flex; vertical-align:top;}
.information-wrap aside { background: #00000066; vertical-align: top; flex: 1 1 250px; min-width: 150px; padding: 0; max-width: 200px; }
.information-wrap main { vertical-align: top; display: flex; flex-direction: row; flex-wrap: wrap; width: 85%; justify-content: center; padding: 0 0 25px 25px; }
.information-wrap label { background: #000000cc; width: 100%; display: inline-block; border-bottom: 1px solid #000000; color: #9FC3C9; text-transform: capitalize; font-weight: 100; font-size: 11px; letter-spacing: 1px; cursor: pointer; transition: all 0.7s ease; position: relative; padding: 10px 10px 10px 30px; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; word-break: break-word; line-height: 125%; }
.information-wrap label:after { content: ""; width: 25px; height: 100%; position: absolute; left: 0; top: 0; background: #000000; filter: contrast(85%); }
.information-wrap details { position: relative; }
.information-wrap details summary::-webkit-details-marker { display: none; }
.information-wrap details summary::before { content: ""; position: absolute; left: 0; background: ; width: 1.5em; height: 1.5em; transition: transform 0.1s linear;}
.information-wrap summary { width: 100%; padding: 20px; padding-left: 25px; border-bottom: 1px solid #000000; background: #9FC3C9; font-family: Proxima; font-weight: 100; text-transform: uppercase; letter-spacing: 2px; color: #000000; -webkit-transition: all 1s ease; transition: all 1s ease; }
.information-wrap summary:hover { color: #ffffff4a; }
.information-wrap summary:focus {outline: none;}
.information-wrap details[open] > summary { background: #000000; filter: contrast(85%); color: #ffffff; }
.information-wrap details[open] > summary ~ * { animation: open 1s ease; }
.information-wrap details[open] summary:before {transform: rotate(90deg);}
.infocard { flex: 0 0 32.3%; display: inline-block; vertical-align: top; font-family: Proxima, Arial, Helvetica, Sans-Serif; position: relative; margin: .5%; align-items: center; justify-content: center; overflow: hidden; color: #000000; text-align: center; line-height: 160%; background-color: #141414; height: 300px; min-width: 300px; -webkit-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1); -moz-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1); -ms-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1); -webkit-border-radius: 5px; -moz-border-radius: 5px; -ms-border-radius: 5px; border-radius: 5px; min-width:250px; border: 1px solid #000000;}
.infocard figure { border: 10px solid #DADCDB; margin: 10px 10px; padding: 0; display: inline-block; position: relative;}
.infocard figure img { display: block; height: auto; max-width: 100%; }
.infocard figcaption { color: #000000; font: 400 18px/26px Proxima, Arial, Helvetica, Sans-Serif; padding: .2em 0; position: absolute; bottom: 0; text-align: center; width: 100%; }
.infocard figcaption span { font-size: 14px; color: #ffffff }
.infocard:last-of-type {margin-bottom: 200px;}
.infocard .icons { top: -7px; position: relative; color:#ffffff}
.information-wrap input { display: none; }
input:checked ~ main .infocard { display: none; }
/* INFOCARD TYPE LABELS & CHECK CONTROLS */
/* TYPE SET #1 */
#infotypeone_cont:checked ~ aside .infotypeone_cont,
#infotypetwo_cont:checked ~ aside .infotypetwo_cont,
#infotypethree_cont:checked ~ aside .infotypethree_cont,
#infotypefour_cont:checked ~ aside .infotypefour_cont,
#infotypefive_cont:checked ~ aside .infotypefive_cont
{ background: #000000; filter: contrast(85%); }
#infotypeone_cont:checked ~ main .infotypeone,
#infotypetwo_cont:checked ~ main .infotypetwo,
#infotypethree_cont:checked ~ main .infotypethree,
#infotypefour_cont:checked ~ main .infotypefour,
#infotypefive_cont:checked ~ main .infotypefive
{display: inline-block;}
/* TYPE SET #2 */
#factiontypeone_cont:checked ~ aside .factiontypeone_cont,
#factiontypetwo_cont:checked ~ aside .factiontypetwo_cont,
#factiontypethree_cont:checked ~ aside .factiontypethree_cont,
#factiontypefour_cont:checked ~ aside .factiontypefour_cont,
#factiontypefive_cont:checked ~ aside .factiontypefive_cont
{ background: #000000; filter: contrast(85%); }
#factiontypeone_cont:checked ~ main .factiontypeone,
#factiontypetwo_cont:checked ~ main .factiontypetwo,
#factiontypethree_cont:checked ~ main .factiontypethree,
#factiontypefour_cont:checked ~ main .factiontypefour,
#factiontypefive_cont:checked ~ main .factiontypefive
{display: inline-block;}
/* TYPE COLORS #1 */
.infotypeone {background-color: #ff00004d;}
.infotypetwo {background-color: #0076ff4d;}
.infotypethree {background-color: #ffac004d;}
.infotypefour {background-color: #ff00fc4d;}
.infotypefive {background-color: #d800004d;}
/* INFORMATION CARDS */
.infocard * { -webkit-box-sizing: border-box; box-sizing: border-box; -webkit-transition: all 0.25s ease; transition: all 0.25s ease; }
.infocard .background { width: 100%; vertical-align: top; opacity: 0.2; -webkit-filter: grayscale(100%) blur(10px); filter: grayscale(100%) blur(10px); -webkit-transition: all 2s ease; transition: all 2s ease; }
.infocard figcaption { width: 100%; padding: 15px 25px; position: absolute; left: 0; top: 50%; }
figure.infocard img { display: inline;}
figure.infocard .profile {border-radius: 50%; position: absolute; bottom: 50%; left: 50%; max-width: 100px; opacity: 1; box-shadow: 3px 3px 20px rgba(0, 0, 0, 0.5); border: 2px solid rgba(255, 255, 255, 0.5); -webkit-transform: translate(-50%, 0%); transform: translate(-50%, 0%); }
figure.infocard img.profile { height: 100px; width: 100px; }
figure.infocard h3 { line-height: 160%; margin: 0 0 5px; font-weight: 100; font-family: Proxima, Arial, Helvetica, Sans-Serif; text-transform: uppercase; text-indent: 0px; }
figure.infocard h3 a { text-decoration: none; letter-spacing: .3em; color: #9FC3C9cc; line-height: 18px; font-size: 15px; -webkit-transition: all 1s ease; transition: all 1s ease; }
figure.infocard h3 a:hover {opacity: .3; }
figure.infocard h3 span a, figure.infocard h3 span { font-size: 8px; opacity: 0.75; letter-spacing: 2px; display: inline-block; line-height: 10px; }
figure.infocard i { padding: 10px 5px; display: inline-block; font-size: 32px; color: #ffffff; text-align: center; opacity: 0.65;}
figure.infocard a {text-decoration: none; background-size: 0;}
figure.infocard i:hover {opacity: 1; -webkit-transition: all 0.35s ease; transition: all 0.35s ease; }
figure.infocard:hover .background, figure.infocard.hover .background {-webkit-transform: scale(1.3);transform: scale(1.3);}
<div id="basesurround">
<form>
<div class="information-wrap">
<!--- BEGIN INFORMATION CONTROLLER :: CHECKBOX --->
<input type="checkbox" name="cont" id="infotypeone_cont">
<input type="checkbox" name="cont" id="infotypetwo_cont">
<input type="checkbox" name="cont" id="infotypethree_cont">
<input type="checkbox" name="cont" id="infotypefour_cont">
<input type="checkbox" name="cont" id="infotypefive_cont">
<input type="checkbox" name="cont" id="factiontypeone_cont">
<input type="checkbox" name="cont" id="factiontypetwo_cont">
<input type="checkbox" name="cont" id="factiontypethree_cont">
<input type="checkbox" name="cont" id="factiontypefour_cont">
<input type="checkbox" name="cont" id="factiontypefive_cont">
<!--- END INFORMATION CONTROLLER :: CHECKBOX --->
<aside>
<!--- BEGIN INFORMATION CONTROLLER :: LABELS --->
<details><summary>
SUBMENU TITLE
</summary>
<label class="infotypeone_cont" for="infotypeone_cont">Check 1</label>
<label class="infotypetwo_cont" for="infotypetwo_cont">Check 2</label>
<label class="infotypethree_cont" for="infotypethree_cont">Check 3</label>
<label class="infotypefour_cont" for="infotypefour_cont">Check 4</label>
<label class="infotypefive_cont" for="infotypefive_cont">Check 5</label>
</details>
<!--- END INFORMATION CONTROLLER :: LABELS --->
<!--- BEGIN INFORMATION CONTROLLER --->
<details><summary>
SUBMENU TITLE
</summary>
<label class="factiontypeone_cont" for="factiontypeone_cont">Faction 1</label>
<label class="factiontypetwo_cont" for="factiontypetwo_cont">Faction 2</label>
<label class="factiontypethree_cont" for="factiontypethree_cont">Faction 3</label>
<label class="factiontypefour_cont" for="factiontypefour_cont">Faction 4</label>
<label class="factiontypefive_cont" for="factiontypefive_cont">Faction 5</label>
</details>
<!--- END INFORMATION CONTROLLER --->
</aside>
<main>
<!--- BEGIN INFORMATION CARD --->
<figure class="infocard infotypeone factiontypeone">
<img src="ICON" class="background"/>
<img src="ICON" class="profile"/>
<figcaption> <h3>
TITLE
<br><span>
SUBTITLE ●
MAIN LINK <br>
INFO #2 | INFO #3
</span></h3><div class="icons">
<i class="ion-ios-person-outline"></i>
<i class="ion-ios-email-outline"></i>
<i class="ion-ios-location-outline"></i>
</div></figcaption></figure>
<!--- END INFORMATION CARD --->
<!--- BEGIN INFORMATION CARD --->
<figure class="infocard infotypetwo factiontypetwo">
<img src="ICON" class="background"/>
<img src="ICON" class="profile"/>
<figcaption> <h3>
TITLE
<br><span>
SUBTITLE ●
MAIN LINK <br>
INFO #2 | INFO #3
</span></h3><div class="icons">
<i class="ion-ios-person-outline"></i>
<i class="ion-ios-email-outline"></i>
<i class="ion-ios-location-outline"></i>
</div></figcaption></figure>
<!--- END INFO CARD --->
<!--- BEGIN INFO CARD --->
<figure class="infocard infotypethree factiontypethree">
<img src="ICON" class="background"/>
<img src="ICON" class="profile"/>
<figcaption> <h3>
TITLE
<br><span>
SUBTITLE ●
MAIN LINK <br>
INFO #2 | INFO #3
</span></h3><div class="icons">
<i class="ion-ios-person-outline"></i>
<i class="ion-ios-email-outline"></i>
<i class="ion-ios-location-outline"></i>
</div></figcaption></figure>
<!--- END INFO CARD --->
<!--- BEGIN INFO CARD --->
<figure class="infocard infotypefour factiontypefour">
<img src="ICON" class="background"/>
<img src="ICON" class="profile"/>
<figcaption> <h3>
TITLE
<br><span>
SUBTITLE ●
MAIN LINK <br>
INFO #2 | INFO #3
</span></h3><div class="icons">
<i class="ion-ios-person-outline"></i>
<i class="ion-ios-email-outline"></i>
<i class="ion-ios-location-outline"></i>
</div></figcaption></figure>
<!--- END INFO CARD --->
<!--- BEGIN INFO CARD --->
<figure class="infocard infotypefive factiontypefive">
<img src="ICON" class="background"/>
<img src="ICON" class="profile"/>
<figcaption> <h3>
TITLE
<br><span>
SUBTITLE ●
MAIN LINK <br>
INFO #2 | INFO #3
</span></h3><div class="icons">
<i class="ion-ios-person-outline"></i>
<i class="ion-ios-email-outline"></i>
<i class="ion-ios-location-outline"></i>
</div></figcaption></figure>
<!--- END INFO CARD --->
</main></div>
</form></div>
I am in a quandary. I'm not very knowledgeable in CSS, and this CMS (which I must use, unfortunately) makes even the easiest of tasks inordinately difficult. Here's what I've tried:
Using nth-child / nth-of-type selectors: I was given this idea by
Temani Afif. This solution is elegant and I loved it, but
unfortunately, because of what the code will be used for, the
structure will vary often.
Placing the input above the labels: I've been advised to look
into this, but I can't find any information on how to properly code
with the input above the label, so I'm unsure if it can be used in this
situation.
I thought about mimicking the behavior I want using
[attribute|=value] selectors instead of id, but I haven't been
able to get it to work. I don't know, though, whether I'm being
limited by the code or my own incompetence, so I'm unsure if it's
something worth looking into further.
So… Is there a recommended means of overcoming the id= limitations I've missed in my research?
FWIW, the purpose of this is to create a simple(ish) code where it's easy to append the INFO CARD part of the code as many times as needed to edit this for sorting movies/books/other information of that nature, while maintaining the ease at which one can change the figure class=.
The issue here is the rather limited way in which the for attribute works inside a <label> - it looks for a form control with the corresponding id. (Only the id will do - no other attribute.)
If it cannot find one, then no form control ends up being associated with the <label>... consequently, the checkbox hack, which relies on the for attribute working, cannot produce the intended effect.
Since we can't add the id to the checkbox in the document's initial mark up, why not, instead, add the id to the checkbox dynamically, by accessing the Document Object Model (DOM)?
This is easily done in a single line:
document.querySelector('[name="thisisaname"]').id = 'thisisanid';
See the Working Example below, noting that the id is not present in the initial markup:
document.querySelector('[name="thisisaname"]').id = 'thisisanid';
label {
cursor: pointer;
}
label:hover {
font-weight: bold;
text-decoration: underline;
}
input[type=checkbox],
input[type=checkbox] + p {
opacity: 0;
}
input[type=checkbox] + p {
transition: opacity 1s linear;
}
input[type=checkbox]:checked + p {
opacity: 1;
}
<label class="thisisanid" for="thisisanid">Click Me</label>
<input type="checkbox" name="thisisaname">
<p>Checkbox hack is working</p>

New to CSS and coding. Organizing radio buttons and divs for a beginner gallery

So the issue I can't seem to solve is how to move the obscured divs under the radio+label buttons.
My Html
My CSS
/*color palette: abls
[lightest to darkest]
#eeeeee
#eaffc4
#b6c399
#6a856a
#333333
*/
body {
background-color: #333333;
font-family: monospace;
display: flex;
justify-content: center;
}
div {
/*background-color: red;*/
width: 100%;
height: 100%;
justify-content: center;
}
/*aesthetics for header*/
.Ghead {
font-size: 250%;
color: #eeeeee;
font-weight: lighter;
text-align: center;
border-color: red;
}
/*color for the 3 lines*/
hr:nth-child(1) {
border-color: #eaffc4;
max-width: 20%;
}
hr:nth-child(2) {
border-color: #b6c399;
max-width: 25%;
}
hr:nth-child(3) {
border-color: #6a856a;
max-width: 30%;
}
/*style for radio button container*/
.mGalD {
position: relative;
/*background-color: blue;*/
display: flex;
}
input[type=radio] {
display:none;
}
/*handles aesthetics of active buttons*/
label {
padding: 5px 7px;
border-radius: 5px;
display: inline-block;
font-size: 14px;
color: #6a856a;
}
input:checked + label {
background-color: #eaffc4;
}
/*handles the appearance of active divs in the display area*/
label + div {
position: relative;
color: red;
border: 2pt solid #eaffc4;
border-radius: 5px;
margin: 5px 0 0 0;
display: none;
max-width: 50%;
}
input:checked + label + div {
display: block;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="./NewbTests.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" type="image/png" href="./Assets/SumisoulLogo.png">
<title>Viewport</title>
</head>
<body>
<div>
<h1>
<!--title and aesthetics for the head of the page-->
<div class="Ghead">
Viewport
<hr>
<hr>
<hr>
</div>
</h1>
<!--Labeled Radio buttons which activate css to reveal divs-->
<div class="mGalD">
<input type="radio" name="gal" id="g1" value="1">
<label for="g1">gallery 1</label><div>one</div>
<input type="radio" name="gal" id="g2" value="2">
<label for="g2">gallery 2</label><div>two</div>
<input type="radio" name="gal" id="g3" value="3">
<label for="g3">gallery 3</label><div>three</div>
</div>
</div>
</body>
</html>
I would have linked a few images to illustrate what is happening but I'm limited in links.
In essence;
Before:
(button 1)(button 2)(button 3)
Upon clicking any button:
(button 1)[_______________________] (button 2)(button 3)
The div shows up on the side of the corresponding button.
I don't really know what to do to have it align in a column without separating all of the divs and breaking the inline style of the buttons
Hope this works
body, html {
padding: 0;
margin: 0;
}
body {
background: linear-gradient(top left, red, orange);
}
span {
display: none;
position: absolute;
max-width: 450px;
left: 17px;
top: 48px;
padding: 3px;
min-height: 30px;
border-top: 1px solid #d3d3d3;
}
label {
cursor: pointer;
display: inline-block;
padding: 10px;
margin: 10px 0 0 0;
background: #e0e0e0;
color: black;
}
label:first-child {
margin-left: 10px;
}
input {
display: none;
}
input:checked + span {
display: initial;
}
h3 {
border-top: 1px solid;
padding-top: 5px;
position: absolute;
top: 150px;
left: 15px;
}
<label for="btn_one">Gallery 1</label>
<input type="radio" id="btn_one" name="nesto" checked="checked"/>
<span class="tab1">Gallery One</span>
<label for="btd_two">Gallery 2</label>
<input type="radio" id="btd_two" name="nesto"/>
<span class="tab2">Gallery two</span>
<label for="btd_tree">Gallery 3</label>
<input type="radio" id="btd_tree" name="nesto"/>
<span class="tab2">Gallery Three</span>

Creating Quiz: Why is it not working in Safari

The Quiz is perfectly showing in firefox and Chrome, just Safari seems to have some issues. It instantly shows the last test instead of the first like chrome and firefox are doing. What am I doing wrong. (I am using Safari Version 8.0.2 (10600.2.5)).
body {
font-size: 100%;
background: white;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, sans-serif;
font-weight: 300; }
input[type=radio],
input[type=checkbox] {
font-size: 0.8em;
position: relative;
display: inline-block;
vertical-align: middle;
border: 0.1em solid #bbbbbb;
background: none;
padding: 0.2em;
margin: 0 0.2em;
font-family: Consolas, "Courier New", monospace;
width: 1em;
height: 1em;
box-sizing: border-box;
-webkit-appearance: none; }
input[type=radio]:focus,
input[type=checkbox]:focus {
outline: 0;
border-color: #335599; }
input[type=radio] {
border-radius: 100%;
background-clip: content-box; }
input[type=radio]:checked {
background-color: #44aacc; }
h1 {
font-size: 2em;
margin: 1em auto;
text-align: center; }
.test {
position: absolute;
top: 25%;
bottom: 25%;
right: 25%;
left: 25%;
background: white; }
.test a {
display: block;
text-align: center;
padding: 0.5em 1em;
border-radius: 3px;
text-decoration: none;
background: #666666;
color: white; }
.test a:hover {
background: #4d4d4d; }
.test .question {
font-size: 1.3em;
margin: 0.5em 0;
border-bottom: 2px dashed #666666; }
.test .answer {
display: inline-block;
padding: 0.5em 1em;
cursor: pointer;
border-bottom: 4px solid white; }
.test .answer:hover {
border-color: #bbbbbb; }
.test .test {
transform: translate3d(150%, 0, 0);
transition: transform 100ms;
top: 0;
bottom: 0;
right: 0;
left: 0; }
.test .false:checked + .answer {
border-color: #dd4411; }
.test .true:checked ~ .test {
transform: translate3d(0, 0, 0); }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="quiz_test.css" type="text/css">
<meta>
<title>test</title>
</head>
<body>
<h1>A simple Quiz in pure CSS</h1>
<div class="test">
<h3 class="question">1 + 2 = ?</h3>
<input type="radio" name="1" id="1-1" class="false"> <label for="1-1" class="answer">12</label><br>
<input type="radio" name="1" id="1-2" class="true"> <label for="1-2" class="answer">3</label>
<div class="test">
<h3 class="question">red - green, orange - blue, yellow - ?</h3>
<input type="radio" name="2" id="2-1" class="false"> <label for="2-1" class="answer">magenta</label><br>
<input type="radio" name="2" id="2-2" class="true"> <label for="2-2" class="answer">purple</label><br>
<input type="radio" name="2" id="2-3" class="false"> <label for="2-3" class="answer">cyan</label>
<div class="test">
<h3 class="question">name the fish!</h3>
<input type="radio" name="3" id="3-1" class="true"> <label for="3-1" class="answer">shark</label><br>
<input type="radio" name="3" id="3-2" class="false"> <label for="3-2" class="answer">dolphin</label><br>
<input type="radio" name="3" id="3-3" class="false"> <label for="3-3" class="answer">whale</label><br>
<input type="radio" name="3" id="3-4" class="false"> <label for="3-4" class="answer">all of the above</label>
<div class="test">
<h1>YOU WIN!!!</h1>
play again
</div>
</div>
</div>
</div>
</body>
</html>
The Problem is that webkit doesnt understand the transition and transform attributes without vendor prefixes. Copy every line of transition and transform and replace the duplicate with -webkit-transision and -webkit- transform.
body {
font-size: 100%;
background: white;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, sans-serif;
font-weight: 300; }
input[type=radio],
input[type=checkbox] {
font-size: 0.8em;
position: relative;
display: inline-block;
vertical-align: middle;
border: 0.1em solid #bbbbbb;
background: none;
padding: 0.2em;
margin: 0 0.2em;
font-family: Consolas, "Courier New", monospace;
width: 1em;
height: 1em;
box-sizing: border-box;
-webkit-appearance: none; }
input[type=radio]:focus,
input[type=checkbox]:focus {
outline: 0;
border-color: #335599; }
input[type=radio] {
border-radius: 100%;
background-clip: content-box; }
input[type=radio]:checked {
background-color: #44aacc; }
h1 {
font-size: 2em;
margin: 1em auto;
text-align: center; }
.test {
position: absolute;
top: 25%;
bottom: 25%;
right: 25%;
left: 25%;
background: white; }
.test a {
display: block;
text-align: center;
padding: 0.5em 1em;
border-radius: 3px;
text-decoration: none;
background: #666666;
color: white; }
.test a:hover {
background: #4d4d4d; }
.test .question {
font-size: 1.3em;
margin: 0.5em 0;
border-bottom: 2px dashed #666666; }
.test .answer {
display: inline-block;
padding: 0.5em 1em;
cursor: pointer;
border-bottom: 4px solid white; }
.test .answer:hover {
border-color: #bbbbbb; }
.test .test {
transform: translate3d(150%, 0, 0);
transition: transform 100ms;
-webkit-transform: translate3d(150%, 0, 0);
-webkit-transition: transform 100ms;
top: 0;
bottom: 0;
right: 0;
left: 0; }
.test .false:checked + .answer {
border-color: #dd4411; }
.test .true:checked ~ .test {
transform: translate3d(0, 0, 0);
-webkit-transform: translate3d(0, 0, 0);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="quiz_test.css" type="text/css">
<meta>
<title>test</title>
</head>
<body>
<h1>A simple Quiz in pure CSS</h1>
<div class="test">
<h3 class="question">1 + 2 = ?</h3>
<input type="radio" name="1" id="1-1" class="false"> <label for="1-1" class="answer">12</label><br>
<input type="radio" name="1" id="1-2" class="true"> <label for="1-2" class="answer">3</label>
<div class="test">
<h3 class="question">red - green, orange - blue, yellow - ?</h3>
<input type="radio" name="2" id="2-1" class="false"> <label for="2-1" class="answer">magenta</label><br>
<input type="radio" name="2" id="2-2" class="true"> <label for="2-2" class="answer">purple</label><br>
<input type="radio" name="2" id="2-3" class="false"> <label for="2-3" class="answer">cyan</label>
<div class="test">
<h3 class="question">name the fish!</h3>
<input type="radio" name="3" id="3-1" class="true"> <label for="3-1" class="answer">shark</label><br>
<input type="radio" name="3" id="3-2" class="false"> <label for="3-2" class="answer">dolphin</label><br>
<input type="radio" name="3" id="3-3" class="false"> <label for="3-3" class="answer">whale</label><br>
<input type="radio" name="3" id="3-4" class="false"> <label for="3-4" class="answer">all of the above</label>
<div class="test">
<h1>YOU WIN!!!</h1>
play again
</div>
</div>
</div>
</div>
</body>
</html>
P.S. The snippet above doesn't run correctly in the preview box because some of stackoverflows css is interfering. It does however run correctly in the full page preview.