Displaying HTML elements in same row - html

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;
}

Related

Put the checkbox on the right side of the label

I want to design a series of horizontal checkboxes where the checkboxes are located on the right side of the labels.
This is what I have written where the labels are located on the left side.
.add-margin {
margin-top: 10px !important;
}
<div>
<div ng-init="loaded()" ng-class="{'add-margin': descriptionsAvailable}" class="checkbox-inline" ng-repeat="opt in options track by $index">
<label>
<input ng-disabled="answer['none']" type="checkbox" ng-model="answer[opt]" ng-true-value="true" ng-false-value="false" name="checkbox-answer-input" display= inline-block >
<span>{{opt}}</span><br/>
<span><i>{{descriptions[$index]}}</i></span>
</label>
</div>
</div>
How can I fix this?
Use the code like this
<div>
<div ng-init="loaded()" ng-class="{'add-margin': descriptionsAvailable}" class="checkbox-inline" ng-repeat="opt in options track by $index">
<label>
<span>{{opt}}</span>
<input ng-disabled="answer['none']" type="checkbox" ng-model="answer[opt]" ng-true-value="true" ng-false-value="false" name="checkbox-answer-input" display= inline-block >
<br/>
<span><i>{{descriptions[$index]}}</i></span>
</label>
</div>
</div>
If I understand your question correctly, you want the checkbox on left and the text on right with opt and description on separate rows.
You need to add some styles like following and provide relevant classes. I hope this helps.
HTML
<div>
<div ng-init="loaded()" ng-class="{'add-margin': descriptionsAvailable}" class="checkbox-inline" ng-repeat="opt in options track by $index">
<label class="container">
<input ng-disabled="answer['none']" type="checkbox" ng-model="answer[opt]" ng-true-value="true" ng-false-value="false" name="checkbox-answer-input" display= inline-block >
<div class="description">
<span>{{opt}}</span><br/>
<span><i>{{descriptions[$index]}}</i></span>
</div>
</label>
</div>
</div>
CSS
.add-margin {
margin-top: 10px !important;
}
.container {
display: flex;
flex-direction: row-reverse;
}
.description {
margin-right: 8px;
}
Here is a screenshot of how I assume you want the data to show up. If you require a different layout, then let me know

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.

How to make text closer to the input radio tag?

My css for radio input tag:
.radio-label-type {
width: 80%;
display: flex;
flex-direction: row;
justify-content: center;
}
.block-radio {
width: 50px;
}
Then, in my form, I have radio input tags:
<div class="radio-label-type">
<input class="block-radio" type="radio" name="nodeType" id="topic" value="topic" > topic </input>
<input class="block-radio" type="radio" name="nodeType" id="author" value="author" > author </input>
</div>
The 'topic' and 'author' words are next to the radio input tags, but they are at a short distance. How can I adjust their distance to make the text much closer to the radio tag?
You can achieve it using margin-right in your CSS.
Like This:
<div class="radio-label-type">
<input class="block-radio" type="radio" name="nodeType" id="topic" value="topic" > topic
<input class="block-radio" type="radio" name="nodeType" id="author" value="author" > author
</div>
.radio-label-type {
width: 80%;
display: flex;
flex-direction: row;
justify-content: center;
}
.block-radio {
width: 50px;
/* Add this to decrease the text and radio button spacing*/
margin-right: -20px;
/* To increase the distance */
/* margin-right: 20px */
}
Check out this JSFiddle
Generally input tags don't have closing tag so you should wrap with a div.
.radio-label-type {
width: 80%;
display: flex;
flex-direction: row;
justify-content: center;
}
.block-input {
margin-inline:20px ;
}
.block-input input{
margin-inline: 15px;
}
<div class="radio-label-type">
<div class="block-input"><input class="block-radio" type="radio" name="nodeType" id="topic" value="topic">topic
</div>
<div class="block-input"><input class="block-radio" type="radio" name="nodeType" id="topic" value="topic">author
</div>
</div>
You can simply target input type and set space what you want.
input[type="radio"]{
margin-right: -5px;
}
<div class="radio-label-type">
<input class="block-radio" type="radio" name="nodeType" id="topic" value="topic" > topic </input>
<input class="block-radio" type="radio" name="nodeType" id="author" value="author" > author </input>
</div>

Checkboxes aligned on row

I have multiple checkboxes and everyone is displayed on a row. I want to have 3 or 4 checkboxes on a row, but I can't do it.
Angular:
<div class="form">
<mat-label>Choose skills:</mat-label>
<div class="container">
<div *ngFor="let skill of listOfSkills; index as i" id="skills">
<input type="checkbox" (change)="getSkill($event,i)">{{skill}}
</div>
</div>
</div>
CSS:
.container input[type=checkbox]{
display:inline-block;
width: 200px;
text-align: center;
}
Base on your question, maybe I can understand as you try to align all checkbox inside a container div ? Not sure is this what you looking for ?
div{
display:flex;
align-items:center;
}
input{
margin-right:10px;
}
input:last-child{
margin-right:0px;
}
<div>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</div>
Your css sets the display property to inline-block on the input tag, but the surrounding div tag is still a block element and therefore will always wrap.
Your css should look like this:
css:
.container .checkbox {
display:inline-block;
width: 200px;
text-align: center;
}
html:
<div class="form">
<mat-label>Choose skills:</mat-label>
<div class="container">
<div *ngFor="let skill of listOfSkills; index as i" class="checkbox">
<input type="checkbox" (change)="getSkill($event,i)">{{skill}}
</div>
</div>
</div>

Changing order of flexbox when input is checked?

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>