打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Styling Texty Inputs Only | CSS

Styling Texty Inputs Only

by: Chris Coyier

Mar 8 2011

Let's say you want fancy styling your your text inputs:

So you go and style those inputs:

input {
    border: 5px solid white;
    -webkit-box-shadow:
      inset 0 0 8px  rgba(0,0,0,0.1),
            0 0 16px rgba(0,0,0,0.1);
    -moz-box-shadow:
      inset 0 0 8px  rgba(0,0,0,0.1),
            0 0 16px rgba(0,0,0,0.1);
    box-shadow:
      inset 0 0 8px  rgba(0,0,0,0.1),
            0 0 16px rgba(0,0,0,0.1);
    padding: 15px;
    background: rgba(255,255,255,0.5);
    margin: 0 0 10px 0;
}

Butthen you add a few more inputs, a file input and the submit button, andyou get sad face because you didn't want those styles to affect thoseelements.

So then you are like no-prob-bob, I'll just make sure to only style text inputs!

input[type=text] {
   /* Awesome styling */
}

Butthen you realize as you build out your form, you want to make use ofthe new HTML5 input types. Those new input types mean betteraccessibility, better mobile support, and enhanced desktop browserexperiences. There is type=email, type=url, type=tel, type=number, type=color, and a bunch more! This is going to get cumbersome...

input[type=text],
input[type=url],
input[type=tel],
input[type=number],
input[type=color],
input[type=email], {
   /* And that ain't all of them... */
}

What are we to do? Well my favorite way would be to harness CSS3 and the :not() selector. So instead of including all the new types, we exclude the ones we don't want styled.

input:not([type=submit]):not([type=file]) {
   /* omg so much cleaner */
}

Nowyou're back to square one (default user agent stylesheet) on thoseother inputs. Don't be afraid to use browser default form controls,people know them and are used to them.

But hold on there hotpants. IE doesn't support that :not()selector until version 9, which isn't even really out yet. Yes indeed,and that sucks. However, if you want to polyfix that sucka you could doso with a quick copy-and-paste job.

<!--[if lt IE 9]>
<script src="//ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->

That is from this project which:

Upgrade[s] MSIE5.5-8 to be compatible with modern browsers.

Notinterested in that? Well you could always just list out all theattribute selectors like I listed above, which will get you back to IE7support. Or, you could go back to just adding class names onto everysingle input and selecting by that which should take you back to thebeginning of the internet.


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
返回主页 SUPERMAN-代码收集狂css小贴士备忘录
Styling an input type=
CSS设置滚动条样式 |前端开发
使用HTML 5和CSS3制作登录页面完整步骤
input file 美化 CSS样式美化
css 层遮挡 无法点击 解决 css pointer-events绝对定位层遮挡的问题解决办法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服