Adding separator between arrow icon and text in select - css

I am trying to build a select menu and I am using Bootstrap 4. I replaced background to replace arrow icon in select element, but now I need to add border left to that image, I am not finding anyway.
For reference, I am attaching Image of what's required
and this is what I have achieved so far
and code I did till now
HTML
<select class="custom-select">
<option disabled>Choose 1</option>
<option>another</option>
<option>2</option>
</select>
And this is my CSS
.custom-select {
background: #fff url("/assets/images/down-arrow.png") no-repeat right 0.75rem center;
background-size: 12px 12px;
}

You can use another image for the line in the background as well or make a combined image of arrow and line
Stack Snippet
.custom-select {
background: url("https://image.flaticon.com/icons/png/128/118/118738.png") no-repeat right 0.75rem center, url("http://www.i2symbol.com/images/symbols/brackets/presentation_form_for_vertical_low_line_uFE33_icon_128x128.png") no-repeat right 2rem center;
background-size: 12px 12px;
width: 300px;
height: 40px;
-webkit-appearance: none;
position: relative;
padding: 0 10px;
}
<select class="custom-select">
<option>1</option>
<option>1</option>
<option>1</option>
<option>1</option>
<option>1</option>
</select>

Wrap the select in another DIV (eg. custom-select-wrapper) and use a CSS psuedo element for the border...
https://www.codeply.com/go/edxDmWNLx6
<div class="custom-select-wrapper">
<select classs="custom-select">
<option>opt1</option>
<option>opt2</option>
<option>opt3</option>
</select>
</div>
CSS
.custom-select-wrapper {
position: relative
}
.custom-select-wrapper:after {
border-left: 2px solid #ccc;
content:"\00a0";
position: absolute;
top: 0;
right: 46px;
z-index: 2;
display:block;
height: 38px;
}

I suggest you wrap the select in a div and add an after to it
<div class="select-wrapper">
<select class="custom-select"></select>
</div>
Than, in CSS you add the arrow with an after
.select-wrapper {
position: relative;
background: #fff;
z-index: 1;
}
.select-wrapper select {
background: transparent;
}
.select-wrapper:after {
position: absolute;
z-index: -1;
top: 2px;
right: 0;
bottom: 2px;
width: 12px;
background: #fff url("/assets/rogers/images/down-arrow.png") no-repeat right 0.75rem center;
background-size: 12px 12px;
border-left: 1px solid #ddd;
}
I couldn't test the code, because you didn't share your HTML, so I just gave you an example.
Or than you can add the line to the arrow image

Related

alignment issue with the down-arrow for select tag

I have one form in which I have one field for City Name
I am facing one issue with the down-arrow alignment, currenlty I have aligned that to the right with background property
something like this
background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right white;
but you can see its touching the border of an div, I want to add some spacing from the right
so that I have an equal spacing
I have tried adding padding, margin, left and right properties but the whole div get move of city code
can someone tell me what's the exact issue with this?
EDIT:
added code snippet
.cityName {
display: flex;
max-width: 300px;
margin: 0 auto;
}
.form-inputs{
background: #FFFFFF;
border-radius: 5px;
height: 50px;
width: 100%;
padding: 0 10px;
font-weight: normal;
font-size: 18px;
line-height: 21px;
color: #445566;
margin-bottom: 10px;
}
.cityName select {
width: 90px;
margin-left: 10px;
}
.cityName select.city-short{
position: relative;
background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right white;
background-size: 10px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
<label for="lastName" class="cityName">
<input type="text" id="cityName" placeholder="Enter City Name" class="city validated form-inputs">
<select class="city-short form-inputs">
<option selected="" value="" >NA
</option>
<option selected="" value="" >US
</option>
</select>
</label>
You can add background position size for background property like:
background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right 10px center white

Remove drop down icon issues

I've gone through a variety of different solutions for this problem that don't seem to work for me. I'm sure it's because I'm using a CSS framework, Bulma, that tends to take over things a bit for the wrong direction.
I'm trying to remove the drop down icon from a drop-down menu and replace it with an image. I've got the image showing but I can't seem to make the default arrow hide/remove.
<div class="control">
<div id="newAd-Preview" class="select">
<select>
<option >
test
</option>
<option>Key</option>
<option>Hello</option>
</select>
</div>
</div>
Here's a jsfiddle with some solutions that I've found but don't seem to work. It also already has bulma linked. https://jsfiddle.net/uxgdp3b9/
Add this definition:
.select:not(.is-multiple):not(.is-loading)::after {
background: url("https://cdnjs.cloudflare.com/ajax/libs/ionicons/4.4.8/collection/icon/svg/ios-arrow-dropdown.svg") no-repeat;
transform: rotate(0);
border: none;
width: 20px;
background-position: 50%;
top: 0;
bottom: 0;
right: 5px;
margin: 0;
height: auto;
}
.select {
display: inline-block;
max-width: 150px;
position: relative;
vertical-align: top;
}
select::-ms-expand
{
display: none;
}
.select:not(.is-multiple) {
height: 2.25em;
}
.select:not(.is-multiple):not(.is-loading)::after {
background: url("https://cdnjs.cloudflare.com/ajax/libs/ionicons/4.4.8/collection/icon/svg/ios-arrow-dropdown.svg") no-repeat !important;
transform: rotate(0) !important;
border: none !important;
width: 20px !important;
background-position: 50% !important;
top: 0 !important;
bottom: 0 !important;
right: 5px !important;
margin: 0 !important;
height: auto !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" rel="stylesheet"/>
<div class="control">
<div id="newAd-Preview" class="select">
<select>
<option >
test
</option>
<option>Key</option>
<option>Hello</option>
</select>
</div>
</div>
Note: I needed to add the !important flags because SO's snippet doesn't include the CSS file in the header. If your Bulma CSS file is overridden by your CSS file, you don't need the !important flags.

Vertical scrollbar overlay round-bordered select with CSS

I have one multiple select with some options inside.
select {
overflow-y:scroll;
height: 200px;
border: 1px solid #c4c7cc;
border-radius: 20px;
margin: 0;
padding: 10px;
color: #323232;
width: 100%;
transition: border-color 0.25s ease;
font-size: 12px;
}
select:not([disabled]):hover,
select:not([disabled]):focus {
border-color: #ff7900;
}
select[disabled] {
opacity: 0.5;
}
<div>
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
My preference is to use default scrollbar and always show vertical scrollbar. But my select has border-radius so when running, the vertical scrollbar hides select's top-right and bottom-right corner.
This works well in IE11 because there is enough space in IE11 for the scrollbar not hiding the corners. But in Chrome, it overlays.
I have tried ::-webkit-scrollbar but it always ask me to use customized scrollbar, which I don't want.
So the question is how to make space in select between scrollbar and the border?
https://jsfiddle.net/x2eqqhqy/
I set border to the parent div instead of select and get the result below.
div {
height: 200px;
border: 1px solid #c4c7cc;
border-radius: 20px;
padding: 10px;
width: 100%;
transition: border-color 0.25s ease;
}
select {
height: 200px;
border:none;
color: #323232;
width: 100%;
font-size: 12px;
}
div:hover{
border-color: #ff7900;
}
<div>
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
To hide the corners you must set border-radius on parent, with overflow:hidden. Don't set height on parent. In short, <select> elements are difficult to style cross-browser. Every single select/dropdown library hides the <select> and draws a surrogate using easier to style elements (typically divs and spans) and than copies the selection to the hidden <select>, using JavasScript.
Here's the closest to what you want, without using a plugin:
select {
overflow-y: scroll;
height: 200px;
margin: 0;
padding: 10px;
color: #323232;
width: 100%;
font-size: 12px;
border-radius: 20px;
border-color: transparent;
outline: none;
}
select[disabled] {
opacity: 0.5;
}
div {
border: 1px solid #c4c7cc;
border-radius: 20px;
transition: border-color 0.25s ease;
overflow: hidden;
}
div:hover,
div:active {
border-color: #ff7900;
}
<div>
<select multiple class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
Apply same border-radius to parent and give overflow: hidden like this:
div {
border-radius: 20px;
overflow: hidden;
}
select {
border-radius: 20px;
}

Padding for placeholder without changing the size of input

I do adaptive search form. Search field should take 100% width of the parent div (the width of the parent div will change depending on the resolution of the device). The button "Search" should always be at the right of the field, do not shift down.
A working version.
But there's a problem: The text "Search now" (placeholder) too close to the edge of the field and I can't move it to the right. In other examples, it moves by the set value for the field padding. But if I change the padding — field itself is shifted to the left, but I only need to move the text!
#searchfield {
padding: 10px 0 13px 0; /* Try to change the left padding here! All field shifts to the left! But I need only shift the placeholder text to right! */
}
Try adding text-align:center for id searchfield or add box-sizing: border-box; declaration.
try with any one of below examples, it will move the placeholder to right as you expected, these will support Ie lower versions too.
Example1 (using box-sizing:border-box declaration)
#searchfield {
padding: 10px 0 13px 0px;
box-sizing: border-box;
}
Example2 (using text-align:center declaration)
#searchfield {
text-align:center;
}
You can still use padding to move the placeholder text, with the flavor of box-sizing: border-box; declaration.
box-sizing: border-box; make user-agents include padding/border to the width/height of the box.
#searchfield {
width: 100%;
border: 1px solid #ccc;
padding: 10px 0 13px 10px;
box-sizing: border-box;
/* other declarations... */
}
Vendor prefixes omitted due to brevity.
#sidebar {
width: 20%;
background: #ccc;
height: 300px;
padding: 20px;
}
#search {
width: 100%;
height: 50px;
position: relative;}
#searchfield {
width: 100%;
border: 1px solid #ccc;
margin: 0;
padding: 12px 0 13px 10px;
box-sizing: border-box;
position: absolute;
right: 0;
}
#searchsubmit {
width: 60px;
height: 41px;
background: red 0 0;
border: 0;
overflow: hidden;
cursor: pointer;
right: 0;
position: absolute;
}
<html>
<body>
<div id="sidebar">
<div id="search">
<form id="searchform" method="get" action="/index.php" _lpchecked="1">
<input type="text" name="s" id="searchfield" placeholder="Search now">
<input type="submit" id="searchsubmit" value="Search">
</form>
</div>
</div>
</body>
</html>
It's worth mentioning that border-box is supported in IE8+ as well as modern web browsers.
This could do the trick for you. It solved the issue I was having.
Tried on firefox and chrome
.random-class-name{
text-indent: 10px;
}
Text written inside the input is indented as well.
No need to use position absolute. try this code:
<html>
<body>
<div id="sidebar">
<div id="search">
<form id="searchform" method="get" action="/index.php" _lpchecked="1">
<input type="text" name="s" id="searchfield" placeholder="Search now">
<input type="submit" id="searchsubmit" value="Search">
</form>
</div>
</div>
</body>
</html>
#sidebar {
width: 20%;
background: #ccc;
height: 300px;
padding: 20px;
}
#search {
width: 100%;
height: 50px;
position: relative;}
#searchfield {
width: calc(100% - 60px);
border: 1px solid #ccc;
margin: 0;
padding: 10px 0 13px 20px; /* Try to change the left padding here! All field shifts to the left! But I need only shift the placeholder text to right!
position: absolute;*/
right: 0;
float:left;
box-sizing:border-box;
}
#searchsubmit {
width: 60px;
height: 41px;
background: red 0 0;
border: 0;
overflow: hidden;
cursor: pointer;
right: 0;
float:left;
box-sizing:border-box;
}
live demo on code pen

Icon in input box with content and :before instead of background-image

My issue was I have this nice font set and I use that to place custom icons next to my buttons. (ie: see here)
But now I want to create an input box and put an icon before it like HERE
But instead of a background image I want to put a font in the before content, is this possible?
CSS
.input-box { position: relative; }
input { display: block; border: 1px solid #d7d6d6; background: #fff; padding: 10px 10px 10px 20px; width: 195px; }
.unit { position: absolute; display: block; left: 5px; top: 10px; z-index: 9; }
HTML
<div class="input-box">
<input value="" autofocus="autofocus"/>
<span class="unit">To;</span>
</div>
check following example here
http://jsfiddle.net/pZLcg/52/

Resources