Changing order of flexbox when input is checked? - html

I was was wondering if it's possible to change the order of my flexbox if the checkbox gets checked. I can get it to work if I don't use the form or div wrapper. Is it possibe to order the whole form container to order 4 once checkbox is checked? I am currently targeting -
input:checked+label, input:checked {
order: 4;
}
How can I add form element to the css selectors?
<div class="list__container">
<form>
<input id="item1" type="checkbox" />
<label for="item1">Create a to-do list</label>
</form>
/* Or DIV*/
<div>
<input id="item2" type="checkbox" />
<label for="item2">Prepare for <strong>the test</strong></label>
</div>
<h1 className="todo"></h1>
<h1 className="completed"></h1>
</div>
.list__container {
display: flex;
flex-direction: column;
}
.todo {
order: 1;
}
.done {
order: 2;
}
input:checked+label, input:checked {
order: 4;
}
input:not(checked)+label, input:not(checked) {
order: 2
}
Thanks!

I think this is what you want
Here my code -> https://codepen.io/jdchavarro/pen/VwjQQBW
const items = document.getElementsByClassName("item-list");
for(let item of items) {
item.onclick = () => {
item.classList.toggle("last");
};
}
.container {
display: flex;
flex-direction: column;
}
.last {
order: 1;
}
<div class="container">
<div class="item-list">
<input type="checkbox" name="item1">
<label for="item1">item1</label>
</div>
<div class="item-list">
<input type="checkbox" name="item2">
<label for="item2">item2</label>
</div>
<div class="item-list">
<input type="checkbox" name="item3">
<label for="item3">item3</label>
</div>
<div class="item-list">
<input type="checkbox" name="item4">
<label for="item4">item4</label>
</div>
</div>

Related

Show/hide content on checkbox

i want to hide all content, i want them to show when checked
like show content when checkbox checked
hide when unchecked so that when i check others they show up too
here is my try but its not working
<style>
#myBike:not(:checked) +#bike {
display: block !important;
}
#myCar:not(:checked) +#car {
display: block !important;
}
</style>
<input type="checkbox" id="myBike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="myCar">
<label for="vehicle2"> I have a car</label><br>
<div class="row" id="bike">
Something for bike
</div>
<div class="row" id="car">
Something for car
</div>
Please check the code below.
#bike {
display: none;
}
#myBike:checked~#bike {
display: block;
}
#car {
display: none;
}
#myCar:checked~#car {
display: block;
}
<input type="checkbox" id="myBike" />
<label for="vehicle1">I have a bike</label>
<input type="checkbox" id="myCar" />
<label for="vehicle2">I have a car</label>
<div class="row" id="bike">Something for bike</div>
<div class="row" id="car">Something for car</div>
Expanation:
You have used a wrong syntax ~ vs +
By default all div are set as display:block. You should set display:none as its initial.

Displaying HTML elements in same row

I am looking to achieve options as
But with current code, am getting it as below:
How to get options Yes and No next to each other
Below is my code:
For HTML
<div class="mycustom-radios">
<div class="mycustom-radios__item" *ngFor="let employeeType of employeeTypes">
<input class="mycustom-radios__input" id="e_employeetype" name="what-type-of-employee" type="radio" [value]="employeeType" [(ngModel)]="selectedemployeeType"/>
<label class="mycustom-label mycustom-radios__label" for="e_employeeType">
<p>{{employeeType}}</p>
</label>
</div>
</div>
For component.ts
selectedemployeeType: string;
employeeTypes: string[] = ['Yes', 'No'];
#Patty! Try using the display:flex CSS property, like this:
<div style="display:flex">
<div>div block 1</div>
<div>div block 2</div>
</div>
You need to apply the CSS styles like so.
// use this styling
div{
display:flex;
align-items:center;
}
input{
margin-right:5px;
}
input:last-child{
margin-right:0px;
}
<div>
<!-- nest your angular controls here -->
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</div>
Change p to span and apply display:inline as in below example. In the example I have added 2 divs to mimic *ngFor="let employeeType of employeeTypes"
.mycustom-radios__item {
display: inline-flex;
}
<div class="mycustom-radios">
<div class="mycustom-radios__item" *ngFor="let employeeType of employeeTypes">
<input class="mycustom-radios__input" id="e_employeetype" name="what-type-of-employee" type="radio" [value]="employeeType" [(ngModel)]="selectedemployeeType" />
<label class="mycustom-label mycustom-radios__label" for="e_employeeType">
<span>No</span>
</label>
</div>
<div class="mycustom-radios__item" *ngFor="let employeeType of employeeTypes">
<input class="mycustom-radios__input" id="e_employeetype" name="what-type-of-employee" type="radio" [value]="employeeType" [(ngModel)]="selectedemployeeType" />
<label class="mycustom-label mycustom-radios__label" for="e_employeeType">
<span>Yes</span>
</label>
</div>
</div>
This will do the trick:
.mycustom-radios {
display: flex;
flex-direction: row;
}
Or:
You can change display of your elements to inline-block like this:
.mycustom-radios__item {
display: inline-block;
}
If you use the flex display, make sure to add flex-wrap for smaller screens (like phones for instance):
.mycustom-radios {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}

Change the color of the icon with click toggle only in CSS

I am using this code. I would also like when it is the display: block the color of the label changes.
label.divcheck { color:blue; text-decoration:underline; }
input.divcheck { display:none; }
input.divcheck + div { display:none; }
input.divcheck:checked + div { display:block;}
<label class="divcheck" for="navigation">Button Nav</label>
<label class="divcheck" for="other">Button Other</label>
<input type="checkbox" class="divcheck" id="navigation"/>
<div class="navigation">
Foo
</div>
<input type="checkbox" class="divcheck" id="other"/>
<div class="navigation">
Other
</div>
https://stackoverflow.com/a/35781115/15949286
The only way to do this without using JavaScript is to parse the label elements and position them after the input. The example for this is as follows.
label.divcheck {
color: blue;
text-decoration: underline;
}
input.divcheck {
display: none;
}
input.divcheck~div {
display: none;
}
input.divcheck:checked~div {
display: block;
}
input.divcheck:checked~label.divcheck {
color: red;
}
section {
display: flex;
}
<section>
<div>
<input type="checkbox" class="divcheck" id="other" />
<label class="divcheck" for="other">Button Other</label>
<div class="navigation">
Foo
</div>
</div>
<div>
<input type="checkbox" class="divcheck" id="navigation" />
<label class="divcheck" for="navigation">Button Nav</label>
<div class="navigation">
Other
</div>
</div>
</section>

CSS - Align div elements in three columns

I am trying to align a list of labels, input radios and icons. The alignment should be:
Label Icon
() LongLabel Icon
() Label Icon
Here my code:
div.mygrid {
display:grid;
grid-template-columns: max-content max-content;
grid-gap:5px;
}
div.mygrid > div > label { text-align:left; }
<div class="mygrid">
<div>
<label> Long Text #1</label>
<i>Colum2</i>
</div>
<div>
<label><input type="radio">Label #2</label>
<i>Colum2</i>
</div>
<div>
<label><input type="radio">Label #3</label>
<i>Colum2</i>
</div>
</div>
Also I find awful to define spaces to replace the space of the radiobutton:
<label> Long Text #1</label>
Any idea how can I achieve that?
If you don't insist on using Grid, I propose a solution similar to the following (should be self-explanatory). Adjust values (width and padding) as needed.
label {
text-align: left;
display: inline-block;
width: 160px;
}
label.L1 {
padding-left: 30px;
}
input[type="radio"] {
width: 30px;
margin: 0;
}
i {
width: 200px;
}
<div class="mygrid">
<div>
<label class="L1">Long Text #1</label>
<i>Colum2</i>
</div>
<div>
<input type="radio"><label>Label #2</label>
<i>Colum2</i>
</div>
<div>
<input type="radio"><label>Label #3</label>
<i>Colum2</i>
</div>
</div>
div.mygrid {
display:flex;
flex-direction: column;
}
div.mygrid > div > label { text-align:left; }
.ml-3 {
margin-left: 17px;
}
<div class="mygrid">
<div class="ml-3">
<label>Long Text #1</label>
<i>Colum2</i>
</div>
<div>
<label><input type="radio">Label #2</label>
<i>Colum2</i>
</div>
<div>
<label><input type="radio">Label #3</label>
<i>Colum2</i>
</div>
</div>

How do I make the following input areas expand until the end of the screen?

This is a Bootstrap-like form:
HTML:
<div class="container">
<div class="row">
<div class="form-group row-group">
<label class="col-6">First name</label>
<input class="col-6" type="text" value=""></input>
</div>
<div class="form-group row-group">
<label class="col-6">Last name</label>
<input class="col-6" type="text" value=""></input>
</div>
</div>
<div class="row">
<div class="form-group row-group">
<label class="col-4">Message</label>
<input class="col-8" type="text" value=""></input>
</div>
</div>
<div class="row">
<div class="form-group row-group">
<label class="col-4">Message</label>
<input class="col-12" type="text" value=""></input>
</div>
<div class="form-group row-group">
<label class="col-4">Message</label>
<input class="col-12" type="text" value=""></input>
</div>
<div class="form-group row-group">
<label class="col-4">Message</label>
<input class="col-12" type="text" value=""></input>
</div>
</div>
<div class="row">
<div class="col-12 row-group">
<button class="btn">Submit</button>
</div>
</div>
</div>
CSS:
.row {
display: flex
}
.row-group {
display: flex
flex-direction: row !important
align-items: center
label {
flex: 0 0 100px
}
input {
flex: 1
}
}
.form-group {
flex: 1 0 0
flex-direction: column
}
This is the result:
I want the inputs of the first row and third row to reach the end of the container div (to not to stack horizontally with its neigbhor).
I tried this:
.row-group {
input: flex: 1 1 100%
}
But nothing moves.
What's the correct way to do this?
Please check out this Fiddle - is this what you're going for?
https://jsfiddle.net/jspruance/1p739t1h/
Here's the modified CSS:
.row {
xdisplay: flex;
}
.row-group {
display: flex;
flex-direction: row !important;
align-items: center;
}
label {
flex: 0 0 100px;
}
input {
width: 100%;
box-sizing: border-box;
flex: 1;
}
.form-group {
flex: 1 0 0;
flex-direction: column;
}
I fixed a few problems with the CSS:
1) Extra close bracket after input element
2) Missing bracket after .row-group
3) Added 'width: 100%' property and 'box-sizing: border-box'
4) Floated label left.
5) Commented out 'display: flex' on .row ( not needed)
Hope this helps.