Change line spacing from <br> to other line spacing methods in css - css

I am writing an HTML5 page at the moment, I'm having an issue switching format from using br for line spacing to line-height, padding, or margin (whichever is easier). Everything is inside of a form and fieldset tag I do not want every line to be on their own, just some. Some text I do want next to each other because I am making a form that has radio buttons and check boxes. But instead of using br tags how I can switch that out to line-height, padding, or margin in css.
<form>
<fieldset class = "top">
Please Select a car: <br>
<input type="radio" name="car" value="truck">truck
<input type="radio" name="car" value="van">van
<input type="radio" name="car" value="suv">suv<br>
<input type="radio" name="car" value="coupe">coupe
<br>
<br>
<input type="checkbox" name="color" value="Blue">Blue
<input type="checkbox" name="color" value="red">red
<br>
<br>
<input type="checkbox" name="color" value="Orange">Orange
<input type="checkbox" name="color" value="black">Black
<br>
<br>
<input type="checkbox" name="color" value="Green">green
<input type="checkbox" name="color" value="brown">brown
<br>
<br>
....

Try to use a fieldset for each group of radios so you can control them more precisely, put margin only around your group and etc.
You can use labels and span around the label/input groups, so you can control them better.
<span>
<label for="name">Value</label>
<input type="checkbox" name="name" value="1"/>
</span>
Also if you use a class specific for your input, you can make it display in block, like this:
input.block {
display: block;
}
then if you put this class block on your input the label will stay in another line...
For a bigger picture see this fiddle:
http://jsfiddle.net/BxwNL/1/
Update: another solution according to cinnamon comment
You can also use a list for your items, but it would make sense if you grouped them according to their properties, like a list for the colours, a list for the types...
The usage would be like:
<ul>
<li>
<label for="name">Value</label>
<input type="checkbox" name="name" value="1"/>
</li>
<li>
<label for="name2">Value2</label>
<input type="checkbox" name="name2" value="2"/>
</li>
</ul>
Fiddle example for the list solution:
http://jsfiddle.net/BxwNL/2/

Related

checkbox, select, radio require bootstrap 4

I would like to know how to include a require for different element like checkbox, select ... not alone but inside a group element
I tried this, but it doesn't seem to work as expected
<div class="form-group aria-required="true">
<div class="radio">
<ul class="list-unstyled">
<li>
<input type="radio" name="radio1">
<input type="radio" name="radio2">
<input type="radio" name="radio3">
</li>
</ul>
</div>
</div>
The aria-required attribute is used to indicate that user input is required on an element before a form can be submitted. This attribute can be used with any typical HTML form element; it is not limited to elements that have an ARIA role assigned.
HTML5 now has the required attribute, but aria-required is still useful for user agents that do not yet support HTML5.
Used in ARIA roles
Combobox
Gridcell
Listbox
Radiogroup
Spinbutton
Textbox
Tree
A simple form
<form action="post">
<label for="firstName">First name:</label>
<input id="firstName" type="text" aria-required="true" />
<br/>
<label for="lastName">Last name:</label>
<input id="lastName" type="text" aria-required="true" />
<br/>
<label for="streetAddress">Street address:</label>
<input id="streetAddress" type="text" />
</form>
Working Examples:
Link

Bootstrap - Layout of Radio Buttons

I have a webpage that uses Bootstrap 3. In this page, I have some radio buttons. Some of them have short labels. Some have longer labels. I'd like to format my radio buttons so that they render like this:
+------------------------------------------------------+
| o Choice 1 |
| |
| o Choice 2. This is a longer label that should |
| wrap. Notice how the wrap does not happen under |
| the radio button. Rather the text is justified |
| |
| o Choice 3 |
+------------------------------------------------------+
In an attempt to do this, I decided to use display:inline-block;, but that's not working. I'd really like to use inline-flex. However, I can't use that because of my target browsers. So, I tried mimicing this functionality using straight HTML. I've created that in this Bootply. Yet, the wrapping behavior is still incorrect. My HTML looks like this:
<div class="container">
<div id="myChoices">
<label class="choice">
<input id="SelectedStation" name="SelectedStation" type="radio" value="1">
<span class="outer"><span class="inner"></span></span>
<p>ABC</p>
</label>
<br>
<label class="choice">
<input id="SelectedStation" name="SelectedStation" type="radio" value="2">
<span class="outer"><span class="inner"></span></span>
<p>CBS</p></label>
<br>
<label class="choice">
<input id="SelectedStation" name="SelectedStation" type="radio" value="3">
<span class="outer"><span class="inner"></span></span>
<p> This is a longer label that should wrap. Notice how the wrap does not happen under the radio button. Rather the text is justified</p>
</label>
<br>
<label class="choice">
<input id="SelectedStation" name="SelectedStation" type="radio" value="4">
<span class="outer"><span class="inner"></span></span>
<p>NBC</p>
</label>
<br>
</div>
</div>
What did I do wrong? Why is a) the label appearing on the line below the radio button and b) why isn't the text wrapping inline with the label?
Thank you
Firstly, you can't use the same id more than once in a single page; so use a .SelectedStation class instead.
Secondly, you can use relative positioning on .choice, absolute positioning on .SelectedStation and apply some left padding to your <p>s.
.choice {
position: relative;
display: block;
}
.SelectedStation {
position: absolute;
top: 0;
left: 0;
}
.choice p {
padding-left: 22px;
}
<div class="container">
<div id="myChoices">
<label class="choice">
<input class="SelectedStation" name="SelectedStation" type="radio" value="1">
<span class="outer"><span class="inner"></span></span>
<p>ABC</p>
</label>
<br>
<label class="choice">
<input class="SelectedStation" name="SelectedStation" type="radio" value="2">
<span class="outer"><span class="inner"></span></span>
<p>CBS</p>
</label>
<br>
<label class="choice">
<input class="SelectedStation" name="SelectedStation" type="radio" value="3">
<span class="outer"><span class="inner"></span></span>
<p>This is a longer label that should wrap. Notice how the wrap does not happen under the radio button. Rather the text is justified</p>
</label>
<br>
<label class="choice">
<input class="SelectedStation" name="SelectedStation" type="radio" value="4">
<span class="outer"><span class="inner"></span></span>
<p>NBC</p>
</label>
<br>
</div>
</div>
#myChoices p {
display: inline-block;
}
p tag is block element, now we changed to inline-block,
as you are using bootstrap, you can use following classes to fix the wrap issue
add col-xs-12 class to #myChoices div tag
add col-xs-2 class to all span.outer tags
add col-xs-10 class to p tag, if p tag is not possible wrap p tag in div
Example codepen

Bootstrap - Layout spacing breaks for group of checkboxes when changing visiblity

I have the following scenario using Bootstrap.
The problem is that when I change the visibility of the first checkbox, it kinda breaks the spacing of the layout.
<label for="">Filter</label>
<div class="checkbox">
<label>
<input type="checkbox"> Filter 1
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Filter 2
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Filter 3
</label>
</div>
You can test in this CodePen it by clicking on the button.
Did I build badly the HTML? Or am I missing some feature here
The margin-top for .checkbox+.checkbox is set for -5px, this rule applies, regardless of if the first checkbox is visible or not. Better solution would be to add the margin to the text above (which should be no label!) and don't set different margins for the different checkbox-classes.
<p>Filter</p>
<ul class="checkbox list-unstyled">
<li> <label> <input type="checkbox"> Filter 1</label> </li>
<li> <label> <input type="checkbox"> Filter 2</label> </li>
</ul>
You would need to change your JS to $(".checkbox li").first().toggleClass('hidden')

inline form parts using CSS (inline attribute)?

I want to create a simple form. The final design should be the one above, but with a responsive positioning.
So I tried to use the inline attribute of css:
<!--Name...-->
<div style="display: inline;">
<label for="vorname_patient">Vorname: </label> <br> <input type="text" name="vorname_patient" id="vorname_patient" required="" size="20" autofocus=""> <br>
<label for="nachname_patient">Nachname: </label> <br> <input type="text" name="nachname_patient" id="nachname_patient" required="" size="20">
</div>
<!--Anrede...-->
<div style="display: inline;">
<label for=anrede_patient">Anrede: </label> <br> <input type="text" name="anrede_patient" id="anrede_patient" size="20">
</div>
If i run that i will not get any inlineme parts anywhere.
i want to get this (without a table):
https://jsfiddle.net/kcd1qr1r/
What did I do wrong here? Thank you!
Inline elements must flow within their nearest block parent. So, because you changed the div containers to be inline, your label and input elements are just flowing within the body (nearest block parent). Use inline-block instead or, due to possible margin issues with that approach, you may want to try flexboxes.

CSS: how to make label appear right of the radio?

Say I have the following mark up:
<label for="name">Name:</label>
<input type="radio" name="name" id="name"/>
The order of the tags appear to be proper to me (in a semantic sense: label before the thing you're labeling). But I want to display this as radio button first, followed by the label. How can I do that in CSS?
You don't need CSS. Wrap your input in a label and put the text last.
<label><input type="radio" name="name" id="name"/>Name:</label>
Is that still semantic for you?
Or you could try the float.
Tag order in this case doesn't matter. And even if it did, then it would be the other way around - first you would have to create the radio button, and then reference it in the label.
To answer your question: just do it in the order you want to display it
<input type="radio" name="name" id="name"/>
<label for="name">Name:</label>
fiddle http://jsfiddle.net/Jm2JR/1/..
write like this:
input{
float:left;
}
Check this http://jsfiddle.net/3cLRg/
<label for="name" style="float:right;">Name:</label>
try this:
<label style="position:relative; left:100px;" for="name">Name:</label>
<input type="radio" name="name" id="name"/>
2nd approach is :
<input type="radio" name="name" id="name"/>
<label for="name">Name:</label>
Hi you just define your input tag as like that
<label>Name:
<input type="radio" name="name" id="name"/></label>
<br />
<label>
<input type="radio" name="name" id="name"/> Name
</label>
​
Live demo http://jsfiddle.net/rohitazad/bhBQn/1/

Resources