Style radio buttons once checked/selected - css

I'm trying to change the colour of radio buttons and button label when the radio button has been selected. Have tried this.
input[type='radio']:checked {
background: yellow !important;
}
<label
className='tag-item'
key={tag}
htmlFor={`filter-${tag}`}
clickable='true'>
<span>{tag}</span>
<input
type='radio'
name='tag'
id={`filter-${tag}`}
value={tag}
checked={tag === currentTag}
onChange={e => setCurrentTag(e.target.value)}
className='tag-radio'
/>
</label>

You can't change the default Radio button's color.
But you can do this with some trick.
input[type=radio]{
display: none;
}
.fake-radio{
position: relative;
display: inline-block;
width: 12px;
height: 12px;
border: 1px solid gray;
border-radius: 100%;
}
.fake-radio::before{
content: '';
display: block;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 6px;
height: 6px;
background-color: gray;
border-radius: 100%;
}
input[type=radio]:checked + .fake-radio{
border-color: red;
}
input[type=radio]:checked + .fake-radio::before{
background-color: red;
}
<label>
<span>Tag</span>
<input type="radio" />
<span class="fake-radio"></span>
</label>

Related

Because of Child div's height, it is resizing parent div

My search suggestion box is not flowing all the way into the section below rather it is resizing the whole navbar. The search input is in the navigation bar. I want the search suggestions to just flow in the divs below. I have tried all the overflow property values but it is not giving me what I want.
.search-box {
position: relative;
}
.nav-search {
width: 260px;
}
.autocom-box {
background-color: white;
color: black;
width: 260px;
/* padding: 10px 8px; */
max-height: 280px;
overflow-y: auto;
border-radius: 5px;
/* opacity: 0; */
/* pointer-events: none; */
}
.search-box li {
list-style: none;
padding: 8px 12px;
cursor: default;
border-radius: 3px;
width: 100%;
/* display: none; */
overflow: auto;
}
.search-box li:hover {
background: #efefef;
}
.search-btn {
height: 38px;
width: 38px;
line-height: 38px;
position: absolute;
top: 0;
right: 0;
text-align: center;
cursor: pointer;
color: black;
margin-right: 10px;
border: none;
background: none;
}
<form class="d-flex ms-auto" action="/" method="post">
<div class="search-box">
<input
class="form-control me-2 nav-search"
autocomplete="off"
name="search"
placeholder="Type to Search..."
/>
<div class="autocom-box">
<li>Avengers</li>
<li>Avengers</li>
<li>Avengers</li>
<li>Avengers</li>
</div>
<button class="search-btn" type="submit">
<i class="fas fa-search"></i>
</button>
</div>
</form>
I've tried giving the full navbar max-height but then it tries to keep everything inside of it so it just pushes the search-box so high up it disappears.
And I've also tried position: absolute; but even that doesn't work it just messes everything up.
Adding position: absolute; to the pop-out window (.autocom-box) should just about do the trick:
.search-box {
position: relative;
border: 2px solid black;
}
.nav-search {
width: 260px;
}
.autocom-box {
position: absolute; /* This is the change */
background-color: white;
border: 2px solid red;
color: black;
width: 260px;
/* padding: 10px 8px; */
max-height: 280px;
overflow-y: auto;
border-radius: 5px;
/* opacity: 0; */
/* pointer-events: none; */
}
.search-box li {
list-style: none;
padding: 8px 12px;
cursor: default;
border-radius: 3px;
width: 100%;
/* display: none; */
overflow: auto;
}
.search-box li:hover {
background: #efefef;
}
.search-btn {
height: 38px;
width: 38px;
line-height: 38px;
position: absolute;
top: 0;
right: 0;
text-align: center;
cursor: pointer;
color: black;
margin-right: 10px;
border: none;
background: none;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css">
<form class="d-flex ms-auto" action="/" method="post">
<div class="search-box">
<input
class="form-control me-2 nav-search"
autocomplete="off"
name="search"
placeholder="Type to Search..."
/>
<div class="autocom-box">
<li>Avengers</li>
<li>Avengers</li>
<li>Avengers</li>
<li>Avengers</li>
</div>
<button class="search-btn" type="submit">
<i class="fas fa-search"></i>
</button>
</div>
</form>
(The black border is the nav bar itself, the red border is the search window)

How to change the colour of placeholder and input field of matInput field using of Angular material

In my code (see below) I want to set the colour of placeholder i.e Username and Password and a margin below it to white.
Means the Username and password text should be of white colour and border below it should also be of white colour as i am using a dark back-ground colour.
How can I achieve that?
Html
<mat-card class="login">
<form >
<mat-form-field color="accent" autocomplete="off" class="form">
<input class="inputField" maxlength="10" matInput [placeholder][1]="Enter Username" [formControl]="">
</mat-form-field>
<br>
<mat-form-field color="accent" autocomplete="off" class="form">
<input class="inputField" maxlength="10" type="password" matInput placeholder="Enter Password" [formControl]="">
</mat-form-field>
<div>
<button mat-button class="otp-btn" type="submit">Login</button>
</div>
<br>
</form>
</mat-card>
CSS
.example-container {
display: flex;
flex-direction: column;
}
.login {
margin-top: 80px;
height: 450px;
max-width: 600px;
margin-left: auto;
margin-right: auto;
background-color: #274c7c
}
.material-icons {
margin-left: 2%;
margin-bottom: 10px;
}
.otp-btn {
margin: 30px 30px 30px 30px;
margin-left: 10%;
width: 80%;
font-size:30px;
height: 55px;
color:white;
border-radius: 10px;
background-color: #f6b319;
}
:host {
flex-grow: 1;
display: flex;
justify-content: center;
align-items: center;
}
img {
height: 16%;
width: 174px;
margin-left: 15%;
margin-right: auto;
padding: 10px;
}
div.input {
position: relative;
}
.form {
display: block;
position: relative;
flex: auto;
min-width: 0;
width: 245px !important;
margin-left:15px;
}
.inputField
{
width: 90%;
font-size: 20px;
}
div.input label {
position: absolute;
top: 0;
transform: translateY(-50%);
left: 10px;
background: white;
padding: 5px 2px;
color: white;
}
div.input input {
padding: 10px 20px;
font-size: 25px;
outline: 0;
color: white;
}
div.input {
margin-top: 20px;
color: white;
}
.example-container > * {
width: 100%;
}
See stackBliz for more details.
Add this to css
::ng-deep .mat-form-field-underline, ::ng-deep .mat-form-field-ripple {
background-color: white !important;
color: white !important
}
::ng-deep .mat-form-field-empty.mat-form-field-label {
color: white;
}
After focusing on the input, you can insert the following code to stylize the placeholder after the animation:
::ng-deep .mat-form-field-appearance-legacy.mat-form-field-can-float.mat-form-field-should-float .mat-form-field-label {
color: beige;
font-family: lobster;
}

Removing white spacing between stacked elements in CSS

I am trying to remove spacing between elements stacked on each other.
This is what i have:
input[type="text"] {
width: 40%;
height: 30px;
border-radius: 29px;
border-style: none;
padding-right: 100px;
padding-left: 30px;
border-width: 0;
}
input[type="submit"] {
margin-left: -100px;
height: 30px;
width: 100px;
border-width: 0;
border-radius: 29px;
background: blue;
color: white;
-webkit-appearance: none;
}
body {
background-color: black;
}
<br/>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" placeholder="Enter your email"><input type="submit">
</form>
I have tried top:0; and bottom:0; but it does not seem to solve my problem in this example.
Remove padding-top and padding-bottom on input[type="text"]
padding-top: 0px;
padding-bottom: 0px;
input[type="text"] {
padding-top: 0px;
padding-bottom: 0px;
width: 40%;
height:30px;
border-radius: 29px;
border-style:none;
padding-right:100px;
padding-left:30px;
border-width: 0;
}
input[type="submit"] {
margin-left: -100px;
height:30px;
width: 100px;
border-width: 0;
border-radius: 29px;
background: blue;
color: white;
-webkit-appearance: none;
}
body {
background-color: black;
}
<br/>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" placeholder="Enter your email"><input type="submit">
</form>
Remove the top bottom padding of input[type="text"].
input[type="text"] {
width: 40%;
height: 30px;
border-radius: 29px;
border-style: none;
padding-right: 100px;
padding-left: 30px;
padding-top: 0;
padding-bottom: 0;
}
I removed the height property from both elements and added it to the container, the form. Then added display: flex to the form.
form {
height: 30px;
display: flex;
}
input[type="text"] {
width: 40%;
border-radius: 29px;
border-style: none;
padding-right: 100px;
padding-left: 30px;
border-width: 0;
}
input[type="submit"] {
margin-left: -100px;
width: 100px;
border-width: 0;
border-radius: 29px;
background: blue;
color: white;
-webkit-appearance: none;
}
body {
background-color: black;
}
<br/>
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" placeholder="Enter your email"><input type="submit">
</form>

Radio buttons as tabs

I want to display radio buttons as tabs. Following this codepen, I've attempted this in my project. But when I click on pseudo tab, nothing happens. It doesn't get checked.
How can I achieve the effect?
input.tgl-radio-tab-child {
position: absolute;
left: -99999em;
top: -99999em;
opacity: 1;
z-index: 1;
}
input.tgl-radio-tab-child+label {
cursor: pointer;
float: left;
border: 1px solid #aaa;
margin-right: -1px;
padding: .5em 1em;
position: relative;
}
input.tgl-radio-tab-child+label:hover {
background-color: #eee;
}
[type=radio]:checked+label {
background-color: #c30;
z-index: 1;
}
<label for="abc">ABC<span style="color: red;">*</span></label>
<div class="form-check">
<div class="tgl-radio-tabs">
<input type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label class="radio-inline">ABCDEFGHIJKL</label>
<input type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label class="radio-inline">MNOPQRSTUVWXYZ</label>
</div>
</div>
You need to bind your labels to your inputs via the for attribute which should reference the respective input's ID:
input.tgl-radio-tab-child {
position: absolute;
left: -99999em;
top: -99999em;
opacity: 1;
z-index: 1;
}
input.tgl-radio-tab-child+label {
cursor: pointer;
float: left;
border: 1px solid #aaa;
margin-right: -1px;
padding: .5em 1em;
position: relative;
}
input.tgl-radio-tab-child+label:hover {
background-color: #eee;
}
[type=radio]:checked+label {
background-color: #c30;
z-index: 1;
}
<label for="abc">ABC<span style="color: red;">*</span></label>
<div class="form-check">
<div class="tgl-radio-tabs">
<input id="x" type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label for="x" class="radio-inline">ABCDEFGHIJKL</label>
<input id="y" type="radio" class="form-check-input tgl-radio-tab-child" name="abcorigin"><label for="y" class="radio-inline">MNOPQRSTUVWXYZ</label>
</div>
</div>

focus pointer in center radio button with css3

I've customized this radio button and have trouble focusing the pointer inside the radio button .
<div class="radio">
<input id="left" type="radio" name="gender" value="left">
<label for="left">Left</label>
<input id="right" type="radio" name="gender" value="right">
<label for="right">Right</label>
</div>
label {
display: inline-block;
cursor: pointer;
position: relative;
padding-left: 25px;
margin-right: 15px;
}
input[type=radio] {
display: none;
}
label:before {
content: "";
display: inline-block;
width: 12px;
height: 12px;
margin-right: 10px;
position: absolute;
left: 0;
bottom: 1px;
background-color: #ffffff;
border: 3px solid;
border-color: #bababa;
}
.radio label:before {
border-radius: 8px;
}
input[type=radio]:checked + label:before {
content: "\2022";
color: #373c3e;
font-size: 60px;
text-align: center;
line-height: 16px;
}
Deputy example so that you can see the error.
Visit https://jsfiddle.net/drag/rbhzpvn3/1/
you can set just background color instead of > content: "\2022".
it means :
input[type=radio]:checked + label:before {
background-color: #373c3e;
}

Resources