1

The following CSS element from this answer works ok in this JS fiddle example, however once I place the elements in my website, the standard drop down arrow becomes visible again due to my div having a float:right.

So: No float:right: Everything works, except that my div is in the wrong location.

Add float:right: Drop down becomes visible again, but then my div is in the correct location.

Sort of: Can't have your cake and eat it.

Browser: Firefox, latest.

Using this, I created a new fiddle with the issue:

<form id="bookingForm">
    <div class="col-md-6" style="float:right">
        Not working due to float:right
        <div class="input-group">
            <select style="width:200px;" class="form-control">
                <option>
                    hr
                </option>
            </select>
        </div>
    </div>
    <div class="col-md-6">
        Working but not in the right place (no float:right)<br/>
        <div class="input-group">
            <select style="width:200px;" class="form-control">
                <option>
                    hr
                </option>
            </select>
        </div>
    </div>
</form>

and the CSS

.input-group {
    width:100%;
    display: inline-block;
}

.input-group select {
    padding: 0% 20% 0% 20%;

    -webkit-appearance:none;
    border: 1px solid #cccccc;
    -webkit-border-radius: 4px;
    border-radius: 20px;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    height: 30px;

    background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAeCAYAAADZ7LXbAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozk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FjbIs82nVfEEBEiAB8k+Q+q1IkqSDNVq4lMy3scIkjuP0FSdbjNHMLys6OwyQVlnXEsOS2QP6OL8jkzlmd70jus86eBT8FIu8PqGXg6oFX6ARGthgX+V1ReFnDJAACZAfhFwHAJI7HF2lZGQaAAAAAElFTkSuQmCC) no-repeat right 0% bottom 0% #ffffff;    

}

For the https://jsfiddle.net/norbertnobel/jtx52dd7/

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Norbert
  • 6,026
  • 3
  • 17
  • 40
  • 1
    Before I post an answer.. is [*this*](https://jsfiddle.net/ctmbocb1/) what you're trying to achieve? – Josh Crozier Mar 17 '15 at 01:23
  • @JoshCrozier : Yes, that is the look I try to achieve. The look and feel is now only sensitive to placing it in the right location with the float:right. Your version is not sensitive to this. Trying to spot the difference... – Norbert Mar 17 '15 at 01:26
  • 1
    @JoshCrozier : Found the difference. I tested those in 1 variation, but not with the padding etc correct I guess. It was to easy for you :) – Norbert Mar 17 '15 at 01:30

2 Answers2

1

(This answer is based on the latest version of FF)


Explanation:

The root of the problem is the percentage based padding on the left/right of the select element.

When the parent element is floated, it basically has a "shrink-to-fit" based width which is reducing the width of the element in your case. Since the percentage based padding on the select element is calculated relative to the parent element's width, the amount of padding differs between both of the elements in your example.

Here is a visual demonstrating how the amount of padding controls whether or not the dropdown arrow appears:

This element's parent is floated:

floated

This select element's parent is not floated:

not-floated

In other words, the floated element has less padding because its parent element's width is smaller.

As you can see, the default arrow is not appearing if the amount of padding exceeds the width of the select element itself. This essentially explains why floating the element causes these visual differences.


Potential solution:

When it comes down to it, you are basically just trying to remove the default dropdown arrow, regardless of the width/padding of the elements. In the latest version of Firefox (v35), you can now simply remove the arrow using -moz-appearance: none:

Updated Example

.input-group select {
    padding: 0% 20% 0% 20%;
    -moz-appearance: none;
    -webkit-appearance: none;
    appearance: none;
    border: 1px solid #cccccc;
    border-radius: 20px;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    height: 30px;
    background: url(...);
}
Community
  • 1
  • 1
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
  • I have to wait 21hrs before I can assign the bounty. It is coming your way – Norbert Mar 17 '15 at 02:25
  • just a quick note, latest stable release version of FF is V36.0.1 [check here](https://www.mozilla.org/en-US/firefox/new/), plus the `-moz-appeareance` solution won't work in FF versions from 30 to 34. – dippas Mar 17 '15 at 02:51
0

It seems like it's your padding that's at fault:

https://jsfiddle.net/jtx52dd7/2/

It works better with this:

.input-group select {
    padding: 0 10px;
}
jlowcs
  • 1,933
  • 1
  • 10
  • 16
  • Tested it, however the current padding (padding: 0% 20% 0% 20%;) makes the "working version" work. This padding:0 10px; makes both show up with the unwanted drop down arrow. – Norbert Mar 14 '15 at 23:04
  • Oh, you **don't** want the arrow? Well, remove the background on the select then. https://jsfiddle.net/jtx52dd7/3/ – jlowcs Mar 14 '15 at 23:06
  • I do not want to have the default arrow. That is why I added the background. Having the default arrow is easy, would not ask that question. Hence that is why I provided a working and not working example in the code and provided the point that adding the float:right messed up my working code. – Norbert Mar 14 '15 at 23:07
  • The background is an arrow. It's not the default arrow, but it is an arrow. https://jsfiddle.net/jtx52dd7/3/ doesn't show an arrow (in chrome anyway) because there is no background. – jlowcs Mar 14 '15 at 23:08
  • Aha: My browser: Firefox latest. That is important information. – Norbert Mar 14 '15 at 23:10
  • Ok, got it. Well, I really don't like the solution from the SO post you're referencing, because the behavior depends on the size of the container (because of the %). I don't have a solution for you though. Usually, when I need a personalized select, I just code one from scratch using div and ul/li. Way less issues that way, although some JS is needed. – jlowcs Mar 14 '15 at 23:21
  • I was going for pure CSS as a way of trying not to use JS for once... ANd it all works until you use rounded corners, then 99% of the solutions fail. This float:right is a curve ball. Just thought I cracked it. – Norbert Mar 14 '15 at 23:37