Flex items don't show in line in Webkit browsers [duplicate] - html

This question already has answers here:
Flex / Grid layouts not working on button or fieldset elements
(3 answers)
Closed 5 years ago.
I've created a text field with a little cogwheel, that offers options in a popup menu about how to treat the search string. For some parts, it uses a flexible box layout.
In Firefox, I get the expected result:
.
In Webkit browsers (Safari and Vivaldi), I get this result:
As you can see, the cogwheel doesn't stay in line. This is my main concern. I'm not too worried about the menu text not stretching as that can easily be solved with giving any of its containers a width.
I currently don't have Chrome, but I suspect it might render it in a similar fashion as the other Webkit browsers.
Here is the css that I think is relevant to my problem.
.flex-search {
position: relative;
display: -webkit-flex; // <--
display: flex; // <--
-webkit-align-items: stretch; // <--
align-items: stretch; // <--
width: 100%;
border: 1px solid #222;
border-radius: .4em;
background-color: #fff;
}
.flex-search > :first-child {
-webkit-flex: 1; // <--
flex: 1; // <--
}
.flex-search > :last-child {
width: 2em; // <--
border-left: 1px solid #ccc;
cursor: pointer;
}
And here's a full code snippet of the search field:
$( '.flex-search input[type="radio"]' ).click( function() {
$( this ).closest( 'span' )
.css( 'display', 'none' )
.delay( 500 )
.queue( function ( next ) {
$( this ).removeAttr( 'style' );
next();
} );
$( this ).closest( 'fieldset' )
.find( 'input[type="text"]' )
.attr( 'placeholder', $( this ).closest( 'label' ).text() )
.focus();
} );
* {
margin: 0;
padding: 0;
border: medium none;
border-spacing: 0;
outline: none;
outline: 0;
color: inherit;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
text-align: inherit;
text-decoration: none;
text-indent: 0;
list-style: none outside none;
background: none repeat scroll 0 0 transparent;
}
*::-moz-focus-inner {
border: 0;
padding: 0;
}
html {
color: #222;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
text-align: left;
height: 100%;
}
body {
font-size: 1.4rem;
line-height: 1.5em;
min-height: 100%;
background-color: #fff;
}
div {
margin: 150px auto 0;
width: 300px;
}
::-webkit-input-placeholder {
color: #666;
font-size: 85%;
}
:-moz-placeholder {
color: #666;
font-size: 85%;
}
::-moz-placeholder {
color: #666;
font-size: 85%;
}
:-ms-input-placeholder {
color: #666;
font-size: 85%;
}
:focus::-webkit-input-placeholder {
color: #ccc;
}
:focus:-moz-placeholder {
color: #ccc;
}
:focus::-moz-placeholder {
color: #ccc;
}
:focus:-ms-input-placeholder {
color: #ccc;
}
.flex-search {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 100%;
border: 1px solid #222;
border-radius: .4em;
background-color: #fff;
}
.flex-search > :first-child {
-webkit-flex: 1;
flex: 1;
}
.flex-search > :last-child {
width: 2em;
border-left: 1px solid #ccc;
cursor: pointer;
}
.flex-search > :last-child:after {
content: '\00a0';
display: block;
width: 100%;
height: 100%;
background: url( 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAEG0lEQVQ4EQEQBO/7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhwAAAOwAAAASAAAAEgAAAOwAAACIAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAADAAAAG8AAAAAAAAADAAAAM8AAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAACIAAAAEwAAAAYAAAAHAAAALwAAACQAAADRAAAA2QAAACkAAABdAAAAvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOwAAAD4AAAAsAAAAG4AAAAAAAAAAAAAAG4AAACwAAAA+AAAAOwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAIEAAADHAAAAAAAAAAAAAAAAAAAAAAAAAMcAAACBAAAAFAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOwAAAD4AAAAsAAAAG4AAAAAAAAAAAAAAG4AAACwAAAA+AAAAOwAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAiAAAAM8AAAAGAAAAVAAAABcAAAAAAAAA6QAAAKwAAAD6AAAAMQAAAHgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFcAAAD4AAAAgQAAAIEAAAD4AAAAVwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhwAAAOwAAAASAAAAEgAAAOwAAACIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6eSOOoDWnnAAAAABJRU5ErkJggg==' ) no-repeat center center;
opacity: 0.5;
}
.flex-search > :last-child:hover:after {
opacity: 1;
}
.flex-search > :last-child > :first-child {
position: absolute;
right: -1px;
bottom: 0;
display: none;
padding: 0 .25em 2.1em 0;
color: #fff;
}
.flex-search > :last-child:hover > :first-child {
display: block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.flex-search label {
display: block;
cursor: pointer;
background-color: #ccc;
}
.flex-search label > span {
position: relative;
display: block;
font-size: 85%;
text-align: right;
padding: .2em .8em .2em 30%;
}
.flex-search label:hover > span,
.flex-search input[type="radio"]:checked ~ span {
color: #999;
background-color: #eee;
}
.flex-search input[type="radio"]:checked ~ span:before {
position: absolute;
left: .7em;
content: '✔';
}
.flex-search input[type="radio"] {
display: none;
}
.flex-search input[type="text"] {
width: 100%;
box-sizing: border-box;
padding: .2em .8em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<fieldset class="flex-search">
<span>
<input type="text" name="id" placeholder="contains">
</span>
<span>
<span>
<label><input type="radio" name="t-id" value="c" checked="checked"><span>contains</span></label>
<label><input type="radio" name="t-id" value="s"><span>starts with</span></label>
<label><input type="radio" name="t-id" value="e"><span>ends with</span></label>
<label><input type="radio" name="t-id" value="i"><span>equals</span></label>
</span>
</span>
</fieldset>
</div>
Do you have any idea why I am not getting the expected result in Webkit browsers and how I can get it to work in them?
I suspect my code might actually be more complex than it needs to be. If you have suggestions on how to simplify, that is greatly appreciated as well of course, but I'm mainly focused on how to make the current code work in Webkit browsers.

Why the cogwheel ends up on the second line is because of a webkit bug that does not render fieldset elements as a flexbox container
Here is a list of flexbugs mentioning the same bug: Some html elements cant be flex containers
If you add a div as an inner wrapper it will work.
<fieldset>
<div class="flex-search">
....
</div>
</fieldset>
Stack snippet
$('.flex-search input[type="radio"]').click(function() {
$(this).closest('span')
.css('display', 'none')
.delay(500)
.queue(function(next) {
$(this).removeAttr('style');
next();
});
$(this).closest('fieldset')
.find('input[type="text"]')
.attr('placeholder', $(this).closest('label').text())
.focus();
});
* {
margin: 0;
padding: 0;
border: medium none;
border-spacing: 0;
outline: none;
outline: 0;
color: inherit;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
text-align: inherit;
text-decoration: none;
text-indent: 0;
list-style: none outside none;
background: none repeat scroll 0 0 transparent;
}
*::-moz-focus-inner {
border: 0;
padding: 0;
}
html {
color: #222;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
text-align: left;
height: 100%;
}
body {
font-size: 1.4rem;
line-height: 1.5em;
min-height: 100%;
background-color: #fff;
}
div {
margin: 150px auto 0;
width: 300px;
}
::-webkit-input-placeholder {
color: #666;
font-size: 85%;
}
:-moz-placeholder {
color: #666;
font-size: 85%;
}
::-moz-placeholder {
color: #666;
font-size: 85%;
}
:-ms-input-placeholder {
color: #666;
font-size: 85%;
}
:focus::-webkit-input-placeholder {
color: #ccc;
}
:focus:-moz-placeholder {
color: #ccc;
}
:focus::-moz-placeholder {
color: #ccc;
}
:focus:-ms-input-placeholder {
color: #ccc;
}
.flex-search {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 100%;
border: 1px solid #222;
border-radius: .4em;
background-color: #fff;
}
.flex-search> :first-child {
-webkit-flex: 1;
flex: 1;
}
.flex-search> :last-child {
width: 2em;
border-left: 1px solid #ccc;
cursor: pointer;
}
.flex-search> :last-child:after {
content: '\00a0';
display: block;
width: 100%;
height: 100%;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAEG0lEQVQ4EQEQBO/7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhwAAAOwAAAASAAAAEgAAAOwAAACIAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAA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') no-repeat center center;
opacity: 0.5;
}
.flex-search> :last-child:hover:after {
opacity: 1;
}
.flex-search> :last-child> :first-child {
position: absolute;
right: -1px;
bottom: 0;
display: none;
padding: 0 .25em 2.1em 0;
color: #fff;
}
.flex-search> :last-child:hover> :first-child {
display: block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.flex-search label {
display: block;
cursor: pointer;
background-color: #ccc;
}
.flex-search label>span {
position: relative;
display: block;
font-size: 85%;
text-align: right;
padding: .2em .8em .2em 30%;
}
.flex-search label:hover>span,
.flex-search input[type="radio"]:checked~span {
color: #999;
background-color: #eee;
}
.flex-search input[type="radio"]:checked~span:before {
position: absolute;
left: .7em;
content: '✔';
}
.flex-search input[type="radio"] {
display: none;
}
.flex-search input[type="text"] {
width: 100%;
box-sizing: border-box;
padding: .2em .8em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<fieldset>
<div class="flex-search">
<span>
<input type="text" name="id" placeholder="contains">
</span>
<span>
<span>
<label><input type="radio" name="t-id" value="c" checked="checked"><span>contains</span></label>
<label><input type="radio" name="t-id" value="s"><span>starts with</span></label>
<label><input type="radio" name="t-id" value="e"><span>ends with</span></label>
<label><input type="radio" name="t-id" value="i"><span>equals</span></label>
</span>
</span>
</div>
</fieldset>
</div>

In the following, you say that the span should be padding-left: 30%. As a result the space for the text is too small. Just remove the 30% and it will work fine. You can also add .8em as a fourth parameter but the browser will do it automatically for you.
.flex-search label>span {
position: relative;
display: block;
font-size: 85%;
text-align: right;
padding: .2em .8em .2em; <-- 30% removed
}
$('.flex-search input[type="radio"]').click(function() {
$(this).closest('span')
.css('display', 'none')
.delay(500)
.queue(function(next) {
$(this).removeAttr('style');
next();
});
$(this).closest('fieldset')
.find('input[type="text"]')
.attr('placeholder', $(this).closest('label').text())
.focus();
});
* {
margin: 0;
padding: 0;
border: medium none;
border-spacing: 0;
outline: none;
outline: 0;
color: inherit;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
text-align: inherit;
text-decoration: none;
text-indent: 0;
list-style: none outside none;
background: none repeat scroll 0 0 transparent;
}
*::-moz-focus-inner {
border: 0;
padding: 0;
}
html {
color: #222;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
text-align: left;
height: 100%;
}
body {
font-size: 1.4rem;
line-height: 1.5em;
min-height: 100%;
background-color: #fff;
}
div {
margin: 150px auto 0;
width: 300px;
}
::-webkit-input-placeholder {
color: #666;
font-size: 85%;
}
:-moz-placeholder {
color: #666;
font-size: 85%;
}
::-moz-placeholder {
color: #666;
font-size: 85%;
}
:-ms-input-placeholder {
color: #666;
font-size: 85%;
}
:focus::-webkit-input-placeholder {
color: #ccc;
}
:focus:-moz-placeholder {
color: #ccc;
}
:focus::-moz-placeholder {
color: #ccc;
}
:focus:-ms-input-placeholder {
color: #ccc;
}
.flex-search {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 100%;
border: 1px solid #222;
border-radius: .4em;
background-color: #fff;
}
.flex-search> :first-child {
-webkit-flex: 1;
flex: 1;
}
.flex-search> :last-child {
width: 2em;
border-left: 1px solid #ccc;
cursor: pointer;
}
.flex-search> :last-child:after {
content: '\00a0';
display: block;
width: 100%;
height: 100%;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAEG0lEQVQ4EQEQBO/7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6eSOOoDWnnAAAAABJRU5ErkJggg==') no-repeat center center;
opacity: 0.5;
}
.flex-search> :last-child:hover:after {
opacity: 1;
}
.flex-search> :last-child> :first-child {
position: absolute;
right: -1px;
bottom: 0;
display: none;
padding: 0 .25em 2.1em 0;
color: #fff;
}
.flex-search> :last-child:hover> :first-child {
display: block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.flex-search label {
display: block;
cursor: pointer;
background-color: #ccc;
}
.flex-search label>span {
position: relative;
display: block;
font-size: 85%;
text-align: right;
padding: .2em .8em .2em;
}
.flex-search label:hover>span,
.flex-search input[type="radio"]:checked~span {
color: #999;
background-color: #eee;
}
.flex-search input[type="radio"]:checked~span:before {
position: absolute;
left: .7em;
content: '✔';
}
.flex-search input[type="radio"] {
display: none;
}
.flex-search input[type="text"] {
width: 100%;
box-sizing: border-box;
padding: .2em .8em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<fieldset class="flex-search">
<span>
<input type="text" name="id" placeholder="contains">
</span>
<span>
<span>
<label><input type="radio" name="t-id" value="c" checked="checked"><span>contains</span></label>
<label><input type="radio" name="t-id" value="s"><span>starts with</span></label>
<label><input type="radio" name="t-id" value="e"><span>ends with</span></label>
<label><input type="radio" name="t-id" value="i"><span>equals</span></label>
</span>
</span>
</fieldset>
</div>
Update:
In the event that the 30% should give the check mark enough space, you can also replace it with 2em:
.flex-search label>span {
position: relative;
display: block;
font-size: 85%;
text-align: right;
padding: .2em .8em .2em 2em;
}
$('.flex-search input[type="radio"]').click(function() {
$(this).closest('span')
.css('display', 'none')
.delay(500)
.queue(function(next) {
$(this).removeAttr('style');
next();
});
$(this).closest('fieldset')
.find('input[type="text"]')
.attr('placeholder', $(this).closest('label').text())
.focus();
});
* {
margin: 0;
padding: 0;
border: medium none;
border-spacing: 0;
outline: none;
outline: 0;
color: inherit;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
text-align: inherit;
text-decoration: none;
text-indent: 0;
list-style: none outside none;
background: none repeat scroll 0 0 transparent;
}
*::-moz-focus-inner {
border: 0;
padding: 0;
}
html {
color: #222;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
text-align: left;
height: 100%;
}
body {
font-size: 1.4rem;
line-height: 1.5em;
min-height: 100%;
background-color: #fff;
}
div {
margin: 150px auto 0;
width: 300px;
}
::-webkit-input-placeholder {
color: #666;
font-size: 85%;
}
:-moz-placeholder {
color: #666;
font-size: 85%;
}
::-moz-placeholder {
color: #666;
font-size: 85%;
}
:-ms-input-placeholder {
color: #666;
font-size: 85%;
}
:focus::-webkit-input-placeholder {
color: #ccc;
}
:focus:-moz-placeholder {
color: #ccc;
}
:focus::-moz-placeholder {
color: #ccc;
}
:focus:-ms-input-placeholder {
color: #ccc;
}
.flex-search {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 100%;
border: 1px solid #222;
border-radius: .4em;
background-color: #fff;
}
.flex-search> :first-child {
-webkit-flex: 1;
flex: 1;
}
.flex-search> :last-child {
width: 2em;
border-left: 1px solid #ccc;
cursor: pointer;
}
.flex-search> :last-child:after {
content: '\00a0';
display: block;
width: 100%;
height: 100%;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAEG0lEQVQ4EQEQBO/7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6eSOOoDWnnAAAAABJRU5ErkJggg==') no-repeat center center;
opacity: 0.5;
}
.flex-search> :last-child:hover:after {
opacity: 1;
}
.flex-search> :last-child> :first-child {
position: absolute;
right: -1px;
bottom: 0;
display: none;
padding: 0 .25em 2.1em 0;
color: #fff;
}
.flex-search> :last-child:hover> :first-child {
display: block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.flex-search label {
display: block;
cursor: pointer;
background-color: #ccc;
}
.flex-search label>span {
position: relative;
display: block;
font-size: 85%;
text-align: right;
padding: .2em .8em .2em 2em;
}
.flex-search label:hover>span,
.flex-search input[type="radio"]:checked~span {
color: #999;
background-color: #eee;
}
.flex-search input[type="radio"]:checked~span:before {
position: absolute;
left: .7em;
content: '✔';
}
.flex-search input[type="radio"] {
display: none;
}
.flex-search input[type="text"] {
width: 100%;
box-sizing: border-box;
padding: .2em .8em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<fieldset class="flex-search">
<span>
<input type="text" name="id" placeholder="contains">
</span>
<span>
<span>
<label><input type="radio" name="t-id" value="c" checked="checked"><span>contains</span></label>
<label><input type="radio" name="t-id" value="s"><span>starts with</span></label>
<label><input type="radio" name="t-id" value="e"><span>ends with</span></label>
<label><input type="radio" name="t-id" value="i"><span>equals</span></label>
</span>
</span>
</fieldset>
</div>
Connecting both solution from LGSon and this one, the result should be something like this:
$('.flex-search input[type="radio"]').click(function() {
$(this).closest('span')
.css('display', 'none')
.delay(500)
.queue(function(next) {
$(this).removeAttr('style');
next();
});
$(this).closest('fieldset')
.find('input[type="text"]')
.attr('placeholder', $(this).closest('label').text())
.focus();
});
* {
margin: 0;
padding: 0;
border: medium none;
border-spacing: 0;
outline: none;
outline: 0;
color: inherit;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
text-align: inherit;
text-decoration: none;
text-indent: 0;
list-style: none outside none;
background: none repeat scroll 0 0 transparent;
}
*::-moz-focus-inner {
border: 0;
padding: 0;
}
html {
color: #222;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
text-align: left;
height: 100%;
}
body {
font-size: 1.4rem;
line-height: 1.5em;
min-height: 100%;
background-color: #fff;
}
div {
margin: 150px auto 0;
width: 300px;
}
::-webkit-input-placeholder {
color: #666;
font-size: 85%;
}
:-moz-placeholder {
color: #666;
font-size: 85%;
}
::-moz-placeholder {
color: #666;
font-size: 85%;
}
:-ms-input-placeholder {
color: #666;
font-size: 85%;
}
:focus::-webkit-input-placeholder {
color: #ccc;
}
:focus:-moz-placeholder {
color: #ccc;
}
:focus::-moz-placeholder {
color: #ccc;
}
:focus:-ms-input-placeholder {
color: #ccc;
}
.flex-search {
position: relative;
display: -webkit-flex;
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 100%;
border: 1px solid #222;
border-radius: .4em;
background-color: #fff;
}
.flex-search> :first-child {
-webkit-flex: 1;
flex: 1;
}
.flex-search> :last-child {
width: 2em;
border-left: 1px solid #ccc;
cursor: pointer;
}
.flex-search> :last-child:after {
content: '\00a0';
display: block;
width: 100%;
height: 100%;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAEG0lEQVQ4EQEQBO/7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6eSOOoDWnnAAAAABJRU5ErkJggg==') no-repeat center center;
opacity: 0.5;
}
.flex-search> :last-child:hover:after {
opacity: 1;
}
.flex-search> :last-child> :first-child {
position: absolute;
right: -1px;
bottom: 0;
display: none;
padding: 0 .25em 2.1em 0;
color: #fff;
}
.flex-search> :last-child:hover> :first-child {
display: block;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.flex-search label {
display: block;
cursor: pointer;
background-color: #ccc;
}
.flex-search label>span {
position: relative;
display: block;
font-size: 85%;
text-align: right;
padding: .2em .8em .2em 2em;
}
.flex-search label:hover>span,
.flex-search input[type="radio"]:checked~span {
color: #999;
background-color: #eee;
}
.flex-search input[type="radio"]:checked~span:before {
position: absolute;
left: .7em;
content: '✔';
}
.flex-search input[type="radio"] {
display: none;
}
.flex-search input[type="text"] {
width: 100%;
box-sizing: border-box;
padding: .2em .8em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<div class="flex-search">
<span>
<input type="text" name="id" placeholder="contains">
</span>
<span>
<span>
<label><input type="radio" name="t-id" value="c" checked="checked"><span>contains</span></label>
<label><input type="radio" name="t-id" value="s"><span>starts with</span></label>
<label><input type="radio" name="t-id" value="e"><span>ends with</span></label>
<label><input type="radio" name="t-id" value="i"><span>equals</span></label>
</span>
</span>
</div>
</div>

Related

Styling icon and button when select is disabled

I have a select with reset style and trying to create additional button and dropdown arrow icon inside using ::after selector and content. And now I'm trying to style the select in case of disabled applied on it. For the button case, I change the style by using select:disabled + button.resetDropdownButton::after. However, I still can't find the way to re-style the arrow icon when select is disabled. Anyone know how to do it?
select, option {
-webkit-appearance: none;
}
button.resetDropdownButton::after {
content: "\2716";
}
.filterWrapper {
/* flex: 1;*/
margin: 0 1rem 1rem;
position: relative;
}
.filterWrapper label {
display: block;
margin-bottom: .25rem;
}
.filterItem {
position: relative;
}
.filterItem::after {
/*add arrow down from fa-icon*/
content: '\f107';
font: normal normal normal 12px/1 FontAwesome;
color: black;
right: 8px;
top: -2px;
height: 26px;
padding: 15px 0px 0px 8px;
position: absolute;
pointer-events: none;
}
.filterItem select {
width: 100%;
/*padding: 0.5rem 1rem;*/
padding-right: 2rem;
padding-left: 1rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
font-size: 1rem;
border-radius: 6px;
border: 2px solid #CBD2E0;
transition: .2s all;
cursor: pointer;
}
.filterItem select::-webkit-input-placeholder {
color: var(--grey);
}
.filterItem select:focus {
outline: none;
background-color: rgba(214, 238, 247, 0.5);
border: 1px solid var(--blue);
box-shadow: 0 0 3px var(--blue);
}
.filterItem select > option {
border-radius: 10px;
}
.filterWrapper .resetDropdownButton {
position: absolute;
top: auto;
right: 1.15rem;
bottom: .5rem;
background-color: transparent;
font-family: 'Roboto', sans-serif;
font-size: 1rem;
/* font-weight: bold;*/
border: 0 solid transparent;
cursor: pointer;
}
.filterWrapper .resetDropdownButton:hover {
text-decoration: underline;
}
select:disabled + button.resetDropdownButton::after {
color: gray;
opacity: 0.7;
}
select:disabled + button.resetDropdownButton:hover {
text-decoration: none;
}
select:disabled + filterItem::after {
/*add arrow down from fa-icon*/
color: yellow;
opacity: 0.7;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" rel="stylesheet" />
<div class="filterWrapper">
<div class="filterItem">
<select disabled>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<button class="resetDropdownButton"></button>
</div>
</div>
I expect the arrow icon that I create using ::after on the div wrapper can be restyle like the button one when select disabled.
Keeping the same HTML structure
This can be achieved with .filterItem:has(select:disabled)::after. But selector :has() is not well supported so far. You can read more.
select,
option {
-webkit-appearance: none;
}
button.resetDropdownButton::after {
content: "\2716";
}
.filterWrapper {
/* flex: 1;*/
margin: 0 1rem 1rem;
position: relative;
}
.filterWrapper label {
display: block;
margin-bottom: .25rem;
}
.filterItem {
position: relative;
}
.filterItem::after {
/*add arrow down from fa-icon*/
content: '\f107';
font: normal normal normal 12px/1 FontAwesome;
color: black;
right: 8px;
top: -2px;
height: 26px;
padding: 15px 0px 0px 8px;
position: absolute;
pointer-events: none;
}
.filterItem select {
width: 100%;
/*padding: 0.5rem 1rem;*/
padding-right: 2rem;
padding-left: 1rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
font-size: 1rem;
border-radius: 6px;
border: 2px solid #CBD2E0;
transition: .2s all;
cursor: pointer;
}
.filterItem select::-webkit-input-placeholder {
color: var(--grey);
}
.filterItem select:focus {
outline: none;
background-color: rgba(214, 238, 247, 0.5);
border: 1px solid var(--blue);
box-shadow: 0 0 3px var(--blue);
}
.filterItem select>option {
border-radius: 10px;
}
.filterWrapper .resetDropdownButton {
position: absolute;
top: auto;
right: 1.15rem;
bottom: .5rem;
background-color: transparent;
font-family: 'Roboto', sans-serif;
font-size: 1rem;
/* font-weight: bold;*/
border: 0 solid transparent;
cursor: pointer;
}
.filterWrapper .resetDropdownButton:hover {
text-decoration: underline;
}
select:disabled+button.resetDropdownButton::after {
color: gray;
opacity: 0.7;
}
select:disabled+button.resetDropdownButton:hover {
text-decoration: none;
}
.filterItem:has(select:disabled)::after {
/*add arrow down from fa-icon*/
color: gray;
opacity: 0.7;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" rel="stylesheet" />
<div class="filterWrapper">
<div class="filterItem">
<select disabled>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<button class="resetDropdownButton"></button>
</div>
</div>
Change HTML structure
You can change the HTML structure and include the arrow inside your .filterItem and after the select, while also applying some CSS to make it look good.
This is better and more supported so far.
Something like this:
select,
option {
-webkit-appearance: none;
}
button.resetDropdownButton::after {
content: "\2716";
}
.filterWrapper {
/* flex: 1;*/
margin: 0 1rem 1rem;
position: relative;
}
.filterWrapper label {
display: block;
margin-bottom: .25rem;
}
.filterItem {
position: relative;
}
.filterItem select {
width: 100%;
/*padding: 0.5rem 1rem;*/
padding-right: 2rem;
padding-left: 1rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
font-size: 1rem;
border-radius: 6px;
border: 2px solid #CBD2E0;
transition: .2s all;
cursor: pointer;
}
.filterItem select::-webkit-input-placeholder {
color: var(--grey);
}
.filterItem select:focus {
outline: none;
background-color: rgba(214, 238, 247, 0.5);
border: 1px solid var(--blue);
box-shadow: 0 0 3px var(--blue);
}
.filterItem select>option {
border-radius: 10px;
}
.filterWrapper .resetDropdownButton {
position: absolute;
top: auto;
right: 1.15rem;
bottom: .5rem;
background-color: transparent;
font-family: 'Roboto', sans-serif;
font-size: 1rem;
/* font-weight: bold;*/
border: 0 solid transparent;
cursor: pointer;
}
.filterWrapper .resetDropdownButton:hover {
text-decoration: underline;
}
select:disabled+button.resetDropdownButton::after {
color: gray;
opacity: 0.7;
}
select:disabled+button.resetDropdownButton:hover {
text-decoration: none;
}
.arrow::after {
/*add arrow down from fa-icon*/
content: '\f107';
font: normal normal normal 12px/1 FontAwesome;
color: black;
right: 8px;
top: -2px;
height: 26px;
padding: 15px 0px 0px 8px;
position: absolute;
pointer-events: none;
}
select:disabled + button.resetDropdownButton + span.arrow::after {
color: gray;
opacity: 0.7;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" rel="stylesheet" />
<div class="filterWrapper">
<div class="filterItem">
<select disabled>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<button class="resetDropdownButton"></button>
<span class="arrow"></span>
</div>
</div>

How to make click hide popup button without js only in html and css?

How to put/place function click hide in popup button without js only through Html and CSS?
I need the close button to close the popup as the x button closes the button.
is there a way to implement this in the HTML or CSS code?
at the bottom is an example of the code.
<!doctype html>
<head>
</head>
<body>
<div id="css-modal">
<input id="modal" class="css-modal-check" type="checkbox" checked />
<div class="css-modal">
<label for="modal" class="close"></label>
<p><img src="./popup-logo.png" alt="" class="center"></p>
<h2>DISCLAIMER</h2>
<p>This site is for recreational use only!
</p>
<div class="css-modal-btn2"><button class="btn2 btn2-primary btn-md">CLOSE</button></a></div>
</div>
<div id="overlay"></div>
</div>
</div>
</body>
</html>
On the bottom, is the css code as a sample.
/* Main Styles */
body {
background-color: #f5f5f5;
color: #333;
font-family: "Arial", Arial, sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.75;
opacity: 15;
}
#page-wrapper {
padding: 1.5em;
}
p.center {
text-align: center;
color: #fff;
}
h1 {
color: #fff;
text-align: center;
text-transform: uppercase;
font-weight: 400;
}
/* Modal Styles */
#css-modal {
bottom: 0;
height: 100%;
left: 0;
pointer-events: none;
position: fixed;
right: 0;
text-align: center;
top: 0;
white-space: nowrap;
padding: 1.5rem 1.6em!important;
z-index: 99;
}
#css-modal h2 {
color: #fff;
font-weight: 700;
font-size: 2em;
letter-spacing: 0.02em;
padding: 0;
margin-bottom: 0.5em;
margin-top: 0;
}
#css-modal .css-modal-check {
display: none;
pointer-events: auto;
}
#css-modal .css-modal-check:checked ~ .css-modal {
opacity: 1;
pointer-events: auto;
}
#css-modal .css-modal {
background: #B92101;
border-radius: 3px;
display: inline-block;
width:600px;
max-width:100%;
min-height:300px;
opacity: 0;
padding: 2.7em;
pointer-events: none;
position: relative;
text-align: center;
vertical-align: middle;
white-space: normal;
z-index: 1;
}
#css-modal .css-modal p {
text-align: center;
color: #fff;
}
#css-modal .css-modal .close {
color: #cca72f;
position: absolute;
right: 1em;
top: 0.5em;
}
#css-modal .css-modal .css-modal-btn2 button {
font-weight: 700;
letter-spacing: 0.05em;
margin-top: 1em;
}
#css-modal .css-modal-check:checked ~ #overlay {
opacity: 0.8;
pointer-events: auto;
}
#css-modal #overlay {
background: #000;
bottom: 0;
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
transition: opacity 0.8s;
}
#css-modal:before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
.close:after {
color: #cca72f;
content: "\0058";
float: right;
font-size: 1.75em;
}
#css-modal .btn2-primary {
color: #fff;
background-color: #cca72f;
}
#css-modal .btn2-primary:hover {
background-color: #b39124;
}
#css-modal .btn2 {
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
font-size: 1em;
padding: 0.75em 1.25em;
text-align: center;
}
working with the code snipped you provided, I changed a few things to demonstrate how to accomplish this without js. Essentially you use the checkbox to manage state, and change the css display value depending on whether or not the checkbox is checked. You can use the label to trigger the checkbox. I also hid the checkbo itself so that it's not visible and the state is managed in the background. Hopefully this helps!
<head>
<style>
label > button {
pointer-events: none;
user-select: none;
}
.css-modal {
display: none;
}
#modal {
display: none;
}
#modal:checked ~ .css-modal {
display: block;
}
</style>
</head>
<body>
<div id="css-modal">
<input id="modal" class="css-modal-check" type="checkbox" checked />
<div class="css-modal">
<p><img src="./popup-logo.png" alt="" class="center" /></p>
<h2>DISCLAIMER</h2>
<p>This site is for recreational use only!</p>
<div class="css-modal-btn2">
<label for="modal" class="close">
<button class="btn2 btn2-primary btn-md">CLOSE</button>
</label>
</div>
</div>
<div id="overlay"></div>
</div>
</body>
/* Main Styles */
body {
background-color: #f5f5f5;
color: #333;
font-family: "Arial", Arial, sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.75;
opacity: 15;
}
#page-wrapper {
padding: 1.5em;
}
p.center {
text-align: center;
color: #fff;
}
h1 {
color: #fff;
text-align: center;
text-transform: uppercase;
font-weight: 400;
}
/* Modal Styles */
#css-modal {
bottom: 0;
height: 100%;
left: 0;
pointer-events: none;
position: fixed;
right: 0;
text-align: center;
top: 0;
white-space: nowrap;
padding: 1.5rem 1.6em!important;
z-index: 99;
}
#css-modal h2 {
color: #fff;
font-weight: 700;
font-size: 2em;
letter-spacing: 0.02em;
padding: 0;
margin-bottom: 0.5em;
margin-top: 0;
}
#css-modal .css-modal-check {
display: none;
pointer-events: auto;
}
#css-modal .css-modal-check:checked ~ .css-modal {
opacity: 1;
pointer-events: auto;
}
#css-modal .css-modal {
background: #B92101;
border-radius: 3px;
display: inline-block;
width:600px;
max-width:100%;
min-height:300px;
opacity: 0;
padding: 2.7em;
pointer-events: none;
position: relative;
text-align: center;
vertical-align: middle;
white-space: normal;
z-index: 1;
}
#css-modal .css-modal p {
text-align: center;
color: #fff;
}
#css-modal .css-modal .close {
color: #cca72f;
position: absolute;
right: 1em;
top: 0.5em;
}
#css-modal .css-modal .css-modal-btn2 button {
font-weight: 700;
letter-spacing: 0.05em;
margin-top: 1em;
user-select: none;
pointer-events: none;
}
#css-modal .css-modal-check:checked ~ #overlay {
opacity: 0.8;
pointer-events: auto;
}
#css-modal #overlay {
background: #000;
bottom: 0;
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
transition: opacity 0.8s;
}
#css-modal:before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
.close:after {
color: #cca72f;
content: "\0058";
float: right;
font-size: 1.75em;
}
#css-modal .btn2-primary {
color: #fff;
background-color: #cca72f;
}
#css-modal .btn2-primary:hover {
background-color: #b39124;
}
#css-modal .btn2 {
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
font-size: 1em;
padding: 0.75em 1.25em;
text-align: center;
}
<!doctype html>
<head>
</head>
<body>
<div id="css-modal">
<input id="modal" class="css-modal-check" type="checkbox" checked />
<div class="css-modal">
<p><img src="./popup-logo.png" alt="" class="center"></p>
<h2>DISCLAIMER</h2>
<p>This site is for recreational use only!
</p>
<div class="css-modal-btn2">
<label for="modal" class="close"></label>
<label for="modal"><div class="css-modal-btn2"><button class="btn2 btn2-primary btn-md">Close</button></label></div>
</div>
</div>
<div id="overlay"></div>
</div>
</body>
</html>

Change the background color when an input is checked [duplicate]

This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Closed 4 years ago.
I can't change the background of my div when an input is checked.
When I check the second input the background of the div should change, possibly with an animation from left to right. Is there anyone who can help me?
This is the html:
.first_switcher {
display: block;
margin: 0 auto;
height: 38px;
margin-top: 50px;
padding: 0px;
background: dimgray;
width: 200px;
border-radius: 38px;
position: relative;
}
.first_switcher__input2 {
display: none;
}
.first_switcher__input1 {
display: none;
}
.first_switcher__label1 {
float: left;
width: 100px;
font-size: 12px;
line-height: 38px;
color: #ffffff;
text-align: center;
cursor: pointer;
z-index: 10;
}
.first_switcher__label2 {
float: left;
width: 100px;
font-size: 12px;
line-height: 38px;
color: dimgray;
text-align: center;
cursor: pointer;
z-index: 10;
}
.first_switcher__input1:checked+.first_switcher__label1 {
color: white;
}
.first_switcher__input2:checked+.first_switcher__label2 {
color: white;
}
.first_switcher__input1:not(:checked)+.first_switcher__label1 {
color: dimgray;
}
.first_switcher__input2:checked+.first_switcher {
background: black;
}
<div class="first_switcher">
<input type="radio" name="balance" id="on" class="first_switcher__input1" checked/>
<label for="on" class="first_switcher__label1">ON</label>
<input type="radio" name="balance" id="off" class="first_switcher__input2"/>
<label for="off" class="first_switcher__label2">OFF</label>
</div>
If you want to do with css then consider below snippet. change color according to your need.
.first_switcher {
display: block;
margin: 0 auto;
height: 38px;
margin-top: 50px;
padding: 0px;
background: dimgray;
width: 200px;
border-radius: 38px;
position: relative;
}
.first_switcher__input2 {
display: none;
}
.first_switcher__input1 {
display: none;
}
.first_switcher__label1 {
float: left;
width: 100px;
font-size: 12px;
line-height: 38px;
color: #ffffff;
text-align: center;
cursor: pointer;
z-index: 10;
}
.first_switcher__label2 {
float: left;
width: 100px;
font-size: 12px;
line-height: 38px;
color: dimgray;
text-align: center;
cursor: pointer;
z-index: 10;
}
.first_switcher__input1:checked+.first_switcher__label1 {
color: white;
}
.first_switcher__input2:checked+.first_switcher__label2 {
color: white;
}
.first_switcher__input1:not(:checked)+.first_switcher__label1 {
color: dimgray;
}
.first_switcher__input2:checked+.first_switcher {
background: black;
}
/*.first_switcher__input1:checked+.first_switcher__label1 {
background: red;
}
.first_switcher__input2:not(:checked)+.first_switcher__label2 {
background: red;
} */
.first_switcher__input1:not(:checked)+.first_switcher__label1 {
color:blue;
background: blue;
border-top-left-radius: 19px;
border-bottom-left-radius: 19px;
}
.first_switcher__input2:checked+.first_switcher__label2 {
background: blue;
border-top-right-radius: 19px;
border-bottom-right-radius: 19px;
}
<div class="first_switcher">
<input type="radio" name="balance" id="on" class="first_switcher__input1" checked/>
<label for="on" class="first_switcher__label1">ON</label>
<input type="radio" name="balance" id="off" class="first_switcher__input2"/>
<label for="off" class="first_switcher__label2">OFF</label>
</div>
You can't target parent via CSS, you have to use JS. But those siblings selector should have spaces between "+", like:
.first_switcher__input1:checked + .first_switcher__label1 {
color: white;
}
.first_switcher__input2:checked + .first_switcher__label2 {
color: white;
}
.first_switcher__input1:not(:checked) + .first_switcher__label1 {
color: dimgray;
}
Use JS to do it onchange set background to parent(wrap div) and change css as below
function changeOn(ele){
if(ele.checked)
{
document.getElementsByClassName("first_switcher")[0].style.background="red";
document.getElementsByClassName("first_switcher__label2")[0].style.color="transparent"
}
}
function changeOff(ele){
if(ele.checked)
{
document.getElementsByClassName("first_switcher")[0].style.background="dimgray";
document.getElementsByClassName("first_switcher__label2")[0].style.color="white"
}
}
.first_switcher {
display: block;
margin: 0 auto;
height: 38px;
margin-top: 50px;
padding: 0px;
background: red;
width: 200px;
border-radius: 38px;
position: relative;
}
.first_switcher__input2 {
display: none;
}
.first_switcher__input1 {
display: none;
}
.first_switcher__label1 {
float: left;
width: 100px;
font-size: 12px;
line-height: 38px;
color: #ffffff;
text-align: center;
cursor: pointer;
z-index: 10;
}
.first_switcher__label2 {
float: left;
width: 100px;
font-size: 12px;
line-height: 38px;
color: transparent;
text-align: center;
cursor: pointer;
z-index: 10;
}
.first_switcher__input1:checked+.first_switcher__label1 {
color: white;
}
.first_switcher__input2:checked+.first_switcher__label2 {
color: white;
}
.first_switcher__input1:not(:checked)+.first_switcher__label1 {
color: dimgray;
}
.first_switcher__input2:checked+.first_switcher {
background: black;
}
<div class="first_switcher">
<input type="radio" name="balance" id="on" class="first_switcher__input1" onchange="changeOn(this)" checked/>
<label for="on" class="first_switcher__label1">ON</label>
<input onchange="changeOff(this)" type="radio" name="balance" id="off" class="first_switcher__input2"/>
<label for="off" class="first_switcher__label2">OFF</label>
</div>

Radio buttons and checkboxes not appearing

I am trying to launch a Web UI using Flask, however, the radio buttons and check boxes aren't showing. I've tried following online examples, like the ones here: https://www.w3schools.com/bootstrap/bootstrap_forms_inputs.asp
The CSS file has a lot of sections pertaining to checkboxes/radios, but I'm not sure which part is the source of the problem (if that).
Here is the relevant portion of the CSS file:
/* Form */
form {
margin: 0 0 2em 0;
}
label {
display: block;
font-size: 0.9em;
font-weight: 400;
margin: 0 0 1em 0;
}
input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
border-radius: 4px;
border: none;
border: solid 1px;
color: inherit;
display: block;
outline: 0;
padding: 0 1em;
text-decoration: none;
width: 100%;
}
input[type="text"]:invalid,
input[type="password"]:invalid,
input[type="email"]:invalid,
select:invalid,
textarea:invalid {
box-shadow: none;
}
.select-wrapper {
text-decoration: none;
display: block;
position: relative;
}
.select-wrapper:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
.select-wrapper:before {
content: '\f078';
display: block;
height: 2.75em;
line-height: 2.75em;
pointer-events: none;
position: absolute;
right: 0;
text-align: center;
top: 0;
width: 2.75em;
}
.select-wrapper select::-ms-expand {
display: none;
}
input[type="text"],
input[type="password"],
input[type="email"],
select {
height: 2.75em;
}
textarea {
padding: 0.75em 1em;
}
input[type="checkbox"],
input[type="radio"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
display: block;
float: left;
margin-right: -2em;
opacity: 0;
width: 1em;
z-index: -1;
}
input[type="checkbox"]+label,
input[type="radio"]+label {
text-decoration: none;
cursor: pointer;
display: inline-block;
font-size: 1em;
font-weight: 200;
padding-left: 2.4em;
padding-right: 0.75em;
position: relative;
}
input[type="checkbox"]+label:before,
input[type="radio"]+label:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
input[type="checkbox"]+label:before,
input[type="radio"]+label:before {
border-radius: 4px;
border: solid 1px;
content: '';
display: inline-block;
height: 1.65em;
left: 0;
line-height: 1.58125em;
position: absolute;
text-align: center;
top: 0;
width: 1.65em;
}
input[type="checkbox"]:checked+label:before,
input[type="radio"]:checked+label:before {
content: '\f00c';
}
input[type="checkbox"]+label:before {
border-radius: 4px;
}
input[type="radio"]+label:before {
border-radius: 100%;
}
::-webkit-input-placeholder {
opacity: 1.0;
}
:-moz-placeholder {
opacity: 1.0;
}
::-moz-placeholder {
opacity: 1.0;
}
:-ms-input-placeholder {
opacity: 1.0;
}
.formerize-placeholder {
opacity: 1.0;
}
label {
color: #444444;
}
input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
background: rgba(144, 144, 144, 0.075);
border-color: #666666;
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
border-color: #EF6480;
box-shadow: 0 0 0 1px #EF6480;
}
.select-wrapper:before {
color: #666666;
}
input[type="checkbox"]+label,
input[type="radio"]+label {
color: #666666;
}
input[type="checkbox"]+label:before,
input[type="radio"]+label:before {
background: rgba(144, 144, 144, 0.075);
border-color: #666666;
}
input[type="checkbox"]:checked+label:before,
input[type="radio"]:checked+label:before {
background-color: #EF6480;
border-color: #EF6480;
color: #ffffff;
}
input[type="checkbox"]:focus+label:before,
input[type="radio"]:focus+label:before {
border-color: #EF6480;
box-shadow: 0 0 0 1px #EF6480;
}
::-webkit-input-placeholder {
color: #999999 !important;
}
:-moz-placeholder {
color: #999999 !important;
}
::-moz-placeholder {
color: #999999 !important;
}
:-ms-input-placeholder {
color: #999999 !important;
}
.formerize-placeholder {
color: #999999 !important;
}
Here is the relevant portion of the HTML file:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Wrapper -->
<div id="wrapper">
<!-- Banner -->
<section id="intro" class="main">
<span class="icon fa-diamond major"></span>
<h3>Please upload your authors list below</h3>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<br><br>
<input type="checkbox" name="sep1" value="Separate initials with period"> Separate initials with period<br>
<input type="checkbox" name="sep2" value="Separate initials with space"> Separate initials with space<br>
<input type="radio" name="affiliation" value="Mark affiliations with letter"> Mark affiliations with letter
<input type="radio" name="affiliation" value="Mark affiliations with number" checked> Mark affiliations with number<br><br>
<input type=submit value=Upload></p>
</form>
</section>
</div>
You can Simplify your CSS from :
input[type="checkbox"], input[type="radio"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
display: block;
float: left;
margin-right: -2em;
opacity: 0;
width: 1em;
z-index: -1;
}
Into This 1
input[type="checkbox"], input[type="radio"] {
width: 1em;
z-index: -1;
}
Or You can just Delete that part of your CSS
Here is the problematic section of your css:
input[type="checkbox"],
input[type="radio"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
display: block;
float: left;
margin-right: -2em;
opacity: 0;
width: 1em;
z-index: -1;
}
Change opacity to 1
Get rid of the appearance none.
There are other problems with your code but this solves your question about the boxes not appearing.
This should get you closer to what you are looking for:
input[type="checkbox"],
input[type="radio"] {
display: inline-block;
opacity: 1;
width: 1em;
z-index: -1;
}
It can happen because of multiple reasons, however
opacity: 1;
is one of the crucial things if your checkbox is not visible. Secondly, your position should not be absolute, it should be like
position: relative;
Just in case you are not able to click/check your checkbox, it's because you have blocked pointer-events. So change it to
pointer-events: all;
In all, your CSS code will look like this,
input[type="checkbox"]{
width: 1em;
position: relative;
opacity: 1;
pointer-events: all;
}
Note: In case if you still fail to achieve the desired result, try this code
input[type="checkbox"]{
width: 1em;
position: relative !important;
opacity: 1 !important;
pointer-events: all !important;
}

CSS Form underline text field animation effect

I have the following code (below) of my form section and in it i want this (below image) underline animation to be done in the text input field . Whenever the user focus on the field the animation to be done.
the animation is to be smooth ease.
But something is missing i can't find in it. What is wrong and How to fix it?
Anyone Please help
html {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
text-rendering: optimizelegibility;
}
html, body {
height: 100%;
}
#contact {
font-family: "Montserrat", sans-serif;
font-size: 14px;
font-weight: 300;
letter-spacing: 3px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
margin: 10% 0;
}
#contact main, body footer {
width: 100%;
}
#contact main {
height: 100%;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.form .text-input, .form .textarea, .form .label, .form .button {
padding: 1em 1.5em;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: none;
line-height: normal;
border: 1px solid transparent;
border-radius: 0;
}
.form .text-input, .form .textarea {
font: inherit;
line-height: normal;
width: 100%;
box-sizing: border-box;
display: block;
padding-left: 0;
border-bottom-color: #00d2ff;
background: transparent;
outline: none;
color: black;
}
.form .text-input:placeholder, .form .textarea:placeholder {
color: rgba(0, 0, 0, 0.7);
}
.form .text-input:-webkit-autofill, .form .textarea:-webkit-autofill {
box-shadow: 0 0 0px 1000px white inset;
border-top-color: white;
border-left-color: white;
border-right-color: white;
}
.form .error.text-input, .form .error.textarea, .error .form .text-input, .form .error .text-input, .error .form .textarea, .form .error .textarea {
border-color: transparent transparent red transparent;
}
.form:not(.has-floated-label) .text-input:active, .form:not(.has-floated-label) .textarea:active, .form:not(.has-floated-label) .text-input:focus, .form:not(.has-floated-label) .textarea:focus {
border-color: transparent transparent black transparent;
}
.form .label {
position: absolute;
z-index: 10;
pointer-events: none;
padding-left: 0;
}
.form .label {
top: 0;
left: 0;
color: rgba(0, 0, 0, 0.3);
-webkit-transition: color 0.3s;
transition: color 0.3s;
}
.active .form .label, .form .active .label {
font-size: 0.80em;
line-height: 1;
font-weight: 600;
text-transform: uppercase;
padding: 0;
color: rgba(0, 0, 0, 0.7);
background: white;
}
.focus .form .label, .form .focus .label {
color: black;
}
.form.has-floated-label .field:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 0%;
border-bottom: 3px solid #00d2ff;
-webkit-transition: width 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955);
transition: width 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955);
}
.form.has-floated-label .field.focus:after {
width: 100%;
}
.form .button {
font: inherit;
line-height: normal;
cursor: pointer;
background-color: #00d2ff;
color: white;
text-transform: uppercase;
text-align: center;
letter-spacing: 0.14286em;
transition-duration: 0.4s;
}
.form .button:hover, .form .button:focus, .form .button:active {
box-shadow: 0 10px 15px rgba(0, 0, 0, .1);
}
.form .button:active {
position: relative;
top: 1px;
left: 1px;
}
.form {
/* max-width: 50em; */
width: 100%;
margin: 0 10%;
/* padding: 1em 2em; */
box-sizing: border-box;
overflow: hidden;
}
.form .field {
position: relative;
width: 100%;
margin-bottom: 1.5em;
float: left;
}
#media screen and (min-width: 40em) {
.form .field.half {
width: calc(50% - 2em);
margin-right: 2em;
}
.form .field.half + .half {
margin-left: 2em;
margin-right: 0;
}
}
.form .field:last-child {
float: right;
width: auto;
}
.form .textarea {
max-width: 100%;
}
<section id="contact">
<main>
<form action='' class='form'>
<p class='field required half'>
<label class='label required' for='name'>Name</label>
<input class='text-input' id='name' name='name' required type='text'>
</p>
<p class='field required half'>
<label class='label' for='email'>E-mail</label>
<input class='text-input' id='email' name='email' required type='email'>
</p>
<p class='field'>
<label class='label' for='message'>Message</label>
<textarea class='textarea' cols='50' id='message' name='message' required rows='4'></textarea>
</p>
<p class='field'>
<input class='button' type='submit' value='Send message'>
</p>
</form>
</main>
</section>
This is an example:
.input-name{
position: relative;
display: inline-block;
overflow: hidden;
}
.input-name > input[type=text]{
border: none;
border-bottom: 2px solid red;
outline: none;
}
.underline-animation{
transition: all 0.5s;
display: inline-block;
bottom: 0;
left: -100%;
position: absolute;
width: 100%;
height: 2px;
background-color: #64e4fe;
}
.input-name > input[type=text]:focus + .underline-animation{
left: 0;
}
<div class="input-name">
<input type="text" placeholder="name">
<span class="underline-animation"></span>
</div>
I don't think this is possible with only the underline element since I know of no way to animate it like that, you can use the <hr> element though.
then you can do
hr{
position:relative;
left:0;
width:0%;
height:2px;
background-color:#1784E1;
border:none;
margin-top:0;
margin-left:0;
margin-bottom:20px;
transition:0.5s;
}
input:focus + hr{
width:100%;
}
if you go to sam.apostel.be/TAD, is that what you want?