I'm using the custom forms of Bootstrap 4 on a website and while clicking there is a weird light-blue background behind the indicator (see BS 4 documentation or picture).
I now played around with my web console and tried different things to get rid of that background, but didn't manage.
I know that the background is on the focus of the actual input, which is set to display none... I have tried adding different styles to the label and/or the input, such as box-shadow: none; outline: none; background-color: transparent; etc. but neither of them worked.
This is why I'm searching for a solution here on StackOverflow. I hope, that someone can help.
Normal unchecked custom checkbox of BS 4
The weird light-blue background appearing from nowhere on focus
The checked custom checkbox of BS 4
Here is something :
Bootply : https://www.bootply.com/s82twl3iDl
CSS :
.custom-control-input~.custom-control-indicator{
background-color: grey !important; // select the background color
}
.custom-control-input:focus~.custom-control-indicator{
box-shadow: none !important;
}
HTML :
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Check this custom checkbox</span>
</label>
One of Bootstrap's styles is
.custom-control-input:active~.custom-control-indicator{color:#fff;background-color:#b3d7ff}
So if you don't want that, if you want it to have the same color as in the not active stage, just change it back to #ddd.
body .custom-control-input:active~.custom-control-indicator {background-color:#ddd}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Check this custom checkbox</span>
</label>
(Note: I had to add body in front of my selector to make the specificity higher, because the link to Bootstrap is included below the snippet styles.
Normally this wouldn't be necessary, since Bootstrap is normally included before your own styles.)
CSS
.custom-control-input:active~.custom-control-label::before {
background-color: #dee2e6;
}
The blue background appears on active.
On focus, a blue border appears. You can set the color to whatever you want. You can use the following code (below) to remove the blue border.
.custom-control-input:focus~.custom-control-label::before {
box-shadow: 0 0 0 1px #fff, 0 0 0 .2rem rgba(222,226,230, .5);
}
HTML
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="rememberMe"
name="rememberMe">
<label class="custom-control-label" for="rememberMe">Remember me</label>
</div>
Related
I'm an amature web developer, just getting my feet wet with my first proper html project.
I'm trying to build a webpage where you have a 'tab' selection in the top row and the currently selected tab shows a different section on the main page (hiding the other sections when not selected). I've done this using a radio input inside a label inside a table made of divs, and defined all of what I think is the correct CSS. (see below)
But the tabs do not work: depending on what I change, either every section shows up at once, or none of them do.
Here's my HTML:
<div class="sheet-table">
<div class="sheet-table-row sheet-candara">
<div class="sheet-col">
<label class="container" title="Adventure tab">
<input type="radio" name="attr_tab" class="sheet-tabs sheet-tab1" value="1">
<span class="sheet-tabs sheet-tab1 sheet-center">SECTION 1</span>
</label>
</div>
<div class="sheet-col">
<label class="container" title="Lifestyle tab">
<input type="radio" name="attr_tab" class="sheet-tabs sheet-tab2" value="2">
<span class="sheet-tabs sheet-tab2 sheet-center">SECTION 2</span>
</label>
</div>
<div class="sheet-col">
<label class="container" title="Options tab">
<input type="radio" name="attr_tab" class="sheet-tabs sheet-tab3" value="3">
<span class="sheet-tabs sheet-tab3 sheet-center">SECTION 3</span>
</label>
</div>
</div>
</div>
Then later on I have the section content (which I've commented out here):
<div class="sheet-section-tab1">
<!-- section 1 'adventure' content -->
</div>
<div class="sheet-section-tab2">
<!-- section 2 'lifestyle' content -->
</div>
<div class="sheet-section-tab3">
<!-- section 3 'options' content -->
</div>
And the CSS (a portion of which was copied and edited from W3Schools.com):
.container {
display: inline-block;
position: relative;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
.sheet-tabs {
position: inherit;
padding: 0.2em 0.9em;
z-index: 9999;
}
.container:hover input ~ .sheet-tabs {
background-color: rgba(30, 20, 20, 0.3);
border-radius: 0.5em;
content: attr(title);
}
.container input:checked ~ .sheet-tabs {
background-color: rgba(30, 20, 20, 0.7);
color: white;
border-radius: 0.5em;
}
div[class^="sheet-section"] {
display: none;
}
.sheet-section-tab1,
.sheet-section-tab2,
.sheet-section-tab3 {
display: none;
}
input.sheet-tab1:checked ~ div.sheet-section-tab1,
input.sheet-tab2:checked ~ div.sheet-section-tab2,
input.sheet-tab3:checked ~ div.sheet-section-tab3{
display: block;
}
Now, the strange thing that I discovered while trying to get this to work was that it does work when I take the inputs and spans out of their respective labels and div tables, like so:
<input type="radio" name="attr_tab" class="sheet-tabs sheet-tab1" value="1">
<span class="sheet-tabs sheet-tab1 sheet-center">SECTION 1</span>
<input type="radio" name="attr_tab" class="sheet-tabs sheet-tab2" value="2">
<span class="sheet-tabs sheet-tab2 sheet-center">SECTION 2</span>
<input type="radio" name="attr_tab" class="sheet-tabs sheet-tab3" value="3">
<span class="sheet-tabs sheet-tab3 sheet-center">SECTION 3</span>
<div class="sheet-section-tab1">
<!-- section 1 'adventure' content -->
</div>
<div class="sheet-section-tab2">
<!-- section 2 'lifestyle' content -->
</div>
<div class="sheet-section-tab3">
<!-- section 3 'options' content -->
</div>
But then I lose all the CSS styling that I worked so hard on...
Is there any way to get the functionality that I desire without compromising on the style, or am I doing something fundamentally wrong here? Or is there just a simple mistake I'm not seeing? Thanks!
(Also, I don't know if this will be relevant to any answers, but for reasons specific to my hosting platform I can't use the id attribute).
Using just HTML and CSS to create a tab system like you propose is possible, but is going to be messy and overall inefficient, and styling of the page will be difficult due to how the radio buttons will need to be aligned in order to achieve this. I highly recommend using java script to accomplish what you are doing. Here is a link to a HowTo on JavaScript tabs. However, if it is a must for this project to be accomplished through the strict use of HTML and CSS, let me know and I'll take a deeper look. From now what I can tell you is a possible way to accomplish this is to use the "+" selector. Structure the page in a way so that it alternate between radio button and the div/tab to be displayed, as so:
radio button
div
radio button
div
radio button
div
This way, the radio button is assigned to the div below it. Now you can target a checked radio button through the use of ":checked" and then using "+" which will select the closest div to the radio button. This can be accomplished in css using the following code:
.tabs {
display: none;
}
[name="radiobutton"]:checked + .tab {
display: block;
}
Cheers!
Have you tried adding in your Css overflow:Hidden;
I am trying to hide checkbox, but still allow it to check when a div / button is pressed.
My code for the custom buttons are
<div class="checkbox flex item center-text bg-theme"
style="border: 1px solid #e3e3e3;border-radius: 12px;">
<i class="twf twf-round-pushpin"></i>
<label for="nearest" class ="color-theme right-5">Nearest to me </label>
<input type="checkbox" id="nearest" class = "filtering" value="nearest" >
I've tried adding visibility:none and display:none; but this just doesn't work, when i click the buttons, nothing happens.
You might try to add opacity:0; in the css.
If you do not want the box to be directly checkable, use pointer-events:none in addition to that
Add display:inline-block on the first div so it will take only the minimum place and won't leave a big blank.
Then for the checkbox, using display:none works fine, I've added an onclick callback to log the state of the checkbox on each click on the label.
Try this sample:
<div class="checkbox flex item center-text bg-theme" style="border: 1px solid #e3e3e3;border-radius: 12px; display:inline-block;">
<i class="twf twf-round-pushpin"></i>
<label for="nearest" class ="color-theme right-5">Nearest to me </label>
<input type="checkbox" id="nearest" class = "filtering" value="nearest" style="display: none;" onclick="console.log(this.checked)">
</div>
I want to exclude materialize css for some items in my view. Eg: i dont want to display materialize styles to check box under table. It causes problems with my internal jquery library. Please check attached image. I gave below html content in my table > td. I want to display this as browser default checkbox.
In my application i am using http://materializecss.com
<div class="checkbox">
<input type="checkbox" class="filled-in dt-checkboxes">
<label></label>
</div>
To remove the Materialize styles from the checkboxes, you first need to understand how the Materialize checkboxes are created:
The "real" checkbox is removed with opacity: 0; and some positioning
A "fake" checkbox is created with the help of the pseudo elements ::before and ::after on the <span> element
So all you need to do is hide the pseudo elements and make the real checkbox visible again. I created a class .reset-checkbox to demonstrate the effect:
[type="checkbox"].reset-checkbox,
[type="checkbox"].reset-checkbox:checked,
[type="checkbox"].reset-checkbox:not(checked) {
opacity: 1;
position: relative;
}
[type="checkbox"].reset-checkbox+span::before,
[type="checkbox"].reset-checkbox+span::after,
[type="checkbox"].reset-checkbox:checked+span::before,
[type="checkbox"].reset-checkbox:checked+span::after {
display: none;
}
[type="checkbox"].reset-checkbox+span:not(.lever) {
padding-left: 10px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css" rel="stylesheet" />
<form action="#">
<div>
<label>
<input type="checkbox" class="filled-in" />
<span>Test with Materialize</span>
</label>
</div>
<div>
<label>
<input type="checkbox" class="filled-in reset-checkbox" />
<span>Test with removed styles</span>
</label>
</div>
</form>
Pay attention to a higher specificity of the selectors here, to make sure that the Materialize styles are overwritten.
I have five thumbnail images in a row, below each image is a title and below the whole row is about 100 words of description text. What I intend to do is setup thumbnails to act as radio buttons to change the block of description text below the row to something relevant to that image.
So far I have setup the thumbnails with:
<div id="thumbcontainer" style="left: 60px;">
<img class="thumb"src="image1.jpg" >Title1
</div>
<div id="thumbcontainer" style="left: 160px;">
<img class="thumb"src="image2.jpg" >Title2
</div>
etc.
<p class=”descrcontainer”>Description text of 100 words</p>
I am working through information in previous questions about how to use images as radio buttons but I cannot find any information about how to change the a block of text when a radio button is clicked. Can someone help me?
Errors
#ids must be unique, there's 2 id="thumbcontainer"
Each class=”descrcontainer”is a syntax error. A smart quote ” does not work in code, use double straight quote "
Solution
Add <input id='rad*' class='rad' name='rad' type='radio' style='display:none'> in front of each <p>
Add display:none to each <p>
Make the <div class="thumbcontainer"> into <label for='chx*'>
Add The CSS etc.
Use label:focus in CSS and add tabindex='1' to each <label> to highlight buttons.
Explaination
A <label> with for attribute with a value of an #id of a form control (e.g. <input type='radio'>) are linked. If you click a <label for='rad0'>, <input id='rad0' type='radio'> is clicked as well--like a remote button.
All <input type='radio'> that share the same name attribute will toggle in sync with each other. The behavior is basically only one radio can be checked.
A radio in the checked state can influence the styles of sibling elements that are after it and elements that are its descendants. In this demo:
.rad:checked + .descrcontainer {display:block;}
Any element with the class of .rad that is checked will make the next element with the class of .descrcontainer appear.
Demo
.descrcontainer {
display: none
}
.rad:checked+.descrcontainer {
display: block;
}
label:focus {
outline: 5px ridge cyan;
box-shadow: 2px 4px 6px 8px rgba(0, 128, 200, 0.4);
}
<label for='rad0' class="thumbcontainer" style="display:inline-block;" tabindex='1'>
<img class="thumb"src="https://static-s.aa-cdn.net/img/ios/1112633650/92503d478bfa0e96f28a3fefe2edf5f1?v=1" width='128'><div style='text-align:center'>Dinosaurs</div>
</label>
<label for='rad1' class="thumbcontainer" style="display:inline-block;" tabindex='1'>
<img class="thumb"src="https://cdn-img.fimfiction.net/user/pcrx-1431833332-196431-256" width='128'><div style='text-align:center'>Demons</div>
</label>
<input id='rad0' type='radio' class='rad' name='rad' style='display:none'>
<p class="descrcontainer">Angulomastacator blikanasaurus colepiocephale didanodon leshansaurus niobrarasaurus nuoersaurus ovoraptor owenodon parksosaurus plateosauravus silvisaurus titanosaurus xenotarsosaurus yaleosaurus yamaceratops yunxiansaurus. Campylodon clepsysaurus elrhazosaurus
giraffatitan heterosaurus iguanodon magnirostris piatnitzkysaurus shanag shidaisaurus tochisaurus veterupristisaurus yimenosaurus. Airakoraptor astrodon balochisaurus brontosaurus ceratonykus elaphrosaurus fabrosaurus hadrosauravus hallopus indosuchus
khateranisaurus moshisaurus nanotyrannosaurus neovenator peltosaurus puertasaurus rebbachisaurus suchosaurus tianyuraptor umarsaurus unquillosaurus wannanosaurus xixiposaurus.</p>
<input id='rad1' type='radio' class='rad' name='rad' style='display:none'>
<p class="descrcontainer">Adramelech andromalius azazel bali raj behemoth bhuta corson dagon eurynomos foras forneus gaki malthus mastema mephistopheles moloch ninurta onoskelis oray ose samael surgat tannin ziminiar. Agares aka manah azazel barbas davy jones drekavac eligos malthus
incubus kokb'ael labal mammon marchosias naberius paimon surgat vapula. Ahriman alal azaz'el baal bael boruta cimeies crocell eblis familiars forcas jikininki labasu morax ad-dajjal medusa naberus serguthy shax shedim. Haborym alastor allocer allu ammut
andhaka asag asb'el azaz'el azi dahaka bael balam davy jones gamigin imp ipos ipes jikininki kabhanda medusa naphula orcus paimonia serguthy vephar vine.</p>
I just getting started this google material design lite. And i found this textfield floating when you r focusing in this label. the color is blue or navy or idk.
the problem is, I changed the link color into this color indigo-pink
<link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.indigo-pink.min.css">
but there is no change for my textfield into an indigo color or a pink color when I focused on it.
question is simple, how to change it?
I did something with this, but still have no luck in it.
the HTML:
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample4">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="sample4">
<label class="mdl-textfield__label mdl-color-modifier" for="sample4">Number...</label>
<span class="mdl-textfield__error">Input is not a number!</span>
</div>
</form>
the css:
div .mdl-textfield__label:after {
background: pink;
}
.mdl-textfield--floating-label .is-focused .mdl-textfield__label, .mdl-textfield--floating-label.is-dirty .mdl-textfield__label, .mdl-textfield--floating-label.has-placeholder .mdl-textfield__label{
color:pink;
}
.mdl-color-modifier:focus{
color:pink;
}
I tried to apply a new class in it with pseudo :focus, but it still have no luck too.
I have it all. The keys are the :after modifier and the is-focused class. Just replace #FAFAFA with your indigo-pink and it should work for ya. This is just proof of concept. Check the fiddle. it has the text label colored too.
.mdl-textfield.is-focused .mdl-textfield__label {
color: #FAFAFA;
}
.mdl-textfield__label:after{
background-color: #FAFAFA;
}
https://jsfiddle.net/90u6Lxc4/30/
I believe an alternate solution would be like this, it worked for me:
.mdl-textfield__input:focus {
border-bottom-color: red;
box-shadow: 0 1px 0 0 red;
}
I deducted the answer from here.