Padding in select boxes

后端 未结 4 1603
北荒
北荒 2021-02-20 10:10

I know select boxes are a bit of a pain to style with css, but without resorting to advanced techniques is there anyway I can add some padding to push down the text a bit withou

4条回答
  •  借酒劲吻你
    2021-02-20 10:36

    @Demilio's answer is great for hiding the default selectbox. With custom styling you can then change the appearance of the selectbox as you wish.

    The only remaining problem is the arrows/caret which are also gone, as mentioned by @romainnm.

    Unfortunately pseudo elements (e.g. :after) don't work on a select element, so the only way around it is to create an actual element after the select, something like

    .

    Add some stylying:

    .Caret {
      display: block;
      position: absolute;
      cursor: pointer;
      right: 1rem;
      top: 50%;
      margin-top: -1px;
      width: 0;
      height: 0;
      border-top: 5px solid #000;
      border-right: 5px solid transparent;
      border-left: 5px solid transparent;
    }
    

    And this should result in a custom styled select box with arrows:

    Unfortunately the only downside is clicking on the arrow won't open the selectbox, and that also doesn't appear to be possible to tackle with JavaScript.

提交回复
热议问题