javascript 如何删除默认边框半径,Select2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29944418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove the default border radius ,Select2
提问by Jaskey
I'mm using https://select2.github.io/examples.htmlbut I don't want the border radius. How can I remove border radius to make the search box as well as the sliding area ?
我正在使用https://select2.github.io/examples.html但我不想要边框半径。如何删除边框半径以制作搜索框以及滑动区域?
回答by BENARD Patrick
You can add this css :
你可以添加这个css:
[class^='select2'] {
border-radius: 0px !important;
}
fiddle: http://jsfiddle.net/jEADR/1537/
回答by Guruprasad Rao
Well I've just tried to do a trick basically in jquery as below and yea it works!!
好吧,我只是尝试在 jquery 中基本上做一个技巧,如下所示,是的,它有效!!
Execute below 2 lines once you initialize your select2
初始化后执行以下 2 行 select2
$('.select2-selection').css('border-radius','0px')
$('.select2-container').children().css('border-radius','0px')
回答by tromlet
I really appreciate all the answers in this thread, as they helped me find a good solution.
我非常感谢这个线程中的所有答案,因为它们帮助我找到了一个好的解决方案。
I'm using Ruby on Rails 5.2.0, and I felt that any JQuery or JavaScript solutions felt a little hacky and after-the-fact especially since it should be doable in vanilla CSS - but I felt that using the CSS !important
tag isn't best practice. Not trying to rag on anyone!
我正在使用 Ruby on Rails 5.2.0,我觉得任何 JQuery 或 JavaScript 解决方案都感觉有点老套和事后,特别是因为它应该在 vanilla CSS 中可行 - 但我觉得使用 CSS!important
标签是'最佳实践。不是想骂人!
So, my CSS is as follows, and works well!
所以,我的 CSS 如下,并且运行良好!
.select2-container--bootstrap .select2-selection{
border-radius: 0px;
}
回答by Alphanumu
Open file select2.min.css located dist/css/select2.min.css. locate the border radius you wish to change. example change "border-radius:4px" to "border-radius:0px"
打开位于 dist/css/select2.min.css 的文件 select2.min.css。找到要更改的边界半径。示例将“border-radius:4px”更改为“border-radius:0px”
section of code from select2.min.css below
下面来自 select2.min.css 的代码部分
.select2-dropdown{background-color:white;border:1px solid #aaa;border-radius:4px;box-sizing:border-box;display:block;position:absolute;left:-100000px;width:100%;z-index:1051;}
After a quick look through the CSS I can see 11 "border-radius:4px" change each one to "border-radius:0px" or just change the ones to the areas you wish. check CSS file.
快速浏览 CSS 后,我可以看到 11 个“border-radius:4px”将每个更改为“border-radius:0px”,或者只是将它们更改为您希望的区域。检查 CSS 文件。
Regards
问候
Ben
本