Style select text overflow - html

Trying to figure out a problem with a styled select box. It is wrapped within a div with a background to create a mask-look to it.
When there is too much text in the input it will overflow into the button.
HTML:
<div class="styled-select">
<select class="form-control required" name="address" disabled>
<option style="" value="">Please Select Address</option>
</select>
</div>
CSS:
.styled-select select {
font-family: "Circular", Helvetica, Arial, sans-serif;
font-size: 18px;
background: transparent;
width: 100%;
padding: 15px;
font-size: 16px;
line-height: 1;
border: 0;
height: 50px;
border-radius: 10px;
-webkit-appearance: none;
padding-right: 10%;
}
.styled-select {
width: 100%;
overflow: hidden;
background: url(../images/bg/down-arrow.jpg) no-repeat right #FFF;
background-size: 60px;
height: 50px;
border-radius: 10px;
}
#media (min-width: 768px) {
.styled-select select {
font-family: "Circular", Helvetica, Arial, sans-serif;
font-size: 18px;
background: transparent;
width: 100%;
padding: 18px;
font-size: 18px;
line-height: 1;
border: 0;
height: 55px;
border-radius: 10px;
-webkit-appearance: none;
padding-right: 10%;
}
.styled-select {
width: 100%;
overflow: hidden;
background: url(../images/bg/down-arrow.jpg) no-repeat right #FFF;
background-size: 60px;
height: 55px;
border-radius: 10px;
}
Can anyone solve this?

The problem is, that you are using padding-right: 10%; in your css on the select itself. Measuring the image - the select is approx 270px wide, making 10% of the width only 27px - which is correct by my measures.
To solve this - the background-image for arrow seems to be 60px wide, so use padding-right: 78px; (that is 60px for the background image's width and 18px to respect the padding in mobile media query you've previously set).

See this Fiddle
.styled-select select {
font-family: "Circular", Helvetica, Arial, sans-serif;
font-size: 18px;
background: transparent;
width: 100%;
padding: 15px;
font-size: 16px;
line-height: 1;
border: 0;
height: 50px;
border: 1px solid #0082ff; /* Just to see the area of the form in white bg */
border-radius: 10px;
-webkit-appearance: none;
padding-right: 55px;
box-sizing: border-box;
}
.styled-select {
width: 200px;
overflow: hidden;
background: url(http://emojipop.net/data/images/emoji_set_651.png) no-repeat right #FFF;
background-size: 50px;
height: 50px;
border-radius: 10px;
text-overflow: ellipsis;
}
#media (min-width: 768px) {
.styled-select select {
font-family: "Circular", Helvetica, Arial, sans-serif;
font-size: 18px;
background: transparent;
width: 100%;
padding: 18px;
font-size: 18px;
line-height: 1;
border: 0;
height: 55px;
border-radius: 10px;
-webkit-appearance: none;
padding-right: 10%;
}
.styled-select {
width: 100%;
overflow: hidden;
background: url(http://emojipop.net/data/images/emoji_set_651.png) no-repeat right #FFF;
background-size: 60px;
height: 55px;
border-radius: 10px;
}
<div class="styled-select">
<select class="form-control required" name="address">
<option style="" value="">Please Select Address</option>
<option style="" value="">Please Select Address2</option>
<option style="" value="">Please Select Address3</option>
</select>
</div>

without seeing any of your code, it is a bit hard to tell how you're setting up the HTML to be structured. But one thing you could do is fudge it. Make it appear as if thats what is happening. Assuming your dropdown arrow is a separate element from your select item you could give it some of the following code. (.select button is the class i gave to your button on the dropdown)
.selectButton {
display: block;
position: absolute;
height: 100%;
width: 20%;
max-width: 40px;
background: blue;
z-index: 12;
right: 0;
top: 0;
box-shadow: -24px 0px 30px rgba(255, 255, 255, 1);
}
basically what this does is put it in front of the input text element and then the box shadow does the trick of gradually covering up the additional text.
If you need to fudge it without altering the original element, create a parent wrapper with a div or something within the it and have the select element be a sibling then give it a style of pointer-events: none; in order to prevent it from being clicked on but will still have the appearance that you want.
Some people may say this is bad practice, but given the situation this is about the best thing you can do. very easy, very light and more functional than many of the options provided.
Holler if you have any questions!
Good Luck buddy!
after comment
try this css per info from comment. It'd be best to create a psuedo element with a background color, bg image and a box shadow on it with a z-index that is higher than the select to create a fake button that will still be make the select clickable.
.styled-select {
/*have this create the size of the select*/
width: 100%;
overflow: hidden;
background-repeat: no-repeat;
-webkit-background-size: 80% 80%;
background-size: 80% 80%;
height: 50px;
position: relative;
}
.style-select::before {
content: '';
display: block;
position: absolute;
right: 0;
background-color: $blue;
top: 50%;
transform: translateY(-50%);
width: 60px;
height: 100%;
background: url(../images/bg/down-arrow.jpg);
/* ^^^^ use this as just the white arrow png ^^^ */
box-shadow: -24px 0px 30px rgba(255, 255, 255, 1);
pointer-events: none;
}

Hello there:
This is my solution, you shall take in a variable, which will be the BG-size of the 'down-arrow'. In this case 60px, so here is it:
.styled-select select{
width: calc( 100% - 60px / 2); //before was width: 100%;
text-overflow: ellipsis;
}
#media (min-width: 768px) {
.styled-select select {
width:100%; //remove it, only one in the mobile first declarationis needed
}
}
Keep all the other CSS same, only changed the above mention ones. HOPE THIS HELPS

You are using a percentage value (10%) for the padding-right of the select element in 2 different places. However, for the background-size property of the .styled-select element you are using a fixed pixel value (60px).
This means that when the .styled-select element is exactly 600px wide, the text of the child select element will be clipped at the point the background-image begins - any bigger and you will start to see white space appear between the text and image, any smaller and the text will start to overlap the image.
So, to solve this, you should change the padding-right to a fixed pixel value equal to the background-size value plus a few extra pixels so the text doesn't run right up to the background-image.
I've also taken the liberty of cleaning up your CSS a bit; you don't need to redeclare all styles within a media query, only those you wish to override or change.
.styled-select{
background:#fff linear-gradient(0deg,#00f,#00f) right / 60px repeat-y;
/** DELETE LINE ABOVE AND UNCOMMENT LINE BELOW **/
/* background:#fff url(../images/bg/down-arrow.jpg) right center / 60px no-repeat;*/
border-radius:10px;
height:50px;
overflow:hidden;
width:100%;
}
.styled-select select{
-webkit-appearance:none;
background:transparent;
border:0;
border-radius:10px;
font-family:Circular,Helvetica,Arial,sans-serif;
font-size:16px;
height:50px;
line-height:1;
padding:15px 75px 15px 15px;
width:100%;
}
#media (min-width:768px){
.styled-select{
height:55px;
}
.styled-select select{
font-size:18px;
height:55px;
line-height:1;
padding-right:78px;
}
}
body{
background:#003;
}
<div class="styled-select">
<select class="form-control required" name="address" disabled>
<option value="">Please Select Address</option>
</select>
</div>

Try this:
.styled-select select {
white-space: nowrap;
width: 10em;
overflow: hidden;
text-overflow: ellipsis;
}

Related

Place div border infront of containing text (with fixed display)

This is what I have:
However, I want the shadow below the text to not appear on top of the border. I can get this effect when my 'position' of the heading is set to anything other than "absolute" or "fixed", but I lose flexiblity in animation... which is what I want to do later.
here is my code:
.feature {
height: 300px;
width: 100%;
background-image: url("http://conceptartworld.com/wp-content/uploads/2013/06/The_Last_of_Us_Concept_Art_Crows_JS-01.jpg");
background-size: cover;
background-repeat: no-repeat;
overflow: hidden;
border-bottom: solid 5px #FFFFFF;
box-shadow: 0 2px 10px #333;
}
.feature h1 {
position: fixed;
font-size: 120px;
vertical-align: text-bottom;
color: #FFFFFF;
margin-left: 50px;
font-family: "oswald", sans-serif;
font-weight: 400;
text-transform: uppercase;
text-shadow: 4px 4px 5px rgba(0,0,0,0.5);
transition: margin 0.5s;
}
#moral {
margin-top: 160px;
}
#studios {
margin-top: 160px;
margin-left: 400px;
}
also... my vertical align text-bottom isn't working...that is why I use the top margin.. can anyone tell me why?
Arman
I think you can't make this effect without making the border line a independent element.
Implement it as an <hr/> and set it z-index greater than the text.

dynamic width custom select box with CSS

I need to style the select boxes in my web site something like below,
I have suceded with html+css for fix sizes as below,
<div><select></select></div>
div{
background: url("select-box-background.png") no-repeat scroll right center #fff;
height: 23px;
overflow: hidden;
width: 54px;
}
select{
background: transparent;
border: 0 none;
border-radius: 0;
font-size: 12px;
line-height: 1;
padding: 3px;
width: 78px;
color: #78abd0;
}
But I can't manage to apply this for all select boxes with different width, because I have done the styles with fix width.
How to manage same thing with the dynamic width.

html remove the default select option arrow with extra space from options

I have a select option markup like this
<div class="styleselect">
<select onchange="setLocation(this.value)" class="selections">
<option selected="selected" value="position">Position</option>
<option value="name">Name</option>
<option value="price">Price</option>
</select>
</div>
Here I want to style the default arrow of select option and I changed my css like this
.styleselect {
background-color: #DFD3C3;
background-image: url("http://s21.postimg.org/nx05vn15f/dropdown_style.png");
background-position: 117px center;
background-repeat: no-repeat;
border: 1px solid #C5AF8A;
overflow: hidden;
vertical-align: middle;
width: 140px;
padding: 0;
margin: 0;
display: inline-block;
}
.styleselect select {
background-color: transparent;
margin: 0 0 1px;
padding: 4px;
vertical-align: middle;
width: 190px;
}
It worked fine. But again I got one problem that when I made click on the options the options came with the extra width from the actual width where it is looking really odd. I know that the extra width is coming from the width .styleselect select where I have put extra width. But that has been donefor the styling the arrow. Can someone kindly tell me how to fix the extrawidth so that the my custom arrow should come in place for default arrow in the select options and the extra width for the options will be also hide. The link for fiddle is here
Any help and suggestions will be really appreciable. Thanks
Here you go... I have added the same color for options also just to have an uniform look for the control. Hope it helps.
CSS code :
select{
appearance:none; -moz-appearance:none; -webkit-appearance: none;
}
.styleselect {
background-color: #DFD3C3;
background-image: url("http://s21.postimg.org/nx05vn15f/dropdown_style.png");
background-position: 117px center;
background-repeat: no-repeat;
border: 1px solid #C5AF8A;
overflow: hidden;
vertical-align: middle;
width: 140px;
padding: 0;
margin: 0;
display: inline-block;
}
.styleselect select {
background-color: transparent;
margin: 0 0 1px;
padding: 4px;
vertical-align: middle;
width: 140px;
}
.styleselect select option{
background-color: #DFD3C3;
overflow: hidden;
vertical-align: middle;
width: 140px;
padding: 0;
margin: 0;
display: inline-block;
}
Styling the select is cumbersome. You may get browser issues. But you can use advance plugin for styling select box like http://ivaynberg.github.io/select2/. This also provide lots of other features.
.styleselect select {
width=auto;
}

100% width layout not working properly in a fluid layout

1st sorry if the title is not 100% at the pont, i really have no idea how to compose it.
Anyway here is a simple problem with 100% width layout. I have a form that is inside a fluid container, it has - 1 input, 1 select, 1 button, they all are align inline (horizontal)
the problem when i minimize the window the button and then the select list they move down. which i dont want that.
Here is a example in the fiddle http://jsfiddle.net/4GSLE/ you can minimize the html part and you will see the problem.
How to make them to be in one line and not to move down?
.main {
max-width: 1200px;
margin: 0px auto;
background-color: #eee;
line-height: 50px;
padding: 10px;
}
form {
padding: 0 0 0 0;
margin: 0 0 0 0;
display: block;
}
.clear {clear: both;}
input, select {
float: left;
height: 50px !important;
padding: 0 10px;
width: 66% !important;
border: 1px solid #d6d8db;
margin-right: 20px;
}
input.button {
height: 54px !important;
padding: 0 10px;
margin-top: -1px !important;
width: 125px !important;
border: 1px solid #d6d8db !important;
background: #333;
cursor: pointer;
color: #fff;
}
select {
width: 200px !important;
height: 52px !important;
}
html:
<div class="main">
<form>
<input type="text" name="" value="search" />
<select>
<option>select</option>
</select>
<input type="submit" name="" value="Search now" class="button" />
</form>
<div class="clear"></div>
</div>
Some CSS tweaking to the form, input, and select selectors should do the trick.
form {
padding: 0;
margin: 0;
display: block;
white-space: nowrap;
}
input, select {
display: inline-block;
height: 50px;
padding: 0 10px;
width: 66%;
border: 1px solid #d6d8db;
margin-right: 20px;
}
Demo Here
Side note: Unless you really need them, all those !important declarations will end up causing more trouble than solving issues. I'd avoid !important as much as possible.

repeating image background on input text field

I have a search bar that uses a background image that's 200 by 25 px that uses the following css class
.searchBar{
border-style: hidden;
border-width: 0px;
color: #FFFFFF;
padding-left: 10px;
padding-right: 10px;
font-size:1em;
background-image: url(images/searchBox2.gif);
font-family: "calibri", "helvetica", sans-serif;
margin-left:1%;
width: 200px;
height: 25px;
outline: 0 none;
vertical-align: middle;
}
For some reason, it extends the element to a 220 by 27 field (the 10 padding on the left and right side and another 1 px from the top and bottom in another class) and the background image is repeated. It worked the way I wanted it before with the background not repeated until I recently added doctype html 4.01 transitional into my code. Here's a link to a visual of what I mean:
Picture of Search Bar before and after
Padding adds up to total width of the element. See the example to know how to get same result.
Without padding
.searchbar {
width: 200px;
}
With padding
.searchbar {
width: 180px;
padding: 0 10px;
}
And to avoid the repeating background use background-repeat:no-repeat;
Here is your full solution
.searchBar{
border-style: hidden;
border-width: 0px;
color: #FFFFFF;
padding-left: 10px;
padding-right: 10px;
font-size:1em;
background-image: url(images/searchBox2.gif);
background-repeat: no-repeat;
font-family: "calibri", "helvetica", sans-serif;
margin-left:1%;
width: 180px;
height: 25px;
outline: 0 none;
vertical-align: middle;
}
You can also use shorthand background to merge your background styles
background: url(images/searchBox2.gif) no-repeat;
You can also use shorthand padding to merge you padding-left and right
padding: 0 10px;