之前一直用windows做开发,最近换了个mac,在几经折腾之下,安装完了各种开发工具,IDE等,然后欣然打开自己正在开发的网站。突然发现mac上所有的下拉框都变了,都是默认样式,无论padding,height都不起作用了,

然后就去搜博客呀,果然,网上好多朋友都在说这个问题,苹果也是让人恼火。

附上一个连接

http://blog.csdn.net/liushuwei0224/article/details/8554995

后来经过搜集资料,修改,调试在测试,依然无果,macos上的select怎么都不能修改高度,

然后最后我要告诉大家的是,给select添加默认样式: border-radius: 0; select瞬间变高变漂亮了

虽然不知道原因,但是希望可以让大家知道这一小小的修改,能解决这一小问题,然后将就着用也挺好看的。

其实中途以为无解的时候,还写了个自定义下拉框样式,还是给大家分享一下吧

less 代码

 .custom-select {
@lineHeight: 36px;
@border: #119ae8;
display: inline-block;
*display: inline;
*zoom:;
height: @lineHeight;
width: 100px;
border: 1px solid #d2d2d2;
position: relative;
line-height: @lineHeight;
text-align: center;
vertical-align: bottom;
margin-right: -4px;
background: white;
&.show {
border: 1px solid @border;
}
.select-text {
display: inline-block;
*display: inline;
*zoom:;
position: absolute;
top:;
left:;
width: 100%;
height: @lineHeight;
cursor: pointer;
cursor: pointer;
.text {
display: inline-block;
height: @lineHeight;
width: 80px;
margin-right: 20px;
line-height: @lineHeight;
overflow: hidden;
}
.arrow {
position: absolute;
right: 5px;
top: 12px;
height:;
width:;
display: inline-block;
*display: inline;
*zoom:;
border: 10px solid transparent;
border-top-color: #9e9e9e;
}
}
.select-options {
display: none;
position: absolute;
top: 37px;
left: -1px;
width: 100%;
border: 1px solid @border;
border-top:none;
background: white;
z-index:;
max-height: 200px;
overflow: auto;
line-height: @lineHeight - 10;
&.show {
display: inline-block;
*display: inline;
*zoom:;
}
.select-option {
display: inline-block;
height: @lineHeight - 10;
color: black;
line-height: @lineHeight - 10;
width: 100%;
cursor: pointer;
&:hover {
background: #119ae8;
color:white;
}
}
}
}

然后用js控制一下点击事件的逻辑

		var select = $('.custom-select');
var optionsContainer = select.find('.select-options');
var selectText = select.find('.select-text');
selectText.find('.text').text('语言方向'); var optionsList = ['test']; // 列表信息从本地固定或者从网络抓取
          optionsContainer.find('.select-option').remove();
          $(optionsList).each(function(index, el){
            optionsContainer.append($('<span class="select-option" lang="'+ el +'">'+langMap[el]+'</span>'));
          }           optionsContainer.find('.select-option').click(function(e){
            selectText.find('.text').text($(this).text());
            optionsContainer.removeClass('show');
            select.removeClass('show');
          }); var selectOptionTimer;
optionsContainer.hover(function(){
// 鼠标进入选择项区域,停止关闭定时器
clearTimeout(selectOptionTimer);
}, function(){
// 鼠标离开选择区域,停止定时器,并关闭选择区域
clearTimeout(selectOptionTimer);
optionsContainer.removeClass('show');
select.removeClass('show');
}); selectText.click(function(){
// 如果当前下拉框是打开状态,则关闭
if(optionsContainer.hasClass('show')) {
optionsContainer.removeClass('show');
select.removeClass('show');
} else {
// 如果当前不是打开状态,先关闭其他所有下拉列表
$('.custom-select .select-options').removeClass('show');
clearTimeout(selectOptionTimer); // 然后再现实当前下拉列表
optionsContainer.addClass('show');
select.addClass('show');
// 如果显示,需要在一定时间之内关闭
selectOptionTimer = setTimeout(function(){
optionsContainer.removeClass('show');
select.removeClass('show');
}, 5*1000);
}
});

  

最后在页面添加对应的元素就OK了

<span class="custom-select">
<span class="select-text">
<span class="text"></span>
<span class="arrow"></span>
</span>
<span class="select-options">
## will rendered by js
## span.select-option
</span>
</span>

  

当然大伙也还是可以随便拿去随便改,毕竟这是空了闲着随便写

最后来一个效果图

关于safari上的select宽高问题小技,自定义下拉框的更多相关文章

  1. jquery美化select,自定义下拉框样式

    select默认的样式比较丑,有些应用需要美化select,在网上找到一个很好的美化样式效果,本人很喜欢,在这里分享一下. <!DOCTYPE html PUBLIC "-//W3C/ ...

  2. select标签设置只读的方法(下拉框不可选但可传值)

    1. <select id="s1" name="s1" onfocus="this.defaultIndex=this.selectedInd ...

  3. jquery Combo Select 下拉框可选可输入插件

    Combo Select 是一款友好的 jQuery 下拉框插件,在 PC 浏览器上它能模拟一个简单漂亮的下拉框,在 iPad 等移动设备上又能回退到原生样式.Combo Select 能够对选项进行 ...

  4. JS为Select下拉框添加输入功能

    JavaScript使用parentNode.nextSibling.value实现的本功能,实际上你会发现网页上有两个控件元素,一个是Select,一个是input,使用CSS将input覆盖于se ...

  5. 高仿QQ即时聊天软件开发系列之三登录窗口用户选择下拉框

    上一篇高仿QQ即时聊天软件开发系列之二登录窗口界面写了一个大概的布局和原理 这一篇详细说下拉框的实现原理 先上最终效果图 一开始其实只是想给下拉框加一个placeholder效果,让下拉框在未选择未输 ...

  6. 自定义样式的select下拉框深入探索

    第一个版本: 首先实现自定义select下拉框应该具有的功能,我是选择将原来的select隐藏掉,自己在jquery代码中动态写进去<dl><dd><dt>这样的结 ...

  7. Jquery对select下拉框的操作

    一.jQuery获取Select选择的Text和Value:语法解释: $("#select_id").change(function(){//code...});   //为Se ...

  8. 吾八哥学Selenium(四):操作下拉框select标签的方法

    我们在做web页面自动化测试的时候会经常遇到<select></select>标签的下拉框,那么在Python里如何实现去操作这种控件呢?今天就给大家分享一下这个玩法.为了让大 ...

  9. 解决select下拉框禁用(设置disabled属性),后台获取值为空

    如果下拉框设置disabled属性后,提交表单到后台,后台获取的下拉框的值为空,以下有三种解决获取不到下拉框选项值的方法. 有下拉框html如:<select name="select ...

随机推荐

  1. Android Support库百分比布局

    之前写过一篇屏幕适配的文章Android 屏幕适配最佳实践,里面提到了类似百分比布局的东西,可是该方法缺点非常明显,就会添加非常多没用的数据,导致apk包变大. 而谷歌的support库中,添加了一个 ...

  2. 自己实现一个SQL解析引擎

    自己实现一个SQL解析引擎 功能:将用户输入的SQL语句序列转换为一个可运行的操作序列,并返回查询的结果集. SQL的解析引擎包含查询编译与查询优化和查询的执行,主要包含3个步骤: 查询分析: 制定逻 ...

  3. Bloom Filter 算法具体解释

    Bloom Filter 算法 Bloom filter是由Burton Bloom 在1970年提出的,其后在P2P上得到了广泛的应用.Bloom filter 算法可用来查询某一数据是否在某一数据 ...

  4. jquery获取当前元素坐标

    1. jquery获取当前元素坐标 A) 获取对象

  5. 给UIImage添加蒙版

    http://stackoverflow.com/questions/17448102/ios-masking-an-image-keeping-retina-scale-factor-in-acco ...

  6. jquery,js常用特效名称

  7. 介绍 Visifire 常用属性的设置

    转载自http://www.cnblogs.com/xinyus/p/3422198.html 主要介绍 Visifire 常用属性的设置,用来生成不同样式的图例 设置Chart的属 //设置titl ...

  8. hprof教程

    大部分内容参考http://www.linuxidc.com/Linux/2012-04/58178.htm J2SE中提供了一个简单的命令行工具来对java程序的cpu和heap进行 profili ...

  9. deb包处理

    1.卸载 dqpg -l 查看信息 dqpg -r  ******  卸载 2.安装 dqpg -i ...............deb

  10. phpwind 去除init.phpwind.net统计功能

    修改的文件如下:global.phplib/staticpage.class.phprequire/template.phpsimple/index.php