Created
April 21, 2015 11:13
-
-
Save patw0929/39af8527700c55b13761 to your computer and use it in GitHub Desktop.
[jQuery] Center text in the dropdown list (<select>)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _optimize_selectbox_padding = function () { | |
$(".search__county, .search__district").each(function () { | |
var text_width = (parseInt($(this).css("font-size"), 10) * $(this).val().length); | |
var padding = (($(this).outerWidth() - text_width) / 2); | |
$(this).css("padding-left", padding); | |
}); | |
}; | |
_optimize_selectbox_padding(); | |
$(".search__county, .search__district").on("change", function () { | |
_optimize_selectbox_padding(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment