css - 在选择器内对齐文本
问题描述
我有一个作为组件创建的选择器:
<my-selector
...
</my-selector>
这是它的css文件:
my-selector{
select {
-webkit-appearance: none !important;
-moz-appearance: none;
padding: .5em;
background: #fff;
border: 1px solid #ccc;
border-radius: 2px;
padding: 3px 26px;
}
.select-container {
position:relative;
display: inline;
margin-right: 10px;
}
.select-container:after {
content:"";
position:absolute;
pointer-events: none;
}
.select-container:after {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
top: .5em;
right: .75em;
border-top: 5px solid black;
}
select::-ms-expand {
display: none;
}
}
我遇到的问题是单词和左边距之间的距离。我已经尝试过 margin-left、padding 和其他方法来删除它或让它变小但没有成功。
有什么建议么?
解决方案
您通过 css 为选择器添加了填充:
select {
-webkit-appearance: none !important;
-moz-appearance: none;
padding: .5em;
background: #fff;
border: 1px solid #ccc;
border-radius: 2px;
padding: 3px 26px; /* this is the problem, and it's overwriting the padding attribute 4 lines up */
}
您需要删除第一次填充,然后将填充设置为:
padding: 3px 26px 3px 5px; /* top right bottom left */
推荐阅读
- javascript - 单击添加新记录按钮时将焦点设置到特定字段
- excel - 如何在excel中排序时显示我的标题?
- machine-learning - input_dim,output_dim 在更新的 keras 中不起作用
- netbeans - NetBeans:没有为项目或全局定义合适的部署服务器
- http - 如何启动 nostromo 网络服务器?
- matlab - 如何使用轮廓线的长度和宽度来确定轮廓线是圆形还是非圆形?
- javascript - Semantic-ui-react 选项卡窗格 activeIndex 更改破坏了组件的 defaultValue?
- shiny - rHandsontable 下拉列表不保留 Shiny 应用程序中的编辑的问题?
- html - 无法在 HTML 页面中获取标签的文本
- python - 在 Pandas 中将列一分为二的简单方法