I'm using the following code to customize my select dropdown arrow:
HTML:
<span class="selectWrapper">
<select id="rowselect" class="pageinfoselect input-mini">
<option>...</option>
</select>
</span>
CSS:
span.selectWrapper {
position: relative;
display: inline-block;
width:65px;
}
span.selectWrapper select {
display: inline-block;
padding: 4px 3px 3px 5px;
margin: 0;
font: inherit;
outline:none; /* remove focus ring from Webkit */
line-height: 1.2;
background: #f5f5f5;
height:30px;
color:#666666;
border:1px solid #dddddd;
}
/* Select arrow styling */
span.selectWrapper:after {
content: url("../images/arrow_down.png");
position: absolute;
top: 0;
right: 0;
bottom: 0;
line-height: 30px;
padding: 0 7px;
background: #f5f5f5;
color: white;
border:1px solid #dddddd;
border-left:0px;
}
This works fine and replaces the default dropdown arrow but the problem is that the arrow image is not clickable. If I click on the select box it opens but I want it to open when I click the arrow image as well
Add the following rule
pointer-events:none;
EDIT:
It should be noted though that IE doesn't yet support this property (Although according to caniuse - It will be supported in IE11)
BUT, If you still want to this method you can use Modernizer or conditional comments (For IE < 10) and this css hack (for IE10) to make IE revert to the standard built in arrow.
/*target Internet Explorer 9 and Internet Explorer 10:*/
#media screen and (min-width:0\0) {
span.selectWrapper:after
{
display:none;
}
}
There is however a workaround (and also a different solution) for this, which I mention in my answer here - which also contains this Codepen
Related
Ok so i'm trying to create a custom html select box using css and divs spans.
I don't see any mistakes on it but have no idea why it's not working
Here is the fiddle
<div class="ik_select episodes_list_selectbox ik_select_autowidth" style="position: relative; width: 258px;">
<div class="ik_select_link episodes_list_selectbox-link">
<div class="ik_select_link_text">active opt 4</div></div>
<div class="ik_select_dropdown episodes_list_selectbox-dd" style="position: absolute; z-index: 9998; width: 100%; display: none;">
<div class="ik_select_list" style="position: relative;">
<div class="ik_select_filter_wrap">
A basic select statement goes like this:
<select class="yourStyle">
<option>option_1</option>
<option>option_2</option>
</select>
As per select part is considered, you should use inbuilt select-option pair to work perfectly. If you insist to use DIV's for that purpose, then you must have to use some JavaScript over there to make it work.
As per my opinion you should customize select-option to work for you like this,
.custom-select {
position: relative;
display: block;
}
/* This is the native select, we're making everything but the text invisible so
* we can see the button styles in the wrapper */
.custom-select select {
width: 100%;
margin: 0;
outline: none;
padding: .6em .8em .5em .8em;
/* Prefixed box-sizing rules necessary for older browsers */
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
/* Font size must be 16px to prevent iOS page zoom on focus */
font-size: 16px;
}
/* Custom arrow sits on top of the select - could be an image, SVG, icon font,
* etc. or the arrow could just baked into the bg image on the select. */
.custom-select::after {
content: " ";
position: absolute;
top: 50%;
right: 1em;
z-index: 2;
/* These hacks make the select behind the arrow clickable in some browsers */
pointer-events: none;
display: none;
}
#supports ( -webkit-appearance: none ) or ( appearance: none )
/* Firefox <= 34 has a false positive on #supports( -moz-appearance: none )
* #supports ( mask-type: alpha ) is Firefox 35+
*/
or ( ( -moz-appearance: none ) and ( mask-type: alpha ) ) {
/* Show custom arrow */
.custom-select::after {
display: block;
}
/* Remove select styling */
.custom-select select {
padding-right: 2em; /* Match-01 */
/* inside #supports so that iOS <= 8 display the native arrow */
background: none; /* Match-04 */
/* inside #supports so that Android <= 4.3 display the native arrow */
border: 1px solid transparent; /* Match-05 */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.custom-select select:focus {
border-color: #aaa; /* Match-03 */
}
}
.custom-select {
border: 3px solid #303840;
background: #56B4F9;
}
.custom-select::after {
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 7px solid #303840;
margin-top: -3px;
}
.custom-select select {
font-family: 'Source Sans Pro', Avenir, 'Helvetica Neue', Helvetica, Arial, sans-serif;
letter-spacing: 0px;
font-weight: 700;
color: #303840;
line-height: 1.5;
cursor: pointer;
}
/* Focus style */
.custom-select select:focus {
outline: none;
box-shadow: none;
border: 1px solid transparent;
}
/* Set options to normal weight */
.custom-select option {
font-weight: bold;
background: #fff;
box-shadow: none;
}
<span>Choose an effect:</span>
<div class="custom-select">
<select name="select" id="select-effect">
<option value="1" selected>Triple Swoosh</option>
<option value="2">Simple</option>
<option value="3">Duo Move</option>
<option value="4">Content Move</option>
</select>
</div>
Depending on the nature of your project, there is multiple reasons why using div elements to stylize a select might be a bad idea. To name a few:
You will not benefit from the native mobile browser UI support.
You might also suffer side effects to accessibility and usability.
If you want full details there is a very good article on the topic here.
If you still think you need this, I doubt that trying to repair the JSFiddle you provided will provide a good return on investment. You need a lot more than this to get a good select alternative (including some non-negligible JavaScript). What I would suggest is to look into popular existing solutions to get there instead, such as:
Select2: https://select2.github.io/examples.html
bootstrap-select: http://silviomoreto.github.io/bootstrap-select/examples/
Selectize.js: http://selectize.github.io/selectize.js/
Etc.
Hi I want to change the style of the dropdown, nearer the option tags, in HTML. In Firefox it is working, but not properly in IE and google chrome.
The padding is only working in firefox. The background color is working on all browsers, but in IE you can see it, even on the selected value.
Demo with JSFiddle
Html:
<label for="locale">locale:<em>*</em></label>
<select name="locale" id="locale">
<option selected="selected">en_CA</option>
<option>en_US</option>
<option>fr_FR</option>
<option>fr_CA</option>
<option>ja_JP</option>
</select><br />
CSS:
label{
margin: 5px 0px 10px 0px;
padding: 5px;
height: 22px;
display: inline-block;
width: 100px;
}
label em{
color: red;
font-family: Arial;
font-weight: bold;
}
select{
color: #333;
margin: 5px 0px 10px -5px;
padding: 5px;
height: 32px;
width: 262px;
border: #999 1px solid;
}
select option {
padding: 5px 8px;
background: #ddd;
}
Webkit browsers (Safari, Chrome etc) don't allow padding on select elements. You can however mimic padding by manipulating the height for top and bottom padding and text-indent for left-padding.
Update: The same goes for background-color on option elements. Webkit doesn't allow that and I don't believe there's a workaround other than doing your own Javascript implementation of a drop-down using for example an unordered list and some styling.
I don't think you could just style the option tags. I think I read it from somewhere that it is based on OS or something...
So I wanted a custom select box and I did the following :
html :
<div class="select">
<select name="Step_01_Roof_Width" onChange="GetWidth();" class="Step_01_SelectBox" id="Step_01_Select_Width">
</div>
css :
.select select
{
width: 300px;
background: transparent;
padding: 5px;
font-size: 10px;
line-height: 1;
border: 0;
border-radius: 0;
height: 19px;
-webkit-appearance: none;
}
.select
{
width: 270px;
height: 19px;
border-radius: 15px;
border: black solid 1px;
background: url(/wp-content/themes/blackbird/phpwizard/HTML5Application/public_html/images/Step_01/selectarrow.png) no-repeat right white ;
}
However, this only works for chrome and safari as far as I know, firefox and IE give some problems with this. You can view it here : http://www.solar-discounter.nl/uw-pv-systeem/ If anyone has any idea on how to achieve the chrome and safari example on firefox and IE, that would be such a big help to me!
Thanks for reading.
I think this is what you are looking for : How to remove the arrow from a select element in Firefox
Add opacity:0; to .select select and a div with position absolute before your select.
You can then update the div text with javascript/jquery.
I am using a custom select/dropdown menu per the solution here: https://stackoverflow.com/a/10190884/1318135
This functions great, except that the options only display if you click on the box. Clicking on the 'arrow' on the right does not bring up the dropdown options. What's a workaround?
http://jsfiddle.net/XxkSC/553/
HTML:
<label class="custom-select">
<select>
<option>Sushi</option>
<option>Blue cheese with crackers</option>
<option>Steak</option>
<option>Other</option>
</select>
CSS:
label.custom-select {
position: relative;
display: inline-block;
}
.custom-select select {
display: inline-block;
padding: 4px 3px 3px 5px;
margin: 0;
font: inherit;
outline:none; /* remove focus ring from Webkit */
line-height: 1.2;
background: #000;
color:white;
border:0;
}
/* Select arrow styling */
.custom-select:after {
content: "▼";
position: absolute;
top: 0;
right: 0;
bottom: 0;
font-size: 60%;
line-height: 30px;
padding: 0 7px;
background: #000;
color: white;
}
.no-pointer-events .custom-select:after {
content: none;
}
Depending on your client base,
One very simple bit of code:
pointer-events:none;
See the browser support here: http://caniuse.com/pointer-events
Edit: just in bed and possibly thought of another solution but can't test on my phone, but maybe the jQuery mousedown trigger could be an option, to momentarily hide the arrow a split second before the click, maybe?
Or this, not sure how it'd be used, but saw it in another thread:
$('#select-id').show().focus().click();
If I was at my pc I'd test it...
That's nice. Thanks for the info. Like the use of content. Don't have an Android but from what I'm seeing in Mac on FF, Saf, and Chrome it works pretty good. May try adding:
-moz-border-radius: 0px 20px 20px 0px;
-webkit-border-radius: 0px 20px 20px 0px;
border-radius: 0px 20px 20px 0px;`=
to it to .custom-select:after to align the borders.
Hey guys Im currently trying to get a textbox a select menu and a button all into one sized div cleanly but im running into an issue where each element has odd borders/margins which prevent it from rendering properly (the button appears below the text box and select menu)
Heres the html Im currently using
<div class="content">
<div class="search-panel">
<div class="search-panel-logo">
<img src="img.png" class="search-panel-logo-img" />
</div>
<div class="search-panel-searchbar">
<form class="search-panel-frm" action="" id="fsearchbar">
<input class="search-panel-frm" type="text" id="tseachtext" name="tsearchtext" value="Search" />
<select class="search-panel-frm" id="ssearchselect" name="ssearchselect">
<option value="Cars">Cars</option>
</select>
<input class="search-panel-frm" type="button" id="bsearchgo" name="bsearchgo" value="Search!" />
</form>
</div>
</div>
</div>
and heres the CSS:
.content {
background:inherit;
width:950px;
height:600px;
margin: 0 auto;
}
.search-panel {
width:inherit;
height:500px;
background:#093;
margin:0 auto;
}
.search-panel-searchbar {
width:inherit;
height:30px;
}
.search-panel-searchbar-frm {
width:inherit;
height:inherit;
}
.search-panel-searchbar-frm-text {
width:60%;
height:70%;
}
.search-panel-searchbar-frm-select {
width:20%;
height:80%;
}
.search-panel-searchbar-frm-go {
width:20%;
height:80%;
}
any idea what I can add to get all the elements to appear in one line as opposed to two, Ive already tried
border:0;
margin:0;
and it didnt fix the problem.
To achieve your goal, some CSS tricks had to be applied, see below the CSS:
CSS
/* wrapper */
.search-panel-searchbar {
width: 100%;
height: 30px;
overflow: hidden;
}
/* form elements must be wrapped and not a direct child of the form tag */
.search-panel-searchbar > form > div {
background-color: #fff;
width: 100%;
height:30px;
}
/* input[type="text"] */
.search-panel-searchbar-frm-text {
margin: 0;
padding: 0;
font-size: 12px;
line-height: 16px;
height: 16px; /* necessary to fix height issue on windows browsers */
padding: 6px 0;
display: block;
border: 1px solid #ccc;
background-color:#fff;
width: 60%;
text-indent: 4px;
float: left;
}
/* select */
.search-panel-searchbar-frm-select {
margin: 0;
padding: 0;
font-size: 12px;
height: 30px;
padding: 6px 4px;
display: block;
border: 1px solid #ccc;
background-color:#fff;
width: 20%;
float: left;
margin-left:-1px; /* pull to prevent border overflow issue with % */
}
/* input[type="button"] */
.search-panel-searchbar-frm-go {
margin: 0;
padding: 0;
font-size: 12px;
height: 30px;
padding: 6px 0;
display: block;
border: 1px solid #ccc;
background-color:#fff;
width: 20%;
float: left;
text-align:center;
margin-left:-1px; /* pull to prevent border overflow issue with % */
cursor: pointer;
}
Note:
CSS does not include style given on the Fiddle example to a visual demonstration, like the button hover and body background.
Please take note that unfortunately, each browser (and OS!) deals with the select in different ways, and it's likely that on one or two browsers, the style may differ.
The working Fiddle example!
Screen shot matches tests performed on:
Linux Ubuntu 12.04
Firefox 12.0
Chromium 18.0.1025.151 (Developer Build 130497 Linux)
Windows XP Profissional versão 2002 Service Pack 3
Internet Explorer 8.0.6001.18702
Opera 11.62
Firefox 3.6.16
Safari 5.1.2 (only select box height fail)
Google Chrome 18.0.1025.168 m
K-Meleon 1.5.4 (fail due to font-family)
Windows 7 Home Edition Service Pack 1
Internet Explorer 9.0.8112.164211C
Opera 11.62
Firefox 12.0
Safari 5.1.4
Google Chrome 18.0.1025.168 m
The font-family that you will use must contain a font family declaration at the end to prevent line-height and text-size issues. e.g., font-family: Helvetica, Arial, sans-serif
Remove the whitespace between the elements.
Also, using width: inherit is probably not a good idea - try width: 100% instead or something along those lines. height: inherit can be replaced with height: auto; (or just omitted).
You've posted some CSS classes that doesn't apply to the HTML you posted (eg. .search-panel-searchbar-frm-go)
You're applying the class search-panel-frm to your form element as well as elements within the form. Are you sure this is what you want?
I'm not seeing the same problem: The input, select and input:button all appear on the same line for me.
You can try adding this simple fix to keep everything on one line which may give you some ideas.
.search-panel-frm *
{
white-space:nowrap;
}
If all your elements are already on the same line and you want them to line up better try different values for vertical-align, such as:
.search-panel-frm *
{
vertical-align:top;
}