Good morning,
I'm developing a web application and I need an horizontal input that lets the user select a value, but radio buttons are not an option.
I thought about using a input with range type, but this is not supported in IE 8 or 9.
Is there any way to show select options horizontally that works both in chrome and IE?
My html code is:
<select size="4">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
It currently looks like this:
Is there any way to make the options show side by side? I tried adding inline-block display to the options, but nothing changes.
--- EDIT ---
I don't want to use radio buttons because I'm using js to create new items which the user can also select and with radio buttons I have to change the button names manually.
Is this what you're after?
select {
display:table-row;
}
option {
display:table-cell;
}
http://jsfiddle.net/rjmnmcru/
Your best bet is probably to use either checkboxes, or an unordered list with links:
<style type="text/css">
ul.selections { list-style:none; }
ul.selections li {display: inline; list-style-type: none; padding-right: 20px;}
div.selections input { margin-left:15px;}
div.selections input.first { margin-left:20px; }
</style>
<div class="selections">
<input type="checkbox" value="volvo" class="first"/> Volvo
<input type="checkbox" value="saab"/> Saab
<input type="checkbox" value="mercedes"/> Mercedes
<input type="checkbox" value="audi"/> Audi
</div>
<ul class="selections" >
<li>Volvo</li>
<li>Saab</li>
<li>Mercedes</li>
<li>Audi</li>
</ul>
you can use the links or onchecked of the checkboxes to fire JS events. To make it clear to the end user, you can add a "highlight" class to the elements from the JS event, and change the background colors as necessary.
I realize you've already accepted an answer, however this works too.
You can customize anything you want in it, including borders, background colours, etc.
HTML
<div class="container"><span class="user">User 1</span>
<div class="selectOptions">
<div class="myOptions">
<div class="option volvo">Volvo</div>
<div class="option saab">Saab</div>
<div class="option mercedes">Mercedes</div>
<div class="option audi">Audi</div>
</div>
<div class="select user1">User 1</div>
</div>
</div>
CSS
.container {
overflow:hidden;
background-color:#ddd;
padding:5px;
padding-bottom:7px;
}
.user {
float:left;
background-color:#ddd;
margin-top:2px;
padding:5px;
}
.user:after {
content:":";
}
.selectOptions {
float:left;
margin-left:5px;
}
.select {
border:2px solid #333;
padding:5px;
text-align:center;
position:absolute;
background-color:#ddd;
}
.select:hover {
background-color:grey;
cursor:pointer;
}
.myOptions {
position:absolute;
top:45px;
/*42px (height of .select + (padding*2) minus border thickness*/
border:2px solid #333;
display:none;
background-color:#ddd;
}
.option {
display:inline-block;
padding:5px;
}
.option:not(:first-of-type) {
margin-left:-5px;
}
.option:hover {
background-color:#123456;
cursor:pointer;
}
JS
$(".select").hover(function () {
$(this).siblings(".myOptions").css("display", "block");
$(this).css("background-color", "grey");
}, function () {
$(this).siblings(".myOptions").css("display", "none");
});
$(".myOptions").hover(function () {
$(this).css("display", "block");
}, function () {
$(this).css("display", "none");
$(this).siblings(".select").css("background-color", "#ddd");
});
$(".option").hover(function () {
$(this).css("background-color", "#123456");
}, function () {
$(this).css("background-color", "#ddd");
var selection = $(this).html();
if (selection == $(this).parent().siblings(".select").html()) $(this).css("background-color", "grey");
});
$(".option").click(function () {
var selection = $(this).html();
$(this).parent().siblings(".select").html(selection);
$(this).siblings().css("background-color", "#ddd");
$(this).css("background-color", "grey");
});
Related
As described in the image,
I would like to make the textbox like this.
I have tried it using min max but it is not working.
<div>
<input type="number" name="quantity" min="1" max="5" placeholder="Number"><br>
</div>
How can i make it like in the image?
Any help would be great.
Thank You.
Try with this i have added custom colors , you can replace it with icons
$(function(){
$('#up').on('click', function(){
var value = $('#value').val();
if(value == 5){
return false;
}
value++;
$('#value').val(value);
});
$('#down').on('click', function(ev){
var value = $('#value').val();
if(value == 0){
return false;
}
value--;
$('#value').val(value);
});
});
.relative {
position:relative;
width:280px;
}
input {
width:100%;
display:inline-block;
border:2px solid #E5E4E4;
appearance:none;
padding:5px 0 5px 5px;
}
#up {
width:25px;
height:17px;
position:absolute;
right:0;
top:0;
background:#096;
border:none;
}
#down {
width:25px;
height:17px;
position:absolute;
right:0;
bottom:0;
background:#06C;
border:none;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin: 0;
}
input[type=number] {
-moz-appearance:textfield;
}
<div class="relative">
<input type="number" name="quantity" id="value" placeholder="Amount Request (low to heigh)">
<button id="up"></button>
<button id="down"></button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
Just remove min and max attribute it will run automatically..
Please try i think you need same like this:
<div>
<input type="number" name="quantity" placeholder="Amount request (low to high) " style="width:250px;"><br>
</div>
I am really confuded in this. I have a label and select drop-down inside my container which is right aligned.
GOAL
Container should act like a drop-down. Only sort-by label should be displayed initially.When user clicks on it, it should shoe the option to the user.
Problem
I don't know how to trigger drop down when i click on the sort by label.
<div class="container">
<label class="Sortlabel">Sort by</label>
<select>
<option>2</option>
<option>22</option>
<option>222</option>
</select>
</div>
If i must use jquery or JS, i ll add these tags also. Any suggestions??
And what is the difference with this one : http://jsfiddle.net/csdtesting/vuc81u87/
Result is the same.
<div class="container">
<label class="Sortlabel"></label>
<select>
<option>Sort by</option>
<option>22</option>
<option>222</option>
</select>
</div>
select
{
width:100%;
-webkit-appearance: none;
}
.container
{
float: right;
width:190px;
}
But if you insists.I took this idea
and here it is (Pure Javascript): http://jsfiddle.net/csdtesting/ybjdsqrx/
var state = false;
// <select> element displays its options on mousedown, not click.
showDropdown = function(element) {
var event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
element.dispatchEvent(event);
};
// This isn't magic.
window.runThis = function() {
var dropdown = document.getElementById('sel');
showDropdown(dropdown);
};
select {
-webkit-appearance: none;
border: none;
width: 70%;
}
.container {
width: 100%;
float: left;
width: 190px;
border: 1px solid;
}
.Sortlabel {
width: 20%;
}
}
<div class="container">
<label class="Sortlabel" onclick="runThis()">Sort by</label>
<select id="sel">
<option></option>
<option>2</option>
<option>22</option>
<option>222</option>
</select>
</div>
I want a way (ideally just using CSS HTML) where when I click on Question, the text shows and remains there. Then if they click on text again, it will revert back to question.
It works on hover, but I don't know how to make it on click. HTML:
<div id="packagequestioninfo">
<p class="packagereplies">Question</p>
<p class="packagecomment">If you require <b>hosting</b> for your website, select your primary website and go to <b>Part II</b>. If you do not require hosting, please Checkout below. </p>
</div>
CSS:
#packagequestioninfo {
padding: 10px;
background: #F2F7FA;
border-radius: 0px;
-moz-box-shadow: 0 0 5px #ccc;
-webkit-box-shadow: 0 0 5px #ccc;
box-shadow: 0 0 5px #ccc;
}
#packagequestioninfo:hover {
background-image:url(../img/index/body/ourproducts/light_blue_background_pattern.jpg);
background-repeat:repeat;
cursor: none;
}
#packagequestioninfo .packagecomment {
display: none;
}
#packagequestioninfo:hover .packagereplies {
display: none;
}
#packagequestioninfo:hover .packagecomment {
display: inline;
}
Here is the code http://jsfiddle.net/53UK2/
Make .packagecomment invinsible with css, then use jQuery:
$('p').click(function(){
$('p').toggle();
});
Fiddle: http://fiddle.jshell.net/RcTGN/
If you do not need IE8 and lower support you can do it with pure CSS like this.
This is because of the ":checked" css selector. See support here.
The HTML:
<div class="question">
<input type="checkbox" class="qestion-checkbox" id="q1" />
<label for="q1" class="qestion-text">Question 1 text</label>
<label for="q1" class="qestion-answer">Question 1 answer</label>
</div>
<div class="question">
<input type="checkbox" class="qestion-checkbox" id="q2" />
<label for="q2" class="qestion-text">Question 2 text</label>
<label for="q2" class="qestion-answer">Question 2 answer</label>
</div>
The CSS:
.qestion-answer, .qestion-checkbox {
display: none;
}
.qestion-checkbox:checked + .qestion-text {
display:none;
}
.qestion-checkbox:checked + .qestion-text + .qestion-answer {
display:block;
}
If you do need IE8 and lower support you need to use some javascript/jQuery
It's impossible using only css. Of course you can change :hover instead :active, but it will be work when the mouse button is held down.
Check it.
Why don't you want use jquery? It will be easier.
Non-jquery way...
Just showing and hiding by changing the display style attribute:
HTML:
<script src="javascriptfile.js"></script>
<div id="packagequestioninfo">
<p class="packagereplies">Question</p>
<p class="packagecomment">If you require <b>hosting</b> for your website, select your primary website and go to <b>Part II</b>. If you do not require hosting, please Checkout below. </p>
</div>
javascriptfile.js:
// Wait for the entire window elements to be loaded
window.onload = function() {
document.addEventListener('packagequestioninfo').addEventListener('onclick', function() {
if(document.getElementById('packagecomment').style.display !== 'none') {
document.getElementById('packagecomment').style.display = 'none';
} else {
document.getElementById('packagecomment').style.display = 'block';
}
});
}
or if you'd like to go with the class toggling method:
window.onload = function() {
document.addEventListener('packagequestioninfo').addEventListener('onclick', function() {
if(document.getElementById('packagecomment').className.indexOf('show')) {
document.getElementById('packagecomment').className = '';
} else {
document.getElementById('packagecomment').className = 'show';
}
});
}
in this approach you'll need to add a class to your CSS:
.show{
display:block;
}
By default when you check a checkbox it will put a tick in the box. I'm trying to change that to a solid color weather it be a css background or an image upon check. http://bootply.com/71996
<label class="checkbox">
<input type="checkbox" value="">
Content
</label>
I've searched and read a few answers on here but nothing conclusive and simple.
Look at your updated code.
HTML:
<label class="checkbox">
<input value="" type="checkbox">
Content
</label>
JavaScript:
$("input[type=checkbox]").on("change", function() {
var $chk = $(this);
var isChecked = $chk.prop('checked');
if (isChecked) {
$chk.parent().addClass("checked");
}
else {
$chk.parent().removeClass("checked");
}
});
CSS:
.checkbox { color:blue; }
.checkbox:before { content:""; background-color:blue; width:15px; height:18px; display:block; position:absolute; margin-left:-20px; }
.checkbox.checked { color:red; }
.checkbox.checked:before { background-color:red; }
Note:
The JavaScript can be simplified but I intentionally check at the value (and not use .toggleClass()) each time it changed.
I tried your script but it isn't working right. I have edited my code below to show exactly what I am working with. Thank you so much for being helpful.
Quazi
Hi,
I am very new to JQuery.
I am trying to get a div to fade in after a click event and then hide after click anywhere. I have three divs set up to do this with css set as display:none. The problem is that the script does not work in IE8 and only works in ff/safari if I double click or triple click the menubar links below.
I am using the following code to show/hide these divs on mouse click:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
body,
html {
margin:0;
padding:0;
color:black;
background:black;
color:black;
}
#logo {
margin-top:1%;
width:12%;
margin-left:5%;
padding:1%;
border:2px solid #FF8c00;
}
#showsbanner {
margin-top:1%;
width:60%;
position:absolute;
right:2px;
}
#wrap {
width:90%;
margin:0 auto;
background:black;
color:black;
}
#header {
padding:5px 10px;
background:black;
color:#ef9c00;
}
h1 {
color:#35002c;
font-family:"verdana";
font-size:25px;
}
h2 {
color:#044476;
font-family:"verdana";
font-size:18px;
}
h3 {
color:#044476;
font-family:"verdana";
font-size:15px;
}
#nav {
padding:5px 10px;
width:89%;
margin-left:5%;
background:#ff8c00;
border:2px solid darkblue;
}
#nav ul {
margin:0;
padding:0;
list-style:none;
}
#nav li {
display:inline;
margin:0;
padding:0;
color:white;
}
#menubar {
float:left;
width:40%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#bcity {
float:right;
width:50%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#aicbk {
display:none;
float:right;
width:50%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#pdil{
display:none;
float:right;
width:50%;
padding:1%;
background:#ff8c00;
margin-bottom:1%;
border:2px solid darkblue;
}
#footer {
clear:both;
padding:1px, 1px;
background:#ff8c00;
width:100%;
border:2px solid darkblue;
}
#footer p {
color:white;
font-size:12px
}
* html #footer {
height:1px;
}
//The last four lines are an IE bug fix
</style>
<script type="text/javascript" src="homepage_files/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var gLastH = null;
var gLastId = null;
$('.toggleh').hide();
$('.toggle').click(function(e) {
$('.toggleh:visible').fadeOut('slow');
gLastId = $(this).attr('id');
console.log('#' + gLastId + 'h');
gLastH = $('#' + gLastId + 'h');
$(gLastH).fadeIn('slow');
e.stopPropagation();
});
$('*').click(function(e) {
if ($(this).attr('id') != gLastId) {
$(gLastH).fadeOut('slow');
}
e.stopPropagation();
});
});
</script>
stuff...
text here
text here2
text here3
stuff......
<div class="toggleh" id="toggle2h">
<div id="aicbk">
stuff....
</div>
</div>
<div class="toggleh" id="toggle3h">
<div id="pdil">
stuff..
</div>
</div>
<div id="footer">
stuff..
</div>
Here's a working sample, tested under Chrome 8.0.552.0 dev:
<html>
<head>
<title>S.O. 3920865</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var gLastH = null;
var gLastId = null;
$('.toggleh').hide();
$('.toggle').click(function(e) {
$('.toggleh:visible').fadeOut('slow');
gLastId = $(this).attr('id');
console.log('#' + gLastId + 'h');
gLastH = $('#' + gLastId + 'h');
$(gLastH).fadeIn('slow');
e.stopPropagation();
});
$('*').click(function(e) {
if ($(this).attr('id') != gLastId) {
$(gLastH).fadeOut('slow');
}
e.stopPropagation();
});
});
</script>
</head>
<body>
<div id="menubar">
<div class="toggle" id="toggle1">
text here
</div>
<div class="toggleh" id="toggle1h">
some description in here I suppose
</div>
<div class="toggle" id="toggle2">
text here2
</div>
<div class="toggleh" id="toggle2h">
some description in here I suppose 2
</div>
<div class="toggle" id="toggle3">
text here3
</div>
<div class="toggleh" id="toggle3h">
some description in here I suppose 3
</div>
</div>
</body>
</html>
Perhaps you need to check jQuery UI accordion which can be what you really want.
EDIT: following 1st comment.
Use this simple code to hide/show menu (or any div)
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
</script>
Click here to toggle visibility of element #foo
<div id="foo" style="display:block">This is foo</div>