I need to style the text of a select box, not the list of options. When I add a padding to the select box, this is applied to the list of options, as well. Look at this image:
The icon is a pseudo-element ::before of the div. (I use a div because the select box doesn't work with pseudo-elements).
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
cursor: pointer;
display: inline-block;
height: 35px;
padding: 7px;
padding-left: 30px;
}
select::-ms-expand {
display: none;
}
.select-wrapper {
display: inline-block;
float: right;
position: relative;
}
.select-wrapper:before {
color: #ccc;
content: "\f0c9";
display: inline-block;
font: 16px "FontAwesome";
padding: 9px;
pointer-events: none;
position: absolute;
}
<div class="select-wrapper">
<select class="turnintodropdown">
<option selected="selected" value="">Menu</option>
<option value="http://localhost/wpdev/sample-page/"> Sample Page</option>
<!-- And more options... -->
</select>
</div>
I don't want that the list of options inherits the padding of the main select.
It's hard to tell without knowing the visual styles (FontAwesome?) you have applied in the picture. However, you can use the HTML option element as a CSS Selector:
.select-wrapper .turnintodropdown option {
padding: 0;
}
Alternatively, you can give all your options a class, and style them using that class as well.
Note: styling the padding property of the option element does not currently work in any browser except Firefox, although you can style things like color and background-color in all browsers, including IE11 (I don't have the ability to test older versions of IE).
A Chrome bug report exists for this, but it has been punted down the line for five years already, so I wouldn't hope for a fix soon.
Related
How do i remove the blue background when active on an option and hovering on an option with my select dropdown.
Here is a screenshot of what i mean:
I have tried every css rule i could thin off and even search the internet, including here but nothing is working
.language {
float: right;
margin-top: -45px;
padding-right: 25px;
}
.language select {
width: 180px;
border: none;
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: '';
cursor: pointer;
}
.language select::-ms-expand {
display: none;
}
.language option {
background-color: #000;
color: #fff;
}
.language option:hover {
background-color: #000;
color: #fff;
}
.language-selector::before {
font-family: "Font Awesome 5 Free";
content: "\f0ac";
visibility: visible;
font-weight: 900;
position: relative;
float: left;
margin-left: 1690px;
margin-top: -53px;
}
<div class="language">
<select>
<option value="">English</option>
<option value="">Deutsch</option>
</select>
</div>
Well, you can't. This is set by the OS. Sorry :/
Try this
:focus {outline:0 !important;}
and this
:hover {outline:0 !important;}
If this is not working try on ur own css style !importent this will overwrite all the normall css
Good luck :)
Usually you'd use background: transparent but you have to tell us the rule that's setting the blue color or if it's the OS/browser as someone else mentioned, tell us which OS/browser. Dropdown attributes can't always be styled as many are set by the browser (see the diff between them in Firefox and Chrome). The solution for complete style control is unfortunately to create your own dropdowns using a trigger and list of items you toggle visibility and handle the user's selection.
hi It's happend for me and this is mt solution {background: transparent !important;}
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.
The code:
<input class="text" type="text" value="text"><input class="submit" type="submit" value="submit">
with styling:
.text, .submit {
outline: none;
border: none;
padding: none;
margin: none;
background: red;
padding: 3px;
box-sizing:border-box;
}
(https://jsfiddle.net/citizenfive/04camn42/)
creates 2 input elements with different heights (submit is larger by ~1px).
The code works fine on Chrome. Is there a way to solve this for Firefox?
All browsers have differences between default behaviours and styles, but firefox is more flexible with S.O. and form elements are controlled by default by the operating system.
The solution is remove padding or use height with EM meassures.
Remove padding:
https://jsfiddle.net/04camn42/2/
.class { padding: 0 }
Using EM height:
https://jsfiddle.net/04camn42/3/
.class {
height: 1.5em
}
IF you use EM you don't worry about responsiveness and user choices.
Removed padding and added height, this works fine in Chrome and Firefox but I don't know whether this fix is fine for you.
New css,
.text, .submit {
outline: none;
border: none;
padding: none;
margin: none;
background: red;
/* padding: 3px; */
box-sizing: border-box;
height: 23px;
}
In order to remove all padding and borders from buttons and inputs for Firefox this handy little CSS snippet will help you out.
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
Also, what's been suggested by the other posters: use box-sizing: border-box; on all form elements to make them behave in all browsers (apart from Firefox).
.text, .submit {
outline: none;
border: none;
padding: none;
margin: none;
background: red;
padding: 3px;
box-sizing:border-box;
-moz-box-sizing:border-box;
}
see in i
I know this kind of question was asked at least 100 times but here is what I mean by CSS only:
I want to change style of checkbox/radio with CSS without beeing required to change markup of those elements ( putting them in container / adding label element etc ). I'm asking if it's possible to style <input type"checkbox"/> without adding any new html to it.
Such CSS could be added to any exisitng page and work. All solutions I've found requires some given type of markup and if you'd just add them to some page with forms it just will not work as they might not have labels or containers for inputs itself.
By modify I mean - changing style of box (main css like border-radius, colors, borders, shadows) and changing style of check (color, shape etc).
I know required markup can be added by JS - but it's not solution, it's workaround and I'm not looking for that.
it is not cross-browser solution
input[type="checkbox"]{
width: 30px;
height: 30px;
margin: 0;
padding: 0;
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
outline: none;
}
input[type=checkbox]:after {
content: "";
width: 30px;
height: 30px;
border: 2px solid #ccc;
margin: 0;
vertical-align: top;
display: inline-block;
border-radius: 50%;
}
input[type=checkbox]:checked:after{
background: #ccc;
}
<input type="checkbox" />
I'm trying to customize a select element with only CSS, found this:
<div class="cs_div">
<select>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
css:
.cs_div {
border: 1px solid #ccc;
border-radius: 3px;
overflow: hidden;
background: #fafafa url("../images/select.png") no-repeat;
width: 190px;
}
.cs_div select {
margin: 0;
padding: 5px 8px;
width: 215px;
border: none;
box-shadow: none;
background: transparent;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
}
.cs_div select:focus {
outline: none;
}
works great, but something on main stylesheet of site adds a "blank space" at bottom of div, in chrome, in firefox this doesn't occur.
chrome:
firefox:
already tried padding-bottom: 0; margin-bottom: 0; but not works...
here is a test site with the custom select element: http://eliterosa.bl.ee/activity/
Your question is a bit vague but you may be referring to the vertical alignment of the now inline-block div. You just need to use vertical-align: middle; to div#activity-filter-by-outer...
#activity-filter-by-outer { display: inline-block; vertical-align: middle; }
Now that you made the div an inline block it takes up line-height much like other inline elements.
See screen shot:
Just figured out a way to remove the select arrow from Firefox. The trick is
to use a mix of -prefix-appearance, text-indent and text-overflow.
select {
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: '';
}
It's pure CSS and requires no extra markup. Tested on Ubuntu and Linux,
latest versions.
Live example: http://jsfiddle.net/4WVZW/
by: Ricardo Fuhrmann