【问题标题】:Html Data-Icon messing with input marginsHtml Data-Icon 与输入边距混淆
【发布时间】:2015-05-15 22:02:06
【问题描述】:

我正在尝试在两个输入字段中插入一个数据图标,但他们不断将我的输入字段向右移动,就像他们在其中添加一个左侧边距一样。

我在图标上使用 z-index:2 是为了让它们漂浮在字段上方,它们确实如此,但添加的边距仍然存在。

这是我的 CSS:

#loginBox input#username, #loginBox input#password {
    height: 20px;
    width: 120px;
    padding: 5px 5px 5px 32px;
    border: 1px solid rgb(178, 178, 178);
    box-sizing : content-box;
    border-radius: 3px;
    box-shadow: 0px 1px 4px 0px rgba(168, 168, 168, 0.6) inset;
    transition: all 0.2s linear;
}
#loginBox [data-icon]:before {
    content: attr(data-icon);
    font-family: FontomasCustomRegular;
    color: #999;
    position: relative;
    left: 25px;
    z-index: 2;
}

这是一个截图:

有什么想法吗?

谢谢。

【问题讨论】:

  • 你确定这是边距吗?你检查过萤火虫吗?
  • 不,不确定。我只是说这似乎是一个利润。添加边距:0; do te css 也不做任何事情。
  • 什么浏览器,添加图标后才出现?
  • 在 IE 上可能是由于 padding: 5px 5px 5px 32px;因为 IE 倾向于在文本框外添加填充。
  • 我无法解决这个问题,因为即使没有应用任何边距或填充,图标的左侧仍有一点空间。我通过创建小的 png 图标而不是使用 Data-Icon 做了一个解决方法。

标签: html input margin


【解决方案1】:

Sanjeev 和 Stéphanie Walter 的代码几乎完全相同

http://www.infotuts.com/email-verification-php/

http://tympanus.net/codrops/2012/03/27/login-and-registration-form-with-html5-and-css3/

[data-icon]:after {
    content: attr(data-icon);
    font-family: 'FontomasCustomRegular';
    color: rgb(106, 159, 171);
    position: absolute;
    left: 10px;
    top: 35px;
    width: 30px;
}

位置:绝对;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 2017-09-29
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 2015-05-29
    相关资源
    最近更新 更多