Bootstrap input border flashing when clicking away from altered input:focus - html

I have a simple form with an input field where I created my own floating placeholder/label. I then wanted to change how the focus behave, removing shadow and alter the borders. Here is the code I have right now which is almost working:
.paddings{
padding: 5rem;
}
input.my-input:focus{
box-shadow: none;
border: thin solid rgba(0, 100, 173, 0.5);
border-top: none;
}
.floating-label{
color: rgb(80 80 80);
pointer-events: none;
position: absolute;
left: 2.5rem;
top: 0.5rem;
transition: 0.2s ease all;
}
input:focus ~ .floating-label{
color: rgb(40 40 40);
font-size: 0.85rem;
top: -0.65rem;
left: 2rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#3.3.7/dist/css/bootstrap.min.css">
<div class="row paddings">
<div class="col-md-12">
<div>
<input class="form-control my-input" type="text">
<span class="floating-label">Search</span>
</div>
</div>
</div>
All looks good when focusing on the element. However, when I unfocus there is a flash of black top border for some reason. Why is this happeneing?
I tried to remove the transition but it is still there. How can I make it transition back to the light grey color it was without the top border flashing black in between?

This is due to the border-top property on input.my-input:focus being set to none. Removing that and adjusting the negative margin on input:focus ~ .floating-label should fix it:
Edit: In response to OP's comment - changing the color of the border-top property will resolve the issue:
.paddings{
padding: 5rem;
}
input.my-input:focus {
box-shadow: none;
border: thin solid rgba(0, 100, 173, 0.5);
border-top: whitesmoke;
}
.floating-label{
color: rgb(80 80 80);
pointer-events: none;
position: absolute;
left: 2.5rem;
top: 0.5rem;
transition: 0.2s ease all;
}
input:focus ~ .floating-label {
color: rgb(40 40 40);
font-size: 0.85rem;
top: -0.65rem;
left: 2rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#3.3.7/dist/css/bootstrap.min.css">
<div class="row paddings">
<div class="col-md-12">
<div>
<input class="form-control my-input" type="text">
<span class="floating-label">Search</span>
</div>
</div>
</div>

Related

how to adjust size of 'tick' inside checkbox?

I have given an input element type checkbox, its fine but when its checked tick seems very big.
I need to make smaller that tick symbol
here is html content from browser:
<div class="defaultRoot">
<div class="defaultBody ">
<div class="checkboxWrapper">
<input id="kis-9l7v7o3vr" type="checkbox" class="kischeckbox" style="width: 24px; height: 24px; accent-color: rgb(47, 55, 93); border: 4px solid gray; border-radius: 0px; display: block; transition: border-color 0ms ease 0s, background-color 0ms ease 0s; cursor: default;">
</div>
<div class="labelWrapper">
<label class="label" data-disabled="false" for="kis-9l7v7o3vr">I agree to sell my privacy</label>
</div>
</div>
</div>
How can I make that tick smaller and thinner
Currently the browser does not (and will not) support virtual elements to the tick of the checkbox you have to customize them yourself. refer here: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_custom_checkbox
using CSS you can adjust the size of the tick inside the checkbox as follow
<!DOCTYPE html>
<html>
<head>
<title>Adjust Checkbox Tick Size</title>
<style>
.checkboxWrapper, .labelWrapper {
display: inline-block;
vertical-align: middle;
}
input[type=checkbox].kischeckbox {
display: inline-block;
width: 14px;
height: 14px;
accent-color: rgb(47, 55, 93);
border: 4px solid gray;
border-radius: 0px;
display: block;
transition: border-color 0ms ease 0s;
cursor: default;
vertical-align: middle;
}
input[type=checkbox].kischeckbox:checked + label::before {
content: "\2714"; /* tick symbol */
font-size: 16px; /* adjust the size of the tick here */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="defaultRoot">
<div class="defaultBody ">
<div class="checkboxWrapper">
<input id="kis-9l7v7o3vr" type="checkbox" class="kischeckbox">
</div>
<div class="labelWrapper">
<label class="label" data-disabled="false" for="kis-9l7v7o3vr">I agree to sell my privacy</label>
</div>
</div>
</div>
</body>
</html>

making bootstrap 4 input like material search field, transition animation issue

i was trying to make bootstrap form input like material design search field. i have managed to make it but i guess there is a small issue with focus state and that is when i click the field, the underline animation runs smooth but, when i click outside of it the animation takes two steps to play. here is the code sample to understand better (i have downloaded bootstrap locally using npm)
in html =>
<div class="container">
<div class="d-flex mt-5">
<i type="submit" class="fa fa-search"></i>
<input type="email" class="form-control" placeholder="Search" />
</div>
</div>
in scss =>
.d-flex {
align-items: center;
}
.form-control {
border-top: 0;
border-left: 0;
border-right: 0;
border-bottom: 1px solid #eee;
border-radius: 0;
padding: 0;
}
.form-control:focus {
box-shadow: none;
border-bottom: 2px solid #4dd1e1;
transition: border-color 0.2s linear;
backface-visibility: hidden;
}
i.fa-search {
margin-top: 0.3rem;
margin-right: 1rem;
}
so, how can i fix this ?
Replace transition: border-color 0.2s linear; into .form-control
.form-control {
border-top: 0;
border-left: 0;
border-right: 0;
border-bottom: 1px solid #eee;
border-radius: 0;
padding: 0;
transition: border-color 0.2s linear; /* moved form :focus */
}
Because your animation activates only on :focus, but whithout :focus the .form-control doesn't now about animation and do the transformation harshly.

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>

How to make a pure CSS bootstrap onclick and hover dropdown menu?

There is a pure CSS (no JavaScript) dropdown menu activated on hover, and the menu stays open if you click it.
It's here: Making Animated Dropdown Menu by Using Pure CSS Like Bootstrap does
Here's the code:
html, body {
margin:0;
}
.acn-menu {
text-align: center;
background-color: rgba(0, 0, 0, 0.9);
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
min-height: 74px;
width: 100%;
}
.label_openclose {
display: none;
}
.menu-tabs {
height: 100%;
}
.menu-tabs .elem {
box-sizing: border-box;
padding: 0 20px;
float: left;
height: 100%;
line-height: 70px;
background-color: rgb(30, 30, 30);
color: white;
}
#-webkit-keyframes spin {
0% {
transform: rotate(-180deg);
}
50% {
transform: rotate(180deg);
}
100% {
transform: rotate(-180deg);
}
}
#keyframes spin {
0% {
transform: rotate(-180deg);
}
50% {
transform: rotate(180deg);
}
100% {
transform: rotate(-180deg);
}
}
.menu-check:checked ~ .label_openclose {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
.menu-check {
display: none;
}
.menu-tabs .elem:hover {
background-color: rgba(255, 255, 255, 0.2);
}
/*#media screen and (max-width:55%)*/
#media screen and (max-width:768px) {
.label_openclose {
-webkit-animation: spin 2s;
animation: spin 2s;
display: inline-block;
transform: rotate(-180deg);
transition-duration: 1s;
margin: 10px;
width: 30px;
height: 30px;
border-radius: 50%;
border-top: 10px solid rgb(50, 50, 50);
border-right: 10px solid rgb(100, 100, 100);
border-bottom: 10px solid rgb(150, 150, 150);
border-left: 10px solid rgb(200, 200, 200);
background-color: transparent;
cursor: pointer;
}
.label_openclose:hover {
transform: rotate(180deg);
}
.menu-tabs .elem {
transition: border 1s linear, height 1s;
line-height: initial;
float: initial;
height: 0px;
cursor: pointer;
border-top: 0px solid #000;
overflow: hidden;
}
.menu-tabs:hover .elem {
height: 25px;
}
.menu-check:checked ~ .menu-tabs .elem {
height: 25px;
color: white;
border-top: 2px solid rgba(255, 255, 255, 0.2);
}
.label_openclose:hover ~ .menu-tabs .elem {
border-top: 2px solid rgba(255, 255, 255, 0.2);
height: 25px;
}
}
<div class="acn-menu">
<input type="checkbox" id="openclose" class="menu-check" />
<label class="label_openclose" for="openclose"></label>
<div class="menu-tabs">
<div class="elem">test</div>
<div class="elem">nav</div>
<div class="elem">bar</div>
<div class="elem">with</div>
<div class="elem">transitions</div>
</div>
</div>
<main>
test content of main page</br>The navbar menu stays open when you click on the circle</br>and it even opens on hover, not just on click.
</main>
I would put the drop down where it says "Solutions" in the navbar:
How could I make this work with the default bootstrap 3 navbar menu?
The trick is in the :checked and :hover CSS psuedo-class selectors on a checkbox in combination with ~ (the general sibling combinator). The combinator (~) sounds complicated, but it basically just means select any sibling after the ~ if it is present in html after the selector before the ~. For example:
.before ~ .after {
background-color: orange;
}
...
<div>
<p class = "before">Before</p>
<p class = "after">After</p> <!-- I'll be orange -->
<p class = "after">After</p> <!-- Me too! -->
<p class = "after">After</p> <!-- You get the point -->
</div>
So basically all you need is (1) a checkbox element (2) a label for said checkbox, and (3) a menu (with as many children as you want). And all three have to be siblings so that checking / unchecking the checkbox can toggle the classes of the other two elements via the psuedo-class selectors and the ~ combinator.
In the example you showed, the checkbox display is set to none, but that's just because its ugly. It could easily still be there and the menu toggle would function the same. You can toggle the check with the label alone, so it's doesn't really matter. But the invisible checkbox is what makes everything happen. You could style it directly and forget the label if you wanted to.
So all you need to do is set the menu to hidden, and the menu after the ~ combinator to show if the checkbox is either checked or hovered over:
.menu {
display: none;
}
.check-toggle:checked ~ .menu, .check-toggle:hover ~ .menu {
display: block;
}
...
<input id="checkBox" class="check-toggle" type="checkbox"/>
<label for="checkBox">MENU</label>
<div class="menu">
<div>Menu Items</div>
<div>Menu Items</div>
<div>Menu Items</div>
<div>Menu Items</div>
</div>
It might be an absolute pain to find a perfect replica of this in bootstrap, or it might be easy, I'm not sure. But you don't really need it. You can just add the invisible checkbox, the label, and the menu with the toggling selectors, and then style everything else with bootstrap.You might need to over-power the cascade, but worst comes to worst you can make special toggling selectors with an id instead of a class.
Here is a minimalist working example:
<style>
.check-toggle {
/*display: none;*/
}
.menu {
display: none;
position: absolute;
background-color: white;
border: 2px solid black;
margin-top: -2px;
}
.menu:hover {
display: block;
}
.check-toggle:checked ~ label, .check-toggle:hover ~ label {
color: orange;
}
.check-toggle:checked ~ .menu, .check-toggle:hover ~ .menu {
display: block;
}
</style>
<div>
<input id="checkBox" class="check-toggle" type="checkbox"/>
<label for="checkBox">MENU</label>
<div class="menu">
<div>Menu Items</div>
<div>Menu Items</div>
<div>Menu Items</div>
<div>Menu Items</div>
</div>
</div>
You can use :focus for this. Check out the example code.
Drawback: You cannot toggle the dropdown (You can open it but cannot close it).

Does :focus work with specificity as :hover does?

Here is my problem. I want the input-group-addon that holds an icon (search icon, calendar icon, etc) to inherit the hover, focus, and active states of its input field by specificity. I have it working for hover but for some reason specificity is ignoring the focus state. I thought it was a conflicting css directive in my code but I isolated the problem in CODEPEN and it does it there as well.
In summary, I want the input group addon border to change to yellow seamlessly with its input field when I focus on it (tab or click), as it does when I hover on it.
My HTML:
<div class="input-group controls">
<input type="text" class="form-control" placeholder="Search by Name" />
<span class="input-group-addon right search"></span>
</div>
My CSS (Use Chrome if possible. I didn't include here the corssbrowser stuff to make it simpler to read) Also, this is originally built on SCSS:
.mar40 {
margin: 40px auto;
}
.form-control {
border-width: 2px;
border-color: #8f8f8f;
-webkit-box-shadow: none;
box-shadow: none;
color: #bbbbbb;
-webkit-border-radius: 34px;
-moz-border-radius: 34px;
-ms-border-radius: 34px;
border-radius: 34px;
background: #211E1E;
}
.form-control:focus,
.form-control:hover {
border-color: rgba(248, 151, 29, 0.77);
-webkit-box-shadow: none;
box-shadow: none;
outline: none;
transition: all 1s ease;
}
.form-control .input-group-addon {
background: #8f8f8f;
border-color: #555555;
border-width: 2px;
}
.controls .input-group-addon.right.search {
background: #30373e;
border: 2px solid #8f8f8f;
color: #bbbbbb;
border-left: none;
border-radius: 0px 20px 20px 0;
padding: 4px 10px;
min-width: 0;
}
.controls .input-group-addon.right.search:before {
content: "\f4a4";
font-family: 'Ionicons';
font-size: 16px;
}
.controls:focus .input-group-addon.right,
.controls:hover .input-group-addon.right,
.controls:active .input-group-addon.right {
border: 2px solid rgba(248, 151, 29, 0.77) !important;
border-left: none !important;
transition: all 1s ease;
}
.controls:focus .input-group-addon.right:before,
.controls:hover .input-group-addon.right:before,
.controls:active .input-group-addon.right:before {
color: rgba(248, 151, 29, 0.77);
transition: all 1s ease;
}
Desired effect illustration on hover/focus/active
This is what I am getting on focus
And the handy dandy CODEPEN
Thanks!
:focus applies for the input and not the parent container and so your selector group should be as follows. (Note the changed selector in the first line)
.form-control:focus + .input-group-addon.right,
.controls:hover .input-group-addon.right,
.controls:active .input-group-addon.right {
border: 2px solid rgba(248, 151, 29, 0.77) !important;
border-left: none !important;
transition: all 1s ease;
}
As far as I know, when you :hover the child you are also indirectly hovering on the parent and so the .controls:hover .input-group-addon.right also works when .form-control:hover is applicable. Thus both the .form-control and .input-group-addon.right get the border.
But when you focus on the .form-control, the focus selector applies only to the input and doesn't get applied to its container. Thus only the .form-control gets the border and not the .input-group-addon. So, the selector must be changed to style the .input-group-addon based on the input and not the container's focus.
CodePen Demo