Circumvent id selectors in a checkbox hack - html

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>

Related

Cant make a logo turn on click in a accordion tab

No matter what I try, I just cant get the icon to turn on click.
Here I've posted my code for the section, ok so I want the label::after to rotate 90deg when you click on the label, here is what I'm mainly using:
#accordion label + input[type="radio"]:checked + label::after
I had the same one, but instead of label::after it was .content, the .content one worked normally but as soon as I try to use anything regarding the label itself it doesn't work at all, can some please tell me what I'm doing wrong?
#accordion {
margin: 100px auto;
max-width: 500px;
}
#accordion li {
list-style: none;
width: 100%;
margin-bottom: 0.5rem;
padding: 5px;
border-radius: 4px;
background: none;
}
#accordion li label {
padding: 5px;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 1.7rem;
font-weight: 700;
cursor: pointer;
color: #000000;
background: white;
border: 2px solid black;
border-radius: 4px;
}
#accordion .content {
background: none;
}
#accordion .content li p {
background: none;
}
#accordion label+input[type="radio"] {
display: none;
}
#accordion .content {
padding: 0 10px;
line-height: 26px;
max-height: 0;
overflow: hidden;
color: black;
transition: max-height 1s;
}
#accordion label+input[type="radio"]:checked+.content {
max-height: 1000px;
}
#accordion label:hover {
color: #ffffff;
background-color: #0062cc;
transition: ease all 0.35s;
font-size: 2rem;
border: 2px solid white;
}
#accordion .tab-close {
width: 35%;
}
#accordion label::after {
content: "\276F";
width: 1em;
height: 1em;
text-align: center;
}
#accordion label+input[type="radio"]:checked+label::after {
display: flex;
transform: rotate(90deg);
transition: 1s;
}
<section class="quantity" id="Quantity">
<div class="services-container">
<div class="quantity-left">
<div class="content">
<h1>Quantity Surveying</h1>
<p>
We at BGQS Consulting strive to offer the highest quality QS service in SA and our main objective is to maintain the highest possible standards with regards to: Services to the client, Effectiveness and competence, Integrity, secrecy, honesty and loyalty,
Quality of documentation, Experience and scope of knowledge, Application of the latest technology, Professionalism and true commitment, Punctuality and response time and Friendliness. Here are some of the steps in our process:
</p>
<ul id="accordion">
<li>
<label for="quantity-first">Estimations</label>
<input type="radio" name="accordion" id="quantity-first">
<div class="content">
<ul>
<li>Preparing capital cost estimates for budget purposes and project approval through all the phases pre-concept to feasibility.</li>
<li>Creating a compilation of budget cost though our in-house database of previously completed projects, quotations from equipment and special services suppliers.</li>
<li>Conducting preliminary measures and elemental cost estimating.</li>
</ul>
</div>
</li>
<li>
<label for="quantity-second">Pre-Contract Services</label>
<input type="radio" name="accordion" id="quantity-second">
<div class="content">
<ul>
<li>Preparing contract conditions, including special conditions.</li>
<li>Standardisation of contract conditions and special conditions for any particular project</li>
<li>Preparing tender bills of quantities for all construction contracts (e.g., civils, building, demolition works, structural, mechanical, piping, electrical and instrumentation, etc.)</li>
<li>Assistance with compilation of vendor lists for client approval.</li>
<li>Drafting of enquiry documents for tender purposes.</li>
<li>Commercial tender evaluations, clarifications and adjudication reports.</li>
</ul>
</div>
</li>
This is because your <label> element is below the radio <input> in the HTML, so in terms of styling, the label cannot infer when the input is "checked" or not. Lets fix it:
#accordion {
max-width: 500px;
padding: 0;
}
#accordion li {
list-style: none;
width: 100%;
margin-bottom: 0.5rem;
padding: 5px;
border-radius: 4px;
background: none;
}
#accordion li label {
padding: 5px;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 1.7rem;
font-weight: 700;
cursor: pointer;
color: #000000;
background: white;
border: 2px solid black;
border-radius: 4px;
}
#accordion .content {
background: none;
}
#accordion .content li p {
background: none;
}
#accordion label+input[type="radio"] {
display: none;
}
#accordion .content {
padding: 0 10px;
line-height: 26px;
max-height: 0;
overflow: hidden;
color: black;
transition: max-height 1s;
}
/* Changhed + to ~ since the order of HTML changed */
#accordion input[type="radio"]:checked ~ .content {
max-height: 1000px;
}
#accordion label:hover {
color: #ffffff;
background-color: #0062cc;
transition: ease all 0.35s;
font-size: 2rem;
border: 2px solid white;
}
#accordion .tab-close {
width: 35%;
}
#accordion label::after {
content: "\276F";
width: 1em;
height: 1em;
text-align: center;
transition: 1s; /* transition should be here and not below */
}
#accordion input[type="radio"]:checked + label::after {
transform: rotate(90deg);
}
<ul id="accordion">
<li>
<input type="radio" hidden name="accordion" id="quantity-first" />
<label for="quantity-first">Estimations</label>
<div class="content">
<ul>
<li>Preparing capital cost estimates for budget purposes and project approval through all the phases pre-concept to feasibility.</li>
<li>Creating a compilation of budget cost though our in-house database of previously completed projects, quotations from equipment and special services suppliers.</li>
<li>Conducting preliminary measures and elemental cost estimating.</li>
</ul>
</div>
</li>
<li>
<input type="radio" hidden name="accordion" id="quantity-second" />
<label for="quantity-second">Pre-Contract Services</label>
<div class="content">
<ul>
<li>Preparing contract conditions, including special conditions.</li>
<li>Standardisation of contract conditions and special conditions for any particular project</li>
<li>Preparing tender bills of quantities for all construction contracts (e.g., civils, building, demolition works, structural, mechanical, piping, electrical and instrumentation, etc.)</li>
<li>Assistance with compilation of vendor lists for client approval.</li>
<li>Drafting of enquiry documents for tender purposes.</li>
<li>Commercial tender evaluations, clarifications and adjudication reports.</li>
</ul>
I advise using input of type checkbox and not radio because radio accordion items cannot be "closed/collapsed" unless another item is "opened". for UX, it's better to use type checkbox .

CSS Display separate text on Hover or Click on Image

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>

Search input field like TripAdvisor functionality

I am trying to achieve a similar search form like tripadvisors (at least UI and Front Design speaking) but i have till now a few issues.
On the first photo is how is my search bar with the class name for testing purposes "asdf".
so in the second picture we have the issue, the expandable part of the form being a bit wider than the input search field.
In the third pict if with have the issue if i try to assign the same width of the rest of the form with the input["text"] field of the search form.
Below my basic html and css code.
HTML
<div class="aboutUs">
<div class="textFlexContainer">
<div class="text-box">
<h1 class="heading-primary">
<span class="heading-primary-main">City</span>
<span class="heading-primary-sub">is where summer happens</span>
</h1>
<form class="search-box" action="/search">
<input class="asdf" type="search" placeholder="Explore City">
<div class="search-page">
<h3>Explore City</h3>
<ul class="search-menu-list">
<li>Our Daily Suggestions</li>
<li>Shopping</li>
<li>City Tours</li>
<li>Restaurants</li>
<li>Events</li>
<li>Things to do</li>
</ul>
<h3>Recently Reviewed</h3>
</div>
</form>
</div>
</div>
</div>
And CSS
.search-box{
display: block;
position: relative;
overflow: hidden;
z-index:15;
padding:2rem;
}
.asdf {
width: 80%;
padding:2rem;
border: none;
outline: none;
border-bottom:2px solid white;
margin-top:2.5rem;
font-size: inherit;
background-color: green;
color: #fff;
}
h3{
color:#fff;
margin-top:2rem;
}
.search-page {
height: fit-content;
background-color:green;
text-align: center;
padding:4rem 0;
transition: all 300ms ease-in-out;
display: none;
}
.search-page.visible {
display: block;
transition: all 300ms ease-in-out;
}
.search-page .search-menu-list{
display:flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.search-page .search-menu-list li{
list-style: none;
}
.search-page .search-menu-list li a:hover{
transform: translateY(-1rem);
}
.search-page .search-menu-list li a{
display: inline-block;
color:#fff;
padding:5px;
list-style: none;
text-decoration: none;
margin-right: 2.5rem;
transition: all 300ms ease-in-out;
border: solid 2px white;
border-radius: 1rem;
padding: 11px 13px 11px 14px;
margin: 10px;
}
.aboutUs{
display: grid;
background-image: linear-gradient(to right bottom, rgba(53, 170, 120, 0.8), rgba(20, 139, 102, 0.8)) ,url(../img/ch4.jpg);
background-size: cover;
background-position: center;
grid-column-start: 1;
grid-column-end: 13;
grid-row-start: 2;
grid-row-end: 3;
}
.textFlexContainer{
display:flex;
align-self: center;
}
.heading-primary {
color:#fff;
text-transform: uppercase;
}
.heading-primary-main{
display: block;
font-size: 6rem;
font-weight: 400;
letter-spacing: 3.5rem;
}
.heading-primary-sub {
display: block;
font-size: 2rem;
font-weight: 400;
letter-spacing: 1.8rem;
}
.text-box {
display: inline-block;
/* This content should just be in the normal flow of the page */
/*
position: absolute
top:30%;
left:50%;
transform: translate(-50% ,-50%);
*/
text-align: center;
/* Because we're using flexbox, we can center the content both horizontally and vertically
* using this declaration
*/
margin: auto;
}
Additionaly i would love if when i click on the search bar field and the form is expanding to not have the letters above the search bar to getting squeezed on the top.
Not entirely sure what you need here but here's a fix for image 3. Adding 2 lines of code to your .search-page fixes the alignment issue.
.search-page{
height: fit-content;
background-color:green;
width:80%;
text-align: center;
padding:4rem 0;
transition: all 300ms ease-in-out;
display: all;
}
The width sets it to line up with the size of the text input of the form. The margin: 0 auto; is a good way to quickly center elements in css.
I can't see the expandable part when I tested your code but have you tried changing the width to become small and then do a margin-left to move de expandable part and align it with the search?

Uncheck checkboxes in html and css only?

I've been trying to create something similar to google images (when you click on an image it 'opens' a larger version with information and links and when you click again it closes).
My task (school) is to realise this with only pure html(5) and css(3), so no javascript or JQuery or any other programming language.
I already tried using checkboxes and radio. When I use checkboxes, it will expand an 'informationbox' which will not close when I open the next one. There only needs to be one open at a time.
Therefore I also tried using radio. The problem here is that I'm not able to deselect them.
Is it possible to realise this with only html and css?
Is there anyone who can help me?
Thanks in advance!
.folder {
width: 100%;
visibility: hidden;
}
.fold {
visibility: hidden;
background-color: #8b0000;
width: 60%;
height: 0px;
color: transparent;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
position: absolute;
}
.toggle { display: none; }
.toggle-label {
display: inline-block;
cursor: pointer;
margin-top: 10px;
margin-bottom: 10px;
border: 1px solid #fff;
font-size: 11px;
color: #999;
background-color: #8b0000;
padding: 5px;
}
.toggle-label:hover {
background-color: #400000;
}
.toggle:checked ~ .fold {
height: 80px;
visibility: visible;
color: #fff;
}
.content{
width: 100%;
min-height: 0;
position: static;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.toggle:checked ~ .content {
min-height: 80px;
}
<label for="toggle1" class="toggle-label">FOLD/UNFOLD</label>
<label for="toggle2" class="toggle-label">FOLD/UNFOLD</label>
<label for="toggle3" class="toggle-label">CLOSE</label>
<div class="content">
<aside class="folder">
<input type="checkbox" name="xinfo" class="toggle" id="toggle1"/>
<div class="fold">Element 1</div>
</aside>
<aside class="folder">
<input type="checkbox" name="xinfo" class="toggle" id="toggle2"/>
<div class="fold">Element 2</div>
</aside>
<aside class="folder">
<input type="checkbox" name="xinfo" class="toggle" id="toggle3"/>
</aside>
</div>
The best solution I found till now is to use radio. You need to use 1 extra input that has no content, so it will not show when you select it. This way the other ones will close.
<aside class="folder">
<input type="radio" name="xinfo" class="toggle" id="toggle3"/>
</aside>
JSFiddle example:
https://jsfiddle.net/zv1pd6wn/
The only problem now is that the close button will be visible till the end of the animation, I already tried to solve it, but no luck, help is appreciated.
Is this you want. kindly try below code.
<label for="toggle1" class="toggle-label">FOLD/UNFOLD</label>
<label for="toggle2" class="toggle-label">FOLD/UNFOLD</label>
<label for="toggle3" class="toggle-label">CLOSE</label>
<input type="radio" name="xinfo" class="toggle" id="toggle3"/>
<div class="content">
<aside class="folder">
<input type="radio" name="xinfo" class="toggle" id="toggle1"/>
<div class="fold">Element 1</div>
</aside>
<aside class="folder">
<input type="radio" name="xinfo" class="toggle" id="toggle2"/>
<div class="fold">Element 2</div>
</aside>
</div>
--css---
.folder {
width: 100%;
visibility: hidden;
}
.fold {
visibility: hidden;
background-color: #8b0000;
width: 60%;
height: 0px;
color: transparent;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
position: absolute;
}
.toggle { display: none; }
.toggle-label {
display: inline-block;
cursor: pointer;
margin-top: 10px;
margin-bottom: 10px;
border: 1px solid #fff;
font-size: 11px;
color: #999;
background-color: #8b0000;
padding: 5px;
}
.toggle-label:hover {
background-color: #400000;
}
.toggle:checked ~ .fold {
height: 80px;
visibility: visible;
color: #fff;
}
.content{
width: 100%;
min-height: 0;
position: static;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.toggle:checked ~ .content {
min-height: 80px;
}
#toggle3:checked + .content .fold
{
visibility: hidden;
}

HTML Form Input Background Image

I am currently working some on CSS for a site. I would like to stylize some input fields so they have a background image. I did put the background image behind the entire form, but I am having having a hard time getting each individual input field to stay lined with the background image when I resize the browser. Ideally, I would like to have each individual input field to have its own background image. Any suggestions?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style type="text/css">
* {
/*margin-left: 10px;*/
font-family: 'Verdana', sans-serif;
}
header {
/*background-color: white;*/
}
body {
background-color: #002254;
/*margin: 0;*/
}
#answers {
/*position: absolute;*/
text-align: center;
color: white;
background: #FFF url("form_ribbons.png");
background-repeat: no-repeat;
background-position: center;
/*position: relative;*/
background-color: transparent;
height: 80px;
/*margin: 0 auto;*/
}
#number {
position: absolute;
/*top: 100px;*/
/*left: 115px;*/
left: 8.5%;
}
#state {
position: absolute;
/*top: 100px;*/
/*left: 400px;*/
left: 8.5%;
display: none;
}
#abbrev {
position: absolute;
/*top: 100px;*/
/*left: 680px;*/
display: none;
}
#cap {
position: absolute;
/*top: 100px;*/
/*left: 960px;*/
display: none;
}
#submit {
display: none;
}
#red {
position: absolute;
background-image: url("blank_us_map.png");
background-size: 500px 310px;
background-repeat: no-repeat;
height: 310px;
width: 500px;
margin-top: 60px;
}
.answer {
/*padding-bottom: 23px;*/
margin-top: 20px;
/*width: 800px;*/
/* margin-right: 30px;
margin-left: 30px;*/
}
.instructions, h1 {
margin-right: 20px;
margin-left: 20px;
}
input {
background: none;
border: none;
outline: none;
text-align: center;
}
::-webkit-input-placeholder { /* Chrome */
color: white;
}
:-ms-input-placeholder { /* IE 10+ */
color: white;
}
::-moz-placeholder { /* Firefox 19+ */
color: white;
opacity: 1;
}
:-moz-placeholder { /* Firefox 4 - 18 */
color: white;
opacity: 1;
}
</style>
</head>
<body>
<header>
<h1 id="title">Learn Your States and Capitals</h1>
<p class="instructions">Choose a number first, then enter its state, abbreviation, and capital. Hit submit to start a list of answers.</p>
<p class="instructions"><strong>Checking your answers: </strong>Shake your device once to bring up a map labeled with the state names and capitals. Shake it again to bring up a map labeled with the state abbreviations. Shake it once more to go back to the map with just the numbers.</p>
<div id="guesses"><p id="guess"></p></div>
<p id="numberresult">State Number:</p>
<p id="stateresult">State:</p>
<p id="abbrevresult">State Abbreviation:</p>
<p id="capresult">State Capital:</p>
</br>
<p id="score">Score: 0</p>
<p id="answers">
<input type="text" id="number" class="answer" placeholder="Number from Map Below">
<!-- </br> -->
<input type="text" id="state" class="answer" placeholder="Number's State">
<!-- </br> -->
<input type="text" id="abbrev" class="answer" placeholder="State's Abbreviation">
<!-- </br> -->
<input type="text" id="cap" class="answer" placeholder="State's Capital">
</br>
<button id="submit">Submit</button>
</br>
</br>
</p>
For UX, I highly advised do not use background image as your background input field. I would recommend you styling like this form input.
HTML
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Name</label>
</div>
CSS
/* form starting stylings ------------------------------- */
.group {
position:relative;
margin-bottom:45px;
}
input {
font-size:18px;
padding:10px 10px 10px 5px;
display:block;
width:300px;
border:none;
border-bottom:1px solid #757575;
background:transparent;
}
input:focus { outline:none; }
/* LABEL ======================================= */
label {
color:#999;
font-size:18px;
font-weight:normal;
position:absolute;
pointer-events:none;
left:5px;
top:10px;
transition:0.2s ease all;
-moz-transition:0.2s ease all;
-webkit-transition:0.2s ease all;
}
/* active state */
input:focus ~ label, input:valid ~ label {
top:-20px;
font-size:14px;
color:#5264AE;
}
DEMO
Styling or animating your form field:
This will expand your text box if you click on the text box.
CSS:
<style>
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
</style>
HTML
<form>
<input type="text" name="search" placeholder="Search..">
</form>
Run Snippet