How can I add custom CSS select box styling for Chrome and Safari? IS there a fix?
Answer:
You need to add -webkit-appearance: none; and a height value for Chrome and Safari.
Any Suggestions?
Resource:
http://bavotasan.com/2011/style-select-box-using-only-css/
Try it on JSFiddle Remove and add that style in Google Chrome:
Before:
- http://jsfiddle.net/JoshSalway/jw6Qy/
After:
- http://jsfiddle.net/JoshSalway/cMbTB/
select{
-webkit-appearance: none;
}
<select> tags are stubborn creatures but there is a way.
If there's a "size" parameter in the tag, almost any CSS will apply. Using this technique, I've created a fiddle that's practically equivalent to a normal select tag, plus the value can be edited manually like a ComboBox in visual languages (unless you put readonly in the input tag).
So here's a minimal example to see the principle behind:
(you'll need jQuery for the clicking mechanism):
<style>
/* only these 2 lines are truly required */
.stylish span {position:relative;}
.stylish select {position:absolute;left:0px;display:none}
/* now you can style the hell out of them */
.stylish input { ... }
.stylish select { ... }
.stylish option { ... }
.stylish optgroup { ... }
</style>
...
<div class="stylish">
<label> Choose your superhero: </label>
<span>
<input onclick="$(this).closest('div').find('select').slideToggle(110)">
<br>
<select size=15 onclick="$(this).hide().closest('div').find('input').val($(this).find('option:selected').text());">
<optgroup label="Fantasy"></optgroup>
<option value="gandalf">Gandalf</option>
<option value="harry">Harry Potter</option>
<option value="jon">Jon Snow</option>
<optgroup label="Comics"></optgroup>
<option value="tony">Tony Stark</option>
<option value="steve">Steven Rogers</option>
<option value="natasha">Natasha Romanova</option>
</select>
</span>
</div>
Here's the fiddle with some more styles:
https://jsfiddle.net/dkellner/7ac9us70/
Hope this helps!
Related
I have a select box like
But when I use the select box in css, it looks like below
how to get the large option box and width have to cover upto text.
You can just add it in the css file.
HTML:
<div >
<select>
<option value="0">Select:</option>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
</div>
And in css you add:
select, option {
width: 250px;
}
Consider the following code:
<div data-role="fieldcontain">
<label for="name">Car</label>
<select data-inline="true" data-theme="b">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<span>message</span>
</div>
The output as follows:
There is a big gap between the component and the message. How can I reduce this gap to a desired amount?
(I tried applying CSS such as width:100px to the component, but no success)
EDIT :
Here is the live demo: http://jsbin.com/icikif/1
The reason can be found in the CSS of jQm:
#media (min-width: 450px)
.ui-field-contain .ui-select {
width: 78%;
display: inline-block;
}
Add a custom Stylesheet and overwrite the width setting.
I'm not sure what you're asking for, but if you want the "message" to be closer to the styled select, add this rule in your CSS:
.ui-field-contain .ui-select {
width: auto !important;
}
just change auto to the desired amount.
How to vertically Align a text with a Select Option.
Link: http://mink7.com/projects/test/dashboard.html
Use labels as in this example fiddle. Markup:
<form action="">
<label for="startDate">Start Date:</label>
<select id="startDate">
<option value="Mar 04">Mar 04</option>
</select>
<label for="endDate">End Date:</label>
<select id="endDate">
<option value="Aug 04">Aug 04</option>
</select>
</form>
When this does not work, then there are some inherited styles interfering and try to set vertical-align: middle as shown in this demo.
In IE and Chrome the select tag text is aligned center automatically, not in firefox. To only target firefox with a padding, without compromising IE and Chrome:
Use a browser specific hack for FF and give it a padding-top:
#-moz-document url-prefix() {
.select select{
padding-top: 8px;
}
}
I have a form with a drop down list of venues and a submit button.
They are supposed to be on the same line, but since the list of venues is dynamic, it could become too long and push the button down.
I was thinking of setting a max-width property to the select, but I'm not clear whether this will work in all browsers. Do you have any suggestions on a workaround?
<form action="http://localhost/ci-llmg/index.php/welcome/searchVenueForm" method="post" class="searchform">
<select name="venue">
<option value="0" selected="selected">Select venue...</option>
<option value="1">venue 0</option>
<option value="2">club 1</option>
<option value="3">disco 2</option>
<option value="4">future test venue</option>
</select>
<input type="submit" name="" value="Show venue!" class="submitButton" />
</form>
css:
.searchform select {
max-width: 320px;
}
.searchform input.submitButton {
float: right;
}
If the venues are generated on the server side, you can use your server-side scripting to cut them down to a specific maximum character count.
When using pure CSS I'd also try setting overflow:hidden, both on the select and the option elements. Also try setting max-width on the option element. When it works in all non-IE, you can use the usual scripts to add max-width support for IE.
try:
fieldset select {
width: auto;
}
I see the "More Action" drop-down box in gmail inbox page.
It has levels and some disabled item in the list.
How to do that in HTML+CSS?
Thank you
In response to Rob, the reason not to use disabled is IE.
The reason why this is not a good idea is that IE still does not support this in IE6, IE7 or IE8.
http://webbugtrack.blogspot.com/2007/11/bug-293-cant-disable-options-in-ie.html
I'v been searching for something similar and this is my solution. You'll need icons to show/hide, add css and javascript (jquery in this example). It show/hide a menu but could be anything inside .hide div.
css:
.shortasc { background: url("/css/asc.gif") no-repeat 50% 50%;cursor:pointer;}
.shortdesc { background: url("/css/desc.gif") no-repeat 50% 50%;cursor:pointer;}
.hide{ display:none;}
.toggle-menu .title {
text-align:left;
}
.toggle-menu div.more{
position: absolute;
border:#999999 1px solid;
background-color:#FFFFFF;
}
.toggle-menu div.more ul{margin:0; padding:2px; text-align:left;}
.toggle-menu div.more ul li{list-style:none; padding:2px; border:#CCCCCC 1px solid;}
html wich call to a jquery function:
<span class="toggle-menu">
<span class="title" onclick="$(this).win('togglewin');">titulo del menu</span><span class="orden shortasc"> </span>
<div class="more hide">
<ul>
<li>Enlace 1</li>
<li>Enlace 2</li>
<li>and so on</li>
</ul>
</div>
</span>
add method to jquery function or edit to add onClick event in title or create your function, or whatever, this is an example with an jquery function http://docs.jquery.com/Plugins/Authoring#Getting_Started:
(function($) {
var methods={
//... your functions
togglewin:function(){
var p = $(this).position();
var parent = (this).closest('.toggle-menu');
if(parent.find('.more').is(':visible')){
parent.find('.orden').removeClass('shortdesc').addClass('shortasc');
parent.find('.more').slideUp();
}else{
parent.find('.orden').removeClass('shortasc').addClass('shortdesc');
parent.find('.more').slideDown().offset( { top:p.top+12,left:p.left } );
}
return this;
}
};
$.fn.win = function(method) {
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' inexistente en jQuery.win' );
}
}
})(jQuery);
Sorry, I can't upload images, but I like the result.
You can group and disable elements in an HTML <select> element without resorting to the use of JavaScript. Something like the following should work:
<select name="foo">
<optgroup label="Odds">
<option value="1">1</option>
<option value="3">3</option>
<option value="5">5</option>
</optgroup>
<optgroup label="Evens">
<option value="2">2</option>
<option value="4">4</option>
<option value="6" disabled="disabled">6</option>
</optgroup>
</select>
A brief inspection in Firebug shows that Google are faking their drop-down box with a whole bunch of HTML and some clever CSS. Personally, I think taking the "correct" approach and styling it to look prettier is a lot more readable than reinventing the wheel here.
You want an unordered list based popup/drop-down menu.