如何创建跨度与输入文本框完全相同

时间:2012-04-06 14:15:41

标签: html css

我想创建与输入文本框完全相同的跨度,但在跨度内,它是一个href链接。

请告知。

1 个答案:

答案 0 :(得分:2)

我不确定为什么你想通过使a标签看起来像input来“欺骗”用户,但我相信你的推理是光荣的。利斯特先生对不同的浏览器以不同的方式呈现input有一个很好的评论。既然如此,我认为最好的办法就是在something like this (the first in the example is a link, the second a real input to compare)上获得能够很好地运行的东西。

我只在FF测试过这个。我将a中的文字的不透明度设置为rgba以隐藏它,但保留它以用于搜索引擎目的(因此,您不仅要有一个空的a标记,关注搜索引擎)。在使用“真实”input来实现外观时,它会添加非语义html,但它确实允许更好的跨浏览器呈现框。

<强> HTML

<span class="fakeInput">
   <input type="text" value="Your link"/>
   <a href="#">Your link</a>
</span>

<强> CSS

.fakeInput {
    position: relative;
    display: inline-block;
    margin: 1px;
}

.fakeInput input {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 0;
    width: 100px;
}

.fakeInput a {
    position: relative;
    display: block;
    width: 100px;
    z-index: 1;
    text-decoration: none;
    color: rgba(256, 256, 256, 0); /*hide anchor text, let input show */
    border: 1px solid transparent;
}