我想在图标字体和选项之间设置一个边距。它可以用空格来做这个,但是我想在选项元素上用margin-right做这个,如下所示:
select
{
padding: 10px;
width: 100%;
}
select{
border: 0;
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
cursor: pointer;
}
.select_category,
{
position: relative;
}
.select_category{
border-left: 2px solid red;
border-top: 2px solid red;
border-bottom: 2px solid red;
}
.select_category:before {
content: "\f0ca";
font-family: 'FontAwesome';
position: absolute;
left: 0;
font-size: 1em;
z-index: 1;
color: green;
padding: 15px 18px;
}
.select_category option{
margin-right:10px;
}
但它不起作用。你知道为什么吗?
答案 0 :(得分:0)
您可以让父flex
将所有内容放在一行,然后您的边距就可以了。删除伪元素上的absolute
定位,并将select
设置为flex-grow: 1
,以便消耗可用空间。如果容器太高,请删除伪元素上的垂直填充。
select {
padding: 10px;
flex-grow: 1;
}
select {
border: 0;
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
cursor: pointer;
}
.select_category {
position: relative;
}
.select_category {
border-left: 2px solid red;
border-top: 2px solid red;
border-bottom: 2px solid red;
display: flex;
align-items: center;
}
.select_category:before {
content: "\f0ca";
font-family: 'FontAwesome';
font-size: 1em;
z-index: 1;
color: green;
padding: 15px 18px;
}
.select_category:after {
content: "\F0D7";
font-family: 'FontAwesome';
color: #d2d6df !important;
font-size: 2em;
z-index: 1;
color: #00af87;
padding: 15px 18px;
}

<div class="select_category">
<select>
<option selected>Items</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
&#13;
答案 1 :(得分:0)
您应该在padding-left
上使用.select
。 .select_category:before
元素(包含菜单图标)具有绝对位置,因此它的边距不会影响任何其他元素的位置。