html5 line height,HTML5, Placeholder, line-height in Webkit

问题

I have an input field:

with styles:

input {

margin: 0;

padding: 0 6px;

font-size: 19px;

line-height: 19px;

height: 36px;

width: 255px;

}

Problem is the line-height is not taking effect for the placeholder in webkit CHROME. so the text in the input field is aligned in an ugly way. Anyone else seen this and now how to fix it?

Thanks

回答1:

Looking at your tags, I'm assuming you are writing something like...

Unfortunately, Chrome ties your hands when it comes to styling the placeholder, the selector looks like this...

input::-webkit-input-placeholder {}

You can find the styling options, gotchas and supported browsers in Styling the HTML Placeholder

回答2:

Input placeholders don't seem to like pixel line-height values, but this will vertically centre it in the input:

::-webkit-input-placeholder { line-height: normal; }

回答3:

It appears that removing your line-height declaration entirely works. It's worked for me in FF7, Chrome15 and Safari 5.1. Also looked good in IE9 and FF3.6 but does NOT look good in IE8.

回答4:

I don't think I can fully replicate your problem, but perhaps you can fix it using padding: 7px 6px;.

Doing this should hopefully set your top and bottom padding to 7px which pretty much does a similar job as line-height. With different sizes (width/font-size) you should be able to choose the appropriate padding by calculating (height - fontsize) / 2 perhaps give or take a pixel or two for perfection.

来源:https://stackoverflow.com/questions/4982045/html5-placeholder-line-height-in-webkit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值