Chrome adds vertical padding to select options on different computers - html

EDIT: See bottom for screen shots:
I'm just wondering if anyone has come across a similar issue. On my machine, Windows 8 and latest version of Chrome, my select box options all look the way I would expect in terms of vertical spacing. On the developer beside me, also running Windows 8 with the same version of Chrome, the select box options appear to have 5px to the top and bottom of padding. The code is on our development server so we're accessing the same files.
Here's a jsfiddle reproducing the issue on the other developer's machine: http://jsfiddle.net/3etfP/
And here's a test case (same a jsfiddle):
<style type="css">
.select {
padding: 3px;
color: #000;
}
</style>
<div>
<select name="testSelect" id="testSelect" class="select">
<option value="-1">Select One</option>
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
Some other details that may be of use:
Both running Windows 8.0 64bit
Both using Desktop mode
Both using Version 30.0.1599.101 m of Google Chrome
Using the following Chrome extensions:
URL-alizer (both)
Google Hangouts (both)
Right inbox for Gmail (me)
Any.do (other dev)
Quick Notes (other dev)
Google Docs (both)
Please let me know if there are any details I've missed.
Thanks
Select with padding:
Select appearing normally:

Being that it's the same OS and same browser I would look into the user stylesheets:
Windows: \User Data\Default\User StyleSheets\custom.css
Linux: ~/.config/chromium/Default/User StyleSheets/Custom.css
(I know you're both on Windows, just covering bases for readers)
Past that I would use the element inspector to check for differences after the page is rendered. A CSS property that always gets in my way with padding, etc., is box-sizing.

Scott,
If this is something really important, you could mimic the behavior of a select with a div and have better control. That being said it may not be padding, have you tried setting the margin: 0 on the <option> elements?
.select option {
padding: 0;
margin: 0;
}
Most elements have their own padding/margin in different browser. I would recommend using a CSS reset if you want uniform design across all browsers (see here). It could also be that either of you have Chrome zoomed in. Both of you should hold control and press + or - to make sure the zoom is set to 100%.
Edit:
I think you are in for it unfortunately.
See Chris Coyier's article Dropdown Default Styling, especially the latter part of the article, most of which is quoted here.
What about the dropdown itself?
As in, the thing that shows the choices when activated. As far as I
know, there is no way to style these in any browser. Not even bold or
italic. The closest thing to style you can get is grouping them by
using . This is probably mostly a UI thing, but it might be
a security thing too. You wouldn't want people doing tricky things
with fonts that make it unclear what option is selected.
What if you want complete design control?
First, try everything you can to make that not necessary. Default form
elements are familiar and work well. Making a dropdown menu match the
font and colors of your brand isn't usually necessary and is more
likely obnoxious at best and bad UX at worst.
If you decide that it's absolutely a good idea to customize a
dropdown, then you should use JavaScript to:
Accessibly hide the original select.
Rebuild the select with custom markup (probably a definition list), that you style how you want.
Replicate all the functionality that default selects have, which include: keyboard events like up and down arrow keys and return to
select, scrolling of long lists, opening the menu upwards when select
is against bottom of screen, to name a few.
For mobile, trigger the opening of the native select menu, because that functionality is just about impossible to replicate. For example,
the iOS flipwheel.
You might want to consider a "clickthrough" style for desktop as well. Have the select be custom styled by default, but when you click
it, it opens the native dropdown menu (in place). When you select an
option it displays the custom styling again with the choice shown.
It's a lot of work and easy to screw up, so beware.
Joshua

Related

How to make <options> display below <select> dropdown title using just html and css

I have a html/css dropdown using <select> and <option> elements (not <ul>, <li>). I would like to style the dropdown options so that when you click to open the dropdown the list of options appear below the title of the dropdown (the bit you see before you click to open it) not on top of or obscuring that title.
I know that there are limitations to styling dropdowns using <select> and <options> with just html/css but I wanted to know if it was possible to achieve this without having to go down the custom dropdown route.
I believe that this may vary from browser to browser but I am having the issue on Chrome on a Mac.
<select name="numbers">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Currently when the dropdown is closed you would see '1' and when you open it you can no longer see the selected number 1, you can only see the new list of options 1,2,3 which is directly on top of where the 1 for the closed dropdown used to be. I would like it so that you can always see your selected choice e.g. 1 (whether the dropdown is open or closed) and when you do open the dropdown your list of options displays beneath the currently selected choice not obscuring it.
I had the same issue and ended up praising this article for being on spot:
If you decide that it’s absolutely a good idea to customize a
dropdown, then you should use JavaScript to:
Accessibly hide the original select.
Rebuild the select with custom markup (probably a definition list), that you style how you want.
Replicate all the functionality that default selects have, which include: keyboard events like up and down arrow keys and return to
select, scrolling of long lists, opening the menu upwards when select
is against bottom of screen, to name a few. ....
https://css-tricks.com/dropdown-default-styling/
I'd recommend not touching system defaults for "default-selects". If you really need a solution, check out ready-made plugins like the great tomselect:
https://tom-select.js.org/ etc ...
I have had a similar problem in the past and I can tell you I have not found any answers, believe me. If you open "select dropdowns" on a mac, the options appear OVER the input. If you do the exact same thing with the exact same code on a windows pc, the dropdown options appear below the input, which is what you want.
I strongly advise you to move on to another problem as the solution to your simple problem is much more complicated than it might seem...
As far as I know the select tag styling not only depends on the browser but also on the OS as well - the element is styled after the OS display settings, so essentially there's not much you can do with the native element.
I assume that the initial thinking behind the select styling had something to do with accessibility settings.

HTML Select in iPhone: how to turn off ellipses?

I have a select box where each option has the potential to be very long. On desktop it's fine, but on mobile the text gets cutoff at the end of each line with an ellipsis. I need to be able to show the full text, or else the options may not be clear to my users. If I can make the text wrap rather than cutting off that would be fine, but I don't know how to accomplish this since I'm not sure how the iPhone handles select elements.
Select options on iPhone
According to this StackOverflow answer, there is no way to change the styling of <select> elements on iOS, as their display styles are built into the browser and not modifiable via CSS.
This answer suggests that you can use a customizable replacement such as Chosen if you would like more control over the style of your <select> boxes.
Apparently Chosen doesn't support iOS. A comment on another answer recommends Selectize.js as an iOS-compatible replacement.

Prevent select from running off bottom of css dropdown menu

I've a CSS dropdown menu containing a select box that extends beyond the menu's
bottom border when opened. Subsequent clicking on a select option that lies beyond
the menu's bottom border causes the menu to close (i.e., ":hover" no longer applies
once the select closes).
Is there a way around this? It'd be great if I could force the select to "drop up",
but I've not found a way to force this to happen.
Any ideas?
One solution would involve limiting the height of the select, so that it doesn't jut out, or making it always drop-up. This answer discusses those options a bit.
Selects aren't typical HTML elements. We're pretty restricted in styling them, and I'm not entirely sure how much control we'll have even when the the shadow DOM is more widely accessible (I've been meaning to test!). The reason of my uncertainty is that it seems that some browsers, like Safari and Chrome, appear to use OS APIs for their selects, whereas other browsers, like Firefox, clearly use the Shadow DOM.
With all of this said, I think the easiest solution for you would be using a Javascript select plugin to completely get around this issue of modifying the select itself.
The idea of using Javascript is pretty simple. You'll hide the actual select and insert new DOM elements (like divs) to replace it. These divs can be styled to look like a select, and programmed to behave as you'd prefer the select to. And any changes to this facade are applied to the real, hidden select, so that forms can be submitted and manipulated as usual.
Bootplus is just one example of a plugin that has a drop-up. It'd be fairly easy to pull that component from the code.
Chosen is another good plugin that I'm pretty sure lets you limit the size of the dropdown as another alternative.
Or you could run some Google searches and find more!
In short: The current best option for cross-browser control over how a select displays and behaves is using a Javascript plugin.

How do you measure absolute pixel count?

I've recently found that most of the measurements I thought I knew were actually different from what I thought they where due to browser specific defaults. I assessed that all my knowledge of my visual inspections were relative...item A is 20px so I can see that Item B is 22px. However because of browser hidden defaults...this method doesn't work too well. How can I know what absolute pixel count is.
Currently, I just created a 20px by 20px ruler in a graphics editor with tick marks.
Attached here
Now I can move this around by using absolute positioning and measure things. However is there something built into the development tools to do this. I'm using Firefox 10 right now.
Thanks
Chrome's inspector tool shows the dimension of any element that you happen to hover over. However, if you must remain loyal to Firefox, Firebug can show the exact dimensions of any element upon hover as well. When you open up Firebug, click "Layout" in the sidebar to the right. Then, when you hover over an element, the dimensions will appear within that box (no clicking necessary). Not exactly as intuitive as Chrome's inspector tool, but it works regardless.
Are you just looking for a tool to easily measure heights and widths without messing around in Firebug?
I'd suggest this add-on for Firefox (also available for Chrome): Web Developer
If this isn't what you're looking for, can you please clarify?
Edit: If you can't install software or add-ons, use the no-install Firebug Lite
there is a sweet measurement tool called "measure it." you can find it HERE. that's the best one i have found so far.
another thought... you could check and make sure all of your different browsers aren't at all zoomed in... view actual size etc...
also - are you using a "reset" of any kind ? if not - you could check out the meyer reset - or normalize... or - the freak reset... (that combines both).

Trace link hover styles

I have been using Firebug in Firefox and the Developer toolbar in IE to help trace my styles for a branding effort in SharePoint. The trace styles feature in the Developer Toolbar is very nice.. I can easily trace a hyperlink's styles and create the CSS to change it's styling, I'm having some trouble with tracing the hover style for links as neither Firebug nor Developer Toolbar will tell me where those styles are being defined, which makes me hard to override it..
I even tried a:hover { color: #ccc !important; } as a hackish way of doing things, and this fixed a lot of them, but some still remain. The CSS that comes with SharePoint is pretty big, and it's hard to manually go in and find them myself.
Any suggestions?
Jopache, I've been debugging on Chrome or Safari for several months and have grown really fond of the "inspect element" option that's built into webkit when you right-mouseclick on an element. I believe that firebug also adds that functionality to Firefox as well--I switch to Firebug when I really need to get detailed on my requests. So, if you've never tried this one, right mouse click on your link (it will be in the hover state at that point) and click on inspect element. Hopefully, that'll point you to at least the a: state which can then be searched via ctrl-f or grep for similar styles. Also, you'll notice a "computed style" that can be helpful to find specific quirks that can serve as alternate elements to search on.
It can be frustrating to do this on big documents....I'm in the middle of a hugely complex application UI refresh with a 5,000 line CSS document that's more complicated that any I've ever seen. Sometimes, it just requires head-banging. You might try a shortcut and see if a generic a:hover declaration at the bottom of the CSS doc (remember, it reads top to bottom so the last element will override any previous) to solve the issue while you search for a better solution.
If all else fails, here's a pretty good tut: http://www.cleverworkarounds.com/2007/10/08/sharepoint-branding-how-css-works-with-master-pages-part-1/