在链接图标下添加文本

时间:2013-09-09 13:19:24

标签: html css

我有这个链接,我嵌入到一个图标,我想在图标本身下面添加一个描述文字。

示例:电子邮件图标,在其下面我会有“电子邮件”

这是我目前的链接,我想添加标题“电子邮件”

<a title="Email"  class="icon-envelope" data-bind="attr: { 'href': 'mailto:' + Email() }"></a>

我如何使用css和html的组合来实现这一目标?

4 个答案:

答案 0 :(得分:0)

HTML

<a title="Email" class="icon-envelope" data-bind="attr: { 'href': 'mailto:' + Email() }">Email</a>

CSS

.icon-envelope {
    display:block; 
    width:100px;
    height:100px;
    padding:110px 0 0 0;
    background: url(http://placekitten.com/100/100) no-repeat;
    text-align:center;
}

的jsfiddle

http://jsfiddle.net/GKC9e/

答案 1 :(得分:0)

[详细] DEMO: http://jsfiddle.net/FCP9k/

CSS

a[title] {
    position: relative;
    margin-bottom: 1em;
    width: 100px;
    height: 100px;
    display: block;
    background-image: url('http://placekitten.com/100/100'); /* Default image */
    border: 1px solid red;
    margin-bottom: 1em;
}
a[title="Email"] {
    background-image: url('http://placekitten.com/200/200'); /* Email icon */
}
a[title="SomethingElse"] {
    background-image: url('http://placekitten.com/300/300'); /* A different icon */
}

a[title]:after {
    content: attr(title);
    position: absolute;
    top: 100px;
    display: block;
    text-align: center;
    width: 100%;
    left: 0;
}

答案 2 :(得分:0)

<强> HTML

<a title="Email"  class="icon-envelope" data-bind="attr: { 'href': 'mailto:' + Email() }">Email</a>

<强> CSS

.icon-envelope {
    padding-top:100px; /*height of bg image*/
    display:block;
}

答案 3 :(得分:-4)

<a href="foo">
    <img src="bar" alt="">
    <br>
    Email
</a>

<a href="foo">
    <img src="bar" alt="">
    Email
</a>

a img { display: block; }