How to position a select element and an icon properly with css? - html

I have created a select element within a div with some options to change the language of the page.
The problem is, that the icon which is positioned absolute doesnt react to clicks.
HTML:
<div class="modal-select">
<select v-model="activeLanguage">
<option v-for="(translation, key) in translations" :value="key">
{{ translation.title }}
</option>
</select>
<i class="fa fa-chevron-down"></i>
</div>
SCSS:
.modal-select {
position: relative;
select {
background: #F8F8F8;
padding: 0 5px;
height: 34px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
border: none;
outline: none;
}
i {
position: absolute;
right: 5%;
top: 25%;
cursor: pointer;
color: #3097D1;
}
}
How could I solve this problem?

I don't know what you mean exactly.
Here a few things that could help.
Check the z-index css property. May be your select area is overlapping the icon.
If you want to click on the icon and open the select, you have to link it with js.
If you don't want any hover or animation in your icon, you can put the icon over the select area and give it pointer-events: none;
For example:
.modal-select {
position: relative;
width: 100px;
}
.modal-select select {
background: #F8F8F8;
padding: 0 5px;
width: 100px;
height: 34px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
border: none;
outline: none;
}
.modal-select i {
position: absolute;
right: 5%;
top: 25%;
cursor: pointer;
color: #3097D1;
pointer-events: none;
}
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css">
<div class="modal-select">
<select>
<option value="">option 1</option>
<option value="">option 2</option>
<option value="">option 3</option>
</select>
<i class="fa fa-chevron-down"></i>
</div>

Related

How to fix disappearing hoverable Box with HTML-Select-Input (in Firefox)

I'm trying to fix an issue with a hoverable span in html. Inside the span element is a html-select option. When I try to select something, the hoverable span disappears.
This issue only occurs in Firefox. In Chrome I don't have this issue.
HTML Part:
<span class="over">
<i class="fa fa-cogs edit"></i>
<div>
<form method="post" accept-charset="utf-8" action="/edit">
<div class="input select">
<label for="select-id">Select</label>
<select name="select_id" id="select-id">
<option value="">-- select --</option>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
</div>
</form>
</div>
</span>
SCSS Part:
.over{
margin-right: 0.5em;
&>i{
color: #bbbbbb;
padding: 2px;
}
&>a{
padding: 2px;
display: none;
&:hover{
color: #000;
}
}
&>div{
display: none;
position: absolute;
border: 1px solid #ccc;
margin: 6px 0 0 -20px;
padding: 2px;
background: white;
border-radius: 4px;
min-width: 140px;
z-index: 100;
text-align: left;
input, select{
padding: 0 5px;
line-height: 1.5em;
width: auto;
display: inline-block;
}
label{
margin: -4px 4px;
display: inline-block;
}
}
&:hover{
border: 1px solid;
border-radius: 4px;
&>i{
color: #000;
}
&>a{
display: inherit;
}
&>div{
display: inline-block;
}
}
}
}
In Chrome I can hover over the span item and select a option from the select-element. Even if I leave the hoverable area.
In Firefox I can also hover over the div, but as soon as I leave the hoverable area, the box disappears and I cannot select an Item.
Problem seems to be fixed in Firefox now.

Add padding to select, but not option tags

I have a simple select dropdown menu with a significant amount of padding-left and padding-right:
If you click the select input, you'll notice the option tags also have the same amount of padding-left and padding-right applied. However, I want the padding to only apply to the select tag, but not the option tags (i.e. no padding for the option tags).
How can I do this?
select {
width: 400px;
background: lightgray;
padding: 12px 48px;
}
<select>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
</select>
From what I know the select box and the dropdown get rendered by the browser engine. This means they are not changeable.
So the only solution is to use a framework (Because of this reason there are many outside) or build one by your own.
If you look in the developer console you will also see that most of the styles of the option element are inherited by the browser and greyed out.
Try This:
$(document).ready(function(){
$('.sel').click(function(){
$('ul').toggle();
})
$('li').click(function(){
$('.sel input[type=text]').val($(this).html());
$('ul').hide();
})
})
* {
box-sizing: border-box;
}
.wrapper {
width: 400px;
position: relative;
cursor: pointer;
}
.sel {
position: relative;
width: inherit;
border: 1px solid #000;
}
.sel input[type="text"]{
width: 100%;
background: lightgray;
padding: 12px 48px;
border-style: none;
outline: none;
cursor: pointer;
}
.sel span {
position: absolute;
right: 25px;
top: 10px;
}
ul {
padding: 0;
margin: 0;
list-style: none;
background: lightgray;
width: 100%;
display: none;
z-index: 999;
}
li {
padding: 10px 0;
}
li:hover {
background-color: skyblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="wrapper">
<div class="sel">
<input type="text" readonly="readonly" value="Option1"><span>▼</span>
</div>
<ul>
<li>Option1</li>
<li>Option2</li>
<li>Option3</li>
</ul>
</div>

CSS Fontawesome Icon Click able in IE 10

I had added Fontawesome Icon in css to display it in select Dropdown
Now I am not able to click the Fontawesome Icon in IE 10 can any one know how to solve this
HTML
<div class="select">
<select>
<option value="">Order By</option>
<option value="1">ID</option>
<option value="2">Details</option>
</select>
</div>
CSS
.select {
position: relative
}
.select select {
-webkit-appearance: none;
-webkit-border-radius: 0px;
-moz-appearance: none;
appearance: none;
border: 0;
background-color: #e5e5e5;
height: 30px;
padding: 0 20px;
width: 100%;
position: relative;
margin-bottom: 0;
}
.select select::-ms-expand {
display: none;
}
.select:after {
content: '\f0d7';
font-family: 'FontAwesome';
font-size: 16px;
color: #000;
position: absolute;
right: 15px;
top: 6px;
pointer-events: none;
}
Fiddle
If you want to have the icons beside your existing elements in the dropdown, you have to include that you want them next to your HTML elements. Meaning, you have to add the specific FontAwesome icon next to your dropdown element for it to display. If that was your question.
Like this; <option value=""><i class="fa fa-your-content"></option>.
Else it won't display no matter how hard you try.
Additionally, have you linked to the FontAwesome source or CDN? Because without the source code, you can't display any of the customized elements.

replace select dropdown arrow with fa-icon

I am trying to replace a select dropdown arrow with a fa-icon (chevron-circle-down) but I can only find that the background can be replaced with an image in the css file.I can add the icon over the select,but it won't be clickable.Any help how I use font icon in select dropdown list ?
as you can't use pseudo-elements on <select> you use them on a label instead.
using:
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
will hide the default down arrow the select has and instead you use the fa-chevron-circle-down icon with it's unicode \f13a as an :after pseudo-element applied to the label
it's not really a 'beautiful' solution, but it does the trick
let me know if it helps
see below snippet
label.wrap {
width:200px;
overflow: hidden;
height: 50px;
position: relative;
display: block;
border:2px solid blue;
}
select.dropdown{
height: 50px;
padding: 10px;
border: 0;
font-size: 15px;
width: 200px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
label.wrap:after {
content:"\f13a ";
font-family: FontAwesome;
color: #000;
position: absolute;
right: 0;
top: 18px;
z-index: 1;
width: 10%;
height: 100%;
pointer-events: none;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<label class="wrap">
<select class="dropdown">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</label>

<select> ::before icon not clickable

I have a select element with a few options, but the icon that is rendered is not part of the element and therefore not clickable. Any ideas?
My code
html
<div class="styled-select icon-drop-down">
<select class="select">
<option value="low">Sort by: Low</option>
<option value="high">Sort by: High</option>
<option value="long text">long text</option>
</select>
</div>
css
.styled-select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 100%;
cursor: pointer;
overflow: hidden;
display: inline;
position: relative;
border-radius: 0;
border: none;
&.icon-drop-down::before {
position: absolute;
top: 5px;
right: 10px;
color: $dark-grey;
transform: scale(0.7);
}
}
pointer-events: none; on the pseudo element will enable you to "click through" the pseudo element as if it was not there.
For more information see:
http://developer.mozilla.org/en/docs/Web/CSS/pointer-events
I got the similar issue, add pointer-events: none; to sudo class style, only fix the issue in chrome and firefox, but it doesn't work properly in IE11. I used display: block; or display: inline-block; together with pointer-events: none; fix the issue in IE browser.