0

Нужно стилизовать тег select при помощи чистого CSS. Попытался сделать вот так, но при клике на стрелку вниз список не открывается, и требуется кликнуть само поле.

* {font-family: Arial}
#search {
    height: 270px;
    width: 310px;
    /*background: #fff65f;*/
    overflow: hidden;
}

#search-form {
    background: #8bab40;
    color: #ffffff;
    padding-left: 40px;
    padding-top: 14px;
}

#search-form input[type="text"], select {
    width: 230px;
    background: #afc968;
    margin-top: 5px;
    margin-bottom: 5px;
    font-family: Arial;
    color: #557013;
}

#search-form input[type="text"]{
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

.select span{
    position: relative;
    top: 2px;
    right: -3px;
}

.select-button {
    float: right;
    width: 18px;
    height: 18px;
    position: relative;
    /*z-index: -9999;*/
    top: 7px;
    right: 42px;
    background: #77993a linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, 0));
    border: #70902b 1px solid;
}

.caret {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 2px;
    vertical-align: middle;
    border-top: 4px solid;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
}

#search-form select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
<div id="search">
<div id="search-form">
                <form>
                    <label>Keyword(s)</label><br>
                    <input type="text">
                    <label>Category</label><br>
                    <div class="select">
                    <select>
                        <option>--select--</option>
                    </select>
                        <div class="select-button"><span class="caret"></span></div>
                    </div>
                </form>
            </div>
            </div>

Что тут ещё нужно доделать?

1 ответ 1

2

Если вы добавите следующее:

.select-button {
   ...
   pointer-events:none
}

Стрелка станет как-бы прозрачной для клика, и при нажатии на нее будет нажиматься поле.

При этом останется возможность стилизовать ее реакции на мышь (hover, active и тд) с помощью селекторов вида select:hover + .select-button

* {font-family: Arial}
#search {
    height: 270px;
    width: 310px;
    /*background: #fff65f;*/
    overflow: hidden;
}

#search-form {
    background: #8bab40;
    color: #ffffff;
    padding-left: 40px;
    padding-top: 14px;
}

#search-form input[type="text"], select {
    width: 230px;
    background: #afc968;
    margin-top: 5px;
    margin-bottom: 5px;
    font-family: Arial;
    color: #557013;
}

#search-form input[type="text"]{
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

.select span{
    position: relative;
    top: 2px;
    right: -3px;
}

.select-button {
    float: right;
    width: 18px;
    height: 18px;
    position: relative;
    /*z-index: -9999;*/
    top: 7px;
    right: 42px;
    background: #77993a linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, 0));
    border: #70902b 1px solid;
    pointer-events:none
}

.caret {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 2px;
    vertical-align: middle;
    border-top: 4px solid;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    
}

#search-form select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
<div id="search">
<div id="search-form">
                <form>
                    <label>Keyword(s)</label><br>
                    <input type="text">
                    <label>Category</label><br>
                    <div class="select">
                    <select>
                        <option>--select--</option>
                    </select>
                        <div class="select-button"><span class="caret"></span></div>
                    </div>
                </form>
            </div>
            </div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.