关于safari上的select宽高问题小技,自定义下拉框
之前一直用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宽高问题小技,自定义下拉框的更多相关文章
- jquery美化select,自定义下拉框样式
select默认的样式比较丑,有些应用需要美化select,在网上找到一个很好的美化样式效果,本人很喜欢,在这里分享一下. <!DOCTYPE html PUBLIC "-//W3C/ ...
- select标签设置只读的方法(下拉框不可选但可传值)
1. <select id="s1" name="s1" onfocus="this.defaultIndex=this.selectedInd ...
- jquery Combo Select 下拉框可选可输入插件
Combo Select 是一款友好的 jQuery 下拉框插件,在 PC 浏览器上它能模拟一个简单漂亮的下拉框,在 iPad 等移动设备上又能回退到原生样式.Combo Select 能够对选项进行 ...
- JS为Select下拉框添加输入功能
JavaScript使用parentNode.nextSibling.value实现的本功能,实际上你会发现网页上有两个控件元素,一个是Select,一个是input,使用CSS将input覆盖于se ...
- 高仿QQ即时聊天软件开发系列之三登录窗口用户选择下拉框
上一篇高仿QQ即时聊天软件开发系列之二登录窗口界面写了一个大概的布局和原理 这一篇详细说下拉框的实现原理 先上最终效果图 一开始其实只是想给下拉框加一个placeholder效果,让下拉框在未选择未输 ...
- 自定义样式的select下拉框深入探索
第一个版本: 首先实现自定义select下拉框应该具有的功能,我是选择将原来的select隐藏掉,自己在jquery代码中动态写进去<dl><dd><dt>这样的结 ...
- Jquery对select下拉框的操作
一.jQuery获取Select选择的Text和Value:语法解释: $("#select_id").change(function(){//code...}); //为Se ...
- 吾八哥学Selenium(四):操作下拉框select标签的方法
我们在做web页面自动化测试的时候会经常遇到<select></select>标签的下拉框,那么在Python里如何实现去操作这种控件呢?今天就给大家分享一下这个玩法.为了让大 ...
- 解决select下拉框禁用(设置disabled属性),后台获取值为空
如果下拉框设置disabled属性后,提交表单到后台,后台获取的下拉框的值为空,以下有三种解决获取不到下拉框选项值的方法. 有下拉框html如:<select name="select ...
随机推荐
- C-冒泡排序,选择排序,数组
——构造类型 ->数组 ->一维数组 ->相同类型的一组数据 ->类型修饰符--数组名—[数组的元素个数(必须是整型表达式或者是整型常量,不能是变 ...
- Android实现程序前后台切换效果
本文演示如何在Android中实现程序前后台切换效果. 在介绍程序实现之前,我们先看下Android中Activities和Task的基础知识. 我们都知道,一个Activity 可以启动另一个Act ...
- .NET基础拾遗(3)字符串、集合和流3
三.流和序列化 3.1 流概念及.NET中常见流 无论什么信息,文字,声音,图像,只要进入了计算机就都被转化为数字,以数字方式运算.存储.由于计算机中使用二进制运算,因此数字只有两个:0 与 1,就是 ...
- Javascript高级程序设计读书笔记(第六章)
第6章 面向对象的程序设计 6.2 创建对象 创建某个类的实例,必须使用new操作符调用构造函数会经历以下四个步骤: 创建一个新对象: 将构造函数的作用域赋给新对象: 执行构造函数中的代码: 返回新 ...
- oracle 数据库 if...elsif...语句
CREATE OR REPLACE FUNCTION "UFN_GETIDS" ( OPEKIND IN VARCHAR2,-- 查询类型 PARAMS IN ...
- 树状dp ural1018
#include<stdio.h> #include<string.h> #include <iostream> using namespace std; ; in ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu 1019 n个数的最小公倍数
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- EF 执行顺序--先删除在更新和添加
public void AcceptAllChanges() { if (this.ObjectStateManager.SomeEntryWithConceptualNullExists()) { ...
- HTML5简单入门系列(一)
前言 随着HTML5的流行,LZ作为一个web开发者,也决定学习一下前端前沿技术. HTML5 是下一代的HTML,它将成为 HTML.XHTML 以及 HTML DOM 的新标准.它是W3C( Wo ...