Display all select option in single line - html

By default only one selected or the default option is displayed in the select box however I want that all the select option to be displayed on the same line and among them the selected option must be highlighted.
Following is my code
.selecttodiv{
display: inline-block;
height: 3em;
-webkit-appearance: none;
-moz-appearance: none;
}
.selecttodiv option{
display: inline-block;
width: 2.5em;
height: 2.5em;
}
<select class="selecttodiv">
<option>I</option>
<option>II</option>
<option>III</option>
<option>IV</option>
<option>V</option>
<option>VI</option>
</select>
following is the link to jsfiddle: https://jsfiddle.net/6yg4yhyy/
I am able to display all option on the single line but not when selected.
Thanks for any help.

You can try using size attribute on select and floating option.
On Chrome and FF it was displayed properly. IE (11) doesn't work.
JSFiddle
Maybe it's better to use some select plugin where you can style it as you want..

Don't style default form elements. It will cause more issues than you think. Better use some extension that provides stylable html wrapper.
E.g. select2, chosen
$(document).ready(function() {
$('.selecttodiv').select2({
width: '190px'
});
})
.select2-results li {
display: inline-block !important;
width: 30px;
text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.4/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.4/select2.min.js"></script>
<select class="selecttodiv" multiple="multiple">
<option>I</option>
<option>II</option>
<option>III</option>
<option>IV</option>
<option>V</option>
<option>VI</option>
</select>
Update
Also it may be checkboxes:
.check {
display: inline-block;
}
span {
width: 20px;
height: 20px;
display: block;
color: black;
font-weight: bold;
cursor: pointer;
text-align: center;
}
input {
display: none;
}
input:checked + span {
background-color: blue;
color: white;
}
<label class="check">
<input type="checkbox" />
<span>I</span>
</label>
<label class="check">
<input type="checkbox" />
<span>II</span>
</label>
<label class="check">
<input type="checkbox" />
<span>III</span>
</label>
<label class="check">
<input type="checkbox" />
<span>IV</span>
</label>
<label class="check">
<input type="checkbox" />
<span>V</span>
</label>
<label class="check">
<input type="checkbox" />
<span>VI</span>
</label>

Related

Moving input radio buttons with CSS

I wish to move my radiobuttons under each of the selections. Radiobutton "test1" under the first selection and radiobutton "test2" under the second selection. That is, the radiobuttons are below the selection, but next to each other.
How do I do that? I do not wish to use tables or br. I would like to use CSS; how should I style my CSS?
<form name="test">
<label style="float:left;">test</label>
<input style="display:block" />
<label style="float:left;">test</label>
<input style="display:block" />
<label style="float:left;">test</label>
<select>
<option>1</option>
<option>2</option>
</select>
<select>
<option>a</option>
<option>b</option>
</select>
<input type="radio" name="test" value="test1">
<input type="radio" name="test" value="test2">
</form>
If I add more than one radio box:
I tried using + (adjacent sibling selector) in CSS, but I think it is because the position is absolute. So the next "children" won't align horizontally. I think this is the easiest/"neat" way of doing it.
So I tried to position it relatively (the first radio box) and float:left. But it positions itself too high.
Here is each radio button underneath each select element using only CSS without changing your HTML.
form {
display: block;
position: relative;
padding-bottom: 30px;
}
input[type="radio"] {
display: inline-block;
position: absolute;
bottom: 0;
left: 30px;
}
input[type="radio"]:last-child {
left: 70px;
}
JSFiddle Demo: https://jsfiddle.net/3w16q179/1/
More than 2 radio buttons:
JSFiddle Demo: https://jsfiddle.net/3w16q179/6/
This will align the radio buttons below the select inputs, regardless of width of their widths.
input[type="radio"] {
display: block;
}
<form name="test">
<label style="float:left;">test</label>
<input style="display:block" />
<label style="float:left;">test</label>
<input style="display:block" />
<label style="float:left;">test</label>
<div style="float:left;">
<select>
<option>1</option>
<option>2</option>
</select>
<input type="radio">
</div>
<div style="float:left;">
<select>
<option>2</option>
<option>3</option>
</select>
<input type="radio">
</div>
</form>
AHA! I just figured it out what you're looking for... Each radio button is centered under the select. I got it.
<!doctype html>
<html>
<style type = "text/css">
form * {
box-sizing: border-box;
}
form {
background: White;
width: 420px;
padding: 8px;
border: 1px solid grey;
}
fieldset {
text-align: center;
border: 0;
padding: 0;
}
label {
width: 33.33%;
float: right;
padding: 6px;
}
legend {
display: block;
float: left;
width: 33.33%;
margin: 0;
}
</style>
<form name="test">
<fieldset>
<label>
<select>
<option>a</option>
<option>b</option>
</select>
</label>
<label>
<select>
<option>a longer ooption</option>
<option>b</option>
</select>
</label>
</fieldset>
<fieldset>
<label>
<input type="radio" name="radio">
</label>
<label>
<input type="radio" name="radio">
</label>
<legend>
Choose One:
</legend>
</fieldset>
</form>
</html>
jsFiddle: https://jsfiddle.net/3jbqjj0f/
You can use display: block or display: inherit;.
input[type="radio"] {
display: block;
}
JSFiddle
Though your question is not that clear, I think you can use class. Just add any class to the input you want to move.
For example:
HTML
<input type="radio" class="myinput" />
CSS
input.myinput {
display:block;
margin-top:20px; /* For top spacing */
}
I hope that helps!

Radio Button CSS3 - Customization

I am trying to customize Radio buttons on bootstrap but it is not working, When i try outside bootstrap environment in plain HTML it works, Below is code for HTML followed by CSS I am using
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
My Current AMP Policies
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
Financial Planning and Retirement Advice
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios3" value="option3">
LifeCover
</label>
</div>
THE CSS
.newradio input[type=radio] {display: none;}
.newradio label {
display: inline-block;
cursor: pointer;
position: relative;
padding-left: 25px;
margin-right: 15px;
font-size: 13px;
}
.newradio label:before {
content: "";
display: inline-block;
width: 14px;
height: 14px;
border-radius: 7px;
margin-right: 10px;
position: absolute;
left: 0;
bottom: 3px;
background-color: #fff;
border:solid 1px #bcb882;
}
.newradio input[type=radio]:checked + .newradio label:before {
content: "";
background: url(../../Content/images/radio-check.png);
display: inline-block;
}
The reason for .newradio is I am using that div as parent class of above given HTML, I am getting proper display of my Radios but Checked status (the image radio-check) is not showing, I tried using color change instead of background image but that doesn't work either.
Does anyone has experience in customizing radio button in bootstrap? please guide
Manoj Soni
You need to find the bootstrap css class and overwrite it. Or use ID instead of class in the css. When that also don't work try !important.

How to make (custom) radio buttons work in CSS3

I've been trying to make custom radio buttons work. I had been using check boxes but found that I needed to restrict the checked options to one. I've been looking at examples/tutorials that I found using Google and thought I understood enough for a simple set of 4 radio buttons but ...
They display correctly initially with the first button checked but checking on other buttons just displays the checked PNG: a previously checked button does not revert to unchecked state.
The buttons are arranged sequentially horizontally in their own div.
HTML
<div class='radio'>
<input id='B12' type='radio' class='radiobutton' checked>
<label id='lblB12' class='radiobutton-label' for='B12'>IR </label>
<input id='BBW' type='radio' class='radiobutton' >
<label id='lblBBW' class='radiobutton-label' for='BBW'>Wide</label>
<input id='B10' type='radio' class='radiobutton' >
<label id='lblB10' class='radiobutton-label' for='B10'>B10</label>
<input id='B8' type='radio' class='radiobutton' >
<label id='lblB8' class='radiobutton-label' for='B8'>B8 </label>
</div>
CSS3
.radiobutton-label {
display: inline-block;
cursor: pointer;
position: relative;
padding-left: 25px;
margin-right: 15px;
font-size: 15px;
}
input[type="radio"] {
display: none;
margin: 10px;
}
.radiobutton-label:before {
content:"";
display: inline-block;
width: 24px;
height: 24px;
margin-right: 10px;
position: absolute;
left: 0;
bottombottom: 1px;
background: url(resources/CheckBoxUnchecked.png) left top;
}
input[type=radio]: + label:before {
background: url(resources/CheckBoxUnchecked.png) left top;
}
input[type=radio]:checked + label:before {
background: url(resources/CheckBoxOK.png) left top;
}
This is the first web page that I have attempted.
Relevant Spec - 17 Forms / 17.2.1 Control types
Radio buttons are like checkboxes except that when several share the same control name, they are mutually exclusive: when one is switched "on", all others with the same name are switched "off".
Therefore if you want the radio elements to be mutually exclusive, just give them all the same name attribute. In this instance, I just used name="checkboxes".
Updated HTML EXAMPLE HERE
<div class='radio'>
<input id='B12' type='radio' class='radiobutton' name="checkboxes" checked="checked"/>
<label id='lblB12' class='radiobutton-label' for='B12'>IR </label>
<input id='BBW' type='radio' class='radiobutton' name="checkboxes"/>
<label id='lblBBW' class='radiobutton-label' for='BBW'>Wide</label>
<input id='B10' type='radio' class='radiobutton' name="checkboxes"/>
<label id='lblB10' class='radiobutton-label' for='B10'>B10</label>
<input id='B8' type='radio' class='radiobutton' name="checkboxes"/>
<label id='lblB8' class='radiobutton-label' for='B8'>B8 </label>
</div>
Base CSS:
input[type=radio] + label:before {
background: url('http://www.csscheckbox.com/checkboxes/vlad.png') 2px 4px no-repeat;
}
input[type=radio]:checked + label:before {
background: url('http://www.csscheckbox.com/checkboxes/vlad.png') 2px -18px no-repeat;
}

Why can't I tab into CSS3 checkboxes?

I've been following tutorial on styling checkboxes using only CSS3 and here's what I came up with:
DEMO:
http://cssdeck.com/labs/jaoe0azx
Checkboxes are styled just fine - but when I tab through form controls -> checkbox is being skipped. Any advice why?
HTML:
<form role="form" id="login_form" data-mode="login">
<div class="form-group">
<label for="ue">Username or email:</label>
<input type="email" class="form-control input-lg" name="ue" id="ue" placeholder="" />
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control input-lg" name="password" id="password" placeholder="" />
</div>
<div>
<input id="rememberme" type="checkbox" name="rememberme" value="1" class="checkbox_1" tabindex="0" />
<label for="rememberme" class="checkbox_1" tabindex="0">remember me</label>
</div>
<div id="auth_area_login_button">
<button class = "btn btn-lg btn-primary">
Login
</button>
</div>
</form>
CSS:
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css');
#login_form{padding:20px;}
label.checkbox_1 {
display: inline-block;
cursor: pointer;
position: relative;
padding-left: 25px;
margin: 0px;
}
label.checkbox_1:before {
content: "";
display: inline-block;
width: 16px;
height: 16px;
margin-right: 10px;
position: absolute;
left: 0;
bottom: 1px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 0px;
}
label.checkbox_1:hover:before{border-color:#66afe9;}
input[type=checkbox].checkbox_1 {
display: none;
}
input[type=checkbox].checkbox_1:checked + label.checkbox_1:before {
content: "\2713";
font-size: 15px;
color: #A0A0A0;
text-align: center;
line-height: 15px;
}
EDIT 1:
seems to work in firefox, but not in chrome...
Input must be accessible to receive focus. It works in chrome/chromium if you add following lines.
input[type=checkbox].checkbox_1 {
opacity: 0;
}
input[type=checkbox].checkbox_1:focus + label.checkbox_1:before {
border: 1px solid #66afe9;
}
Since the real checkbox is hide with display:none you can't focus it but you can also don't hide the element just make it be under the :before of the label:
input[type=checkbox].checkbox_1 {
position: absolute;
width: 16px;
height: 16px;
margin: 0;
border: 1px solid transparent;
margin-top: 3px;
}
Check this http://cssdeck.com/labs/pl4ljry7
Tested in Chrome
Because, it is not a checkbox.
Look at the css:
input[type=checkbox].checkbox_1 {
display: none;
}
The checkbox is actually hidden. So, you will not be able to focus it. The stylized square and checkmark shown are through the :before pseudo element on label. Pseudo-elements can't be focused. Nor can the labels.
I know this is an old question, but I came up with a Jquery solution when the CSS solution didn't work for me, and thought others might find this helpful. I wrapped the input in a div with the desired tabindex value and the class "checkbox-add-tabindex". Then, using Jquery, I transferred the tabindex from the div to the input.
HTML:
<div class="checkbox-add-tabindex" tabindex="10">
<input id="rememberme" type="checkbox" name="rememberme" value="1" class="checkbox_1" tabindex="0" />
<label for="rememberme" class="checkbox_1" tabindex="0">remember me</label>
</div>
Jquery:
$(".checkbox-add-tabindex").focus(
function () {
var tabval = $(this).prop("tabindex");
$(this).removeAttr("tabindex");
$(this).children(":first").attr("tabindex", tabval);
$(this).children(":first").focus();
})

How can I make multi-line, vertically and horizontally aligned labels for radio buttons in HTML Forms with CSS?

Assuming the following markup:
<fieldset>
<legend>Radio Buttons</legend>
<ol>
<li>
<input type="radio" id="x">
<label for="x"><!-- Insert multi-line markup here --></label>
</li>
<li>
<input type="radio" id="x">
<label for="x"><!-- Insert multi-line markup here --></label>
</li>
</ol>
</fieldset>
How do I style radio button labels so that they look like the following in most browsers (IE6+, FF, Safari, Chrome:
I believe this does it all. You didn't mention that it has to validate, however, so I used the inline-block (-moz-inline-box) display. One of my favorites, actually.
Here's a working copy
Tested in Safari 3, FireFox 3, and IE7.
<style type="text/css">
ol{
padding-left: 0;
margin-left:0;
}
ol>li {
list-style-type: none;
margin-bottom: .5em;
}
ol>li input[type=radio] {
display: -moz-inline-box;
display: inline-block;
vertical-align: middle;
}
ol>li label {
display: -moz-inline-box;
display: inline-block;
vertical-align: middle;
}
</style>
Using the following markup and css I was able to produce multi-line labels that do not wrap under the radio button:
<style type="text/css">
fieldset input, label {
float: left;
display: block;
}
fieldset li {
clear: both;
}
</style>
<fieldset>
<ol>
<li>
<input type="radio" id="x" />
<label for="x">
stuff<br/>
stuff1
</label>
</li>
<li>
<input type="radio" id="x" />
<label for="x">
stuff<br/>
stuff1
</label>
</li>
</ol>
</fieldset>
however I was unable to use:
fieldset label {
vertical-align: middle;
}
to center the label vertically on the radio button, even when applying a width (both suggestions in Dmitri Farkov's answer. My main purpose was to prevent wrapping under the radio button, so this solution will be fine for the time being.
Since I asked how to handle really long labels above, and I finally solved it myself. Here is the solution to my problem. Maybe it could help you to?
<style type="text/css">
#master_frame {
background: #BBB;
height: 300px;
width: 300px;
}
fieldset.radios {
border: none;
}
fieldset fields {
clear: both;
}
input {
float: left;
display: block;
}
label {
position: relative;
margin-left: 30px;
display: block;
}
</style>
<div id="master_frame">
<fieldset class='radios'>
<div class='field'>
<input type="radio" id="a" />
<label for="a">Short</label>
</div>
<div class='field'>
<input type="radio" id="b" />
<label for="b">
A really long and massive text that does not fit on one row!
</label>
</div>
</fieldset>
</div>
Make input and label both
float: left;
display: block;
Set width's for the label and input.
apply
clear: both;
vertical-align: middle;
to all the li's.
You should use white-space: normal; in label for multiline