css ie8 改变select样式2样式 ie8卡死

&nbsp&#8250&nbsp&nbsp&#8250&nbsp
下拉选择框select的纯CSS替代方案
这篇教程中,我将给大家展示表单元素下拉选择框select的CSS替代方案。该方法采用css来实现,看上去非常简单。我们用radio标签列表来模拟下拉列表,选择一个radio可以很好的模拟出select中选择一个元素的效果。一:HTML
下面是我们在form表单里面用到的html代码:&fieldset class="radio-container"&
&div class="radio-options"&
&div class="toggle"&Choose your beer&/div&
&input type="radio" name="my-beer" id="choice1" value="choice1"&
&label for="choice1"&Cul Dorcha&/label&
&input type="radio" name="my-beer" id="choice2" value="choice2"&
&label for="choice2"&Rowers Red Ale&/label&
&input type="radio" name="my-beer" id="choice3" value="choice3"&
&label for="choice3"&Belfast Ale&/label&
&input type="radio" name="my-beer" id="choice4" value="choice4"&
&label for="choice4"&O'Hara Irish Stout&/label&
&/fieldset&二 : 逻辑草图为了让讲解看起来更直观,我试着画了如下的草图来描述,希望表达清楚了。三:CSS代码为了让教程看起来更简洁,我省略了一部分视觉效果方面的CSS代码,(比如绘制箭头部分的CSS)-你可以在附件中查看完整版本的代码。基于同样的原因我还省略可针对不同浏览器的前缀。radio-container的css:radio-container {
height: 4 /* 3em (being the max-height of the inner container) + 1em ("margin") */
.radio-container:hover {
z-index: 9999; }包含在radio-container里面的元素的css:.radio-options {
max-height: 3
width: 100%;
transition: 0.7s;
.radio-options:hover {
max-height: 100
.radio-options .toggle {
padding: 0.75
background:
border-radius: 10
z-index: 1; }
/* li are stacked at the same position as .toggle, only .toggle is visible */
.radio-options li {
width: 100%;
height: 100%;
.radio-options label {
opacity: 0;
transition: 0s; }为了隐藏了input,我们可以用display : none达到目的,但是这种方法在某些浏览器(比如一些移动浏览器)下点击label起不到聚焦相关input的作用。.radio-options input {
width: 300
opacity: 0;
z-index:1;
}四 :鼠标移上去的css代码根据上面的代码,我们来仔细看看hover上去时发生了什么,.radio-container的z-index为一个很大的值,同时.radio-options的max-height属性也变大了(为100em),我们继续:/* li elements have a normal flow within the .radio-options container */
.radio-options:hover li {
position: }
.radio-options:hover label {
opacity: 1;
transition: 0.5s; }五:选中状态To style the checked option we will use the general sibling selector. It uses a tilde character combinator (E ~ F) and matches elements that are siblings of a given element. The first element (E) has to occur before the second (F) one and they have to share the same parent (li items in our case).If one of the radio is checked, we’ll see its label instead of the toggle :.radio-options input:checked ~ label {
opacity: 1;
/* is above the .toggle so is visible */
z-index: 2;
/* has tha same styles as .toggle */
padding: 0.75
background:
border-radius: 10 }On hover it returns to the normal flow.radio-options:hover input:checked ~ label {
border-radius: 0; }六:移动设备上所需的修正因为我们响应的是鼠标的hover事件,所以必须针对移动设备做响应(移动设备没有鼠标)。一种解决办法是将radio 的label始终可见。我先用用自定义的来检测触摸设备,然后添加如下的脚本:$(document).ready(function(){
if (Modernizr.touch) {
$(".radio-options").bind("click", function(event) {
if (!($(this).parent('.radio-container').hasClass("active")))
$(this).parent('.radio-container').addClass("active");
event.stopPropagation();
$(".toggle").bind("click", function(){
$(this).parents('.radio-container').removeClass("active");
})在css中我如下修改每一个:hover的定义:.no-touch .radio-container:hover, .active.radio-container
z-index: 9999; }
.no-touch .radio-options:hover, .active .radio-options {
max-height: 100
.no-touch .radio-options:hover li,
.active .radio-options li {
position: }
.no-touch .radio-options:hover label, .active .radio-options label {
opacity: 1;
transition: 0.5s; }
....七:IE8下如何处理是否兼容IE8取决于你自己,这部分并不是本教程的重点&!--[if (IE 8)]&
$(document).ready(function(){
$(".radio-options li").bind("click", function() {
$(this).siblings(".checked").removeClass("checked");
$(this).addClass("checked");
&![endif]--&css.radio-options .checked label {
padding: 0.75
background: #1b9e4d;
visibility:
z-index: 2; }
....教程结束,希望对你有所帮助,谢谢。
上一篇: 本文为你介绍一个时尚的显示与隐藏图片文字说明的动画效果。当鼠标悬停在一张图片上的时候,包含作者信息、超链接、图片标题的说明内容将会显示出来,显示过程中会有多种特效。某些效果会用到3D transform。我们的目的是是显示效果有着微妙的变化,同时激发
下一篇: 这19种风景树和草轮廓的笔刷完全免费奉献给大家,这是从国外一个前端人员的博客上获得的,据他本人所说,这些素材来自于他亲自骑着自行车出去摄影采集而来。 国内的素材网站往往难以找到这种优雅的素材。 就图片本身而言,似乎充满了哥特式的暗黑风格。 原文2547人阅读
前端开发&HTML5(45)
IE下设置select的无法实现的。先改变select的尺寸可以设置select的宽高
select{ height:20 width:80}
&option&test1&/option&
我想尝试使用css来模拟实现可改变高度,其实ie67下可以通过设置font-size来实现改变select的高度,但是这个是个不是很靠谱的方法,我说下我实现的原理:
第一步:就是在select外边加上两个div分别是 select-outer 和select-inner,然后给他们成inline-block,这样主要为了模拟select是内联元素,然后给select-inner设置一个宽度和高度,这个宽度和高度就是实现重点,为什么呢?大家可以自己做个测试,看看一个不设置任何属性的select高度是多少?这个我做了测试,但是我给select设置了font-size:12因为这个是基本的不然汉字都看不清楚别的就不需要在谈了,然后我给select设置了border:1px
solid #同理也是为了统一不同的浏览器对select边框设置的不同,在这两个前提下我做了测试:IE67:21px; IE8:19px;IE9:18px;FF:18px;chrome:19px;safari:18px;从结果上可以看出,这种情况下的select的高度最大是21最小是18,还有就是我们发现ie67是一样的,并且只有ie67不能更改高度,那么解决的方案来了,那就是把select的高度设置21,那么这个时候所有的浏览器的select的高度相同了,第一步解决了。
第二步:截掉select默认的边框,这个时候我们的select-inner就派上用场了,方法是给select设置position:margin:-1然后给select-inner 设置高度,高度就是上面的21-2=19,我想这个大家应该明白用意了,然后设置overflow:hidden,以及display:inline-block(这里就不再介绍它的兼容设置了,相信大家都很熟悉了),这样设置完在浏览器中看,除去ie67有瑕疵外其余的良好边框被截掉,但是ie67下的左右边框截取的不好,想想应该是没有给select-inner设置宽度的原因,设置了宽度后ok都正常,现在的问题来了,宽度是多少取决于你给select设置了多度是多少?所以当select使用在诸多不同的位置的时候这个问题怎么解决呢?这个也着实让我很头疼没有办法解决(如果你有好的方法可以告诉我),最后我使用了一个比较笨的方案,那就是给select-outer再加上一个class来控制宽度,这样灵活性变得差了许多。
第三步:设置改变高度,我想你如果仔细看完上面的内容,那么答案就很简单了,那个是select-outer设置padding,这个padding-bottom=padding-top=(你要设置的高度-19)/2,当然padding的左右是多少你可以设置。然后给select-outer设置你想要的边框和边框颜色,到这里就基本上完成了。其实我们可以把padding和边框等等设置到上面说的另加的class上去,这样只需要换这个class即可以不同的显示效果了!
下面是代码示例:
&!DOCTYPE html PUBLIC &-//W3C//DTD XHTML 1.0 Transitional//EN& &http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&&
&html xmlns=&http://www.w3.org/1999/xhtml&&
&meta http-equiv=&Content-Type& content=&text/ charset=utf-8& /&
&title&无标题文档&/title&
&style type=&text/css&&
* { padding:0; margin:0; }
body { text-align: padding:50}
.select-outer { display:inline- *display: zoom:1; border:1px solid # }
.select-inner { display:inline- *display: zoom:1; height:19 overflow: position: }
.select-h { border:1px solid # height:21 font-size:12 position: zoom:1; margin:-1 }
.select-wh200 { padding:3 }
.select-wh200 .select-inner { width:200 }
.select-wh200 select { width:202 }
&div class=&select-outer select-wh200&&
&div class=&select-inner&&
&select name=&& class=&select-h&&
&option value=&&&web标准学习aa&/option&
&option value=&&&jQuery学习&/option&
&div class=&select-outer select-wh200&&
&div class=&select-inner&&
&select name=&& class=&select-h&&
&option value=&&&web标准学习&/option&
&option value=&&&jQuery学习&/option&
&div class=&select-outer select-wh200&&
&div class=&select-inner&&
&select name=&& class=&select-h&&
&option value=&&&web标准学习&/option&
&option value=&&&jQuery学习&/option&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:120061次
积分:1689
积分:1689
排名:第18369名
原创:41篇
转载:36篇
评论:42条
(1)(1)(1)(4)(1)(2)(11)(4)(1)(1)(1)(1)(1)(3)(3)(1)(1)(1)(1)(1)(2)(1)(1)(3)(1)(6)(1)(1)(1)(1)(2)(2)(1)(5)(5)(4)南方网景是提供专业网站建设、手机开发、推广优化和软件定制的互联网解决方案综合服务商
兼容IE6/IE7/IE8/火狐浏览器的下拉菜单select样式设置
添加时间:
点击数:950
相关阅读: &
代码如下:&!DOCTYPE html PUBLIC &-//W3C//DTD XHTML 1.0 Transitional//EN& &http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&&&html xmlns=&http://www.w3.org/1999/xhtml&&&head&&meta http-equiv=&Content-Type& content=&text/ charset=utf-8& /&&title&兼容IE6/IE7/IE8/火狐---下拉菜单select样式设置&/title&&style type=&text/css&&body {background-color:#6C6;}.select_border{width:59height:29*background:#background:#*border:1px solid #09f;*padding:4*height:20}.container{*border:0;*position:*height:18*overflow:}.select{border:1px solid #09f;padding:4px 3font-size:12height:30width:60*width:52margin:-1}.select_border,.container {*width:50}&/style&&/head&&body&&p&宽高:93px-28px&/p&&div class=&select_border&&&div class=&container&&&select name=&& class=&select&&&option&北京&/option&&option&天津&/option&&option&上海&/option&&option&重庆&/option&&/select&&/div&&/div&&/body&&/html&
网友 [121.34.170.135]
客服:020-
业务传真:020-相关热词搜索:
延伸阅读:下拉菜单select样式设置(兼容IE6/IE7/IE8/火狐)_CSS3技术应用_网页教学基地
热门关键字:
         
下拉菜单select样式设置(兼容IE6/IE7/IE8/火狐)
来源:下拉菜单select样式设置(兼容IE6/IE7/IE8/火狐) 时间: 09:00:47&&浏览次数:0
复制代码代码如下: &!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"& &html xmlns="http://www.w3.org/1999/xhtml"& &head& &meta http-equiv="Content-Type" content="text/ charset=utf-8" /& &title&兼容IE6/IE7/IE8/火狐---下拉菜单select样式设置&/title& &style type="text/css"& body {background-color:#6C6;} .select_border{ width:59 height:29 *background:# background:# *border:1px solid #09f; *padding:4 *height:20 } .container{ *border:0; *position: *height:18 *overflow: } .select{ border:1px solid #09f; padding:4px 3 font-size:12 height:30 width:60 *width:52 margin:-1 } .select_border,.container {*width:50} &/style& &/head& &body& &p&宽高:93px-28px&/p& &div class="select_border"& &div class="container"& &select name="" class="select"& &option&北京&/option& &option&天津&/option& &option&上海&/option& &option&重庆&/option& &/select& &/div& &/div& &/body& &/html&}

我要回帖

更多关于 ie8无法显示css样式 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信