0

代替

<style> some css code</a>

然后使用

<a href="mylink" class="some class">anchor</a>

我想使用这样的东西:

<a href="mylink" style="something">anchor</a>

那么我将如何将这个 css 转换成这样的形式(东西):

<style>
.twitterbird {
margin-bottom: 10px;
width: 160px;
height:160px;
display:block;
background:transparent url('twitterbird.png') center top no-repeat;
}

.twitterbird:hover {
background-image: url('twitterbird_hover.png');
}
</style>
4

3 回答 3

2

我不明白你为什么不链接到外部样式表。

放...

<link rel="stylesheet" type="text/css" href="<!--thename of your css file.css-->" />

在你的<head>部分。

获取所有样式并将其保存在该行的 href="" 中链接的文件名中。

像这样...

.twitterbird {
margin-bottom: 10px;
width: 160px;
height:160px;
display:block;
background:transparent url('twitterbird.png') center top no-repeat;
}

.twitterbird:hover {
background-image: url('twitterbird_hover.png');
}

在 .css(级联样式表)文件中,您不使用样式标签。然后,您将使用类名和 id,就像您在 html/php 文件顶部的标签之间使用 css 一样。

于 2013-05-15T16:11:12.817 回答
1

尝试这个

<a href="mylink" 
 style="margin-bottom: 10px;width: 160px;height:160px;display:block;background:transparent url('twitterbird.png') center top no-repeat;" 
 onmouseover="this.style.background='url(twitterbird_hover.png)'"       
 onmouseout="this.style.background='url(twitterbird.png)'">anchor</a>

请不要认为这不是最好的方法,你不应该真正使用内联样式/javascript

于 2013-05-15T16:11:13.213 回答
1

鉴于您的示例,您可以使用内联 css:

<a href="mylink" style="margin-bottom: 10px; width: 160px; height: 160px; display: block; background: transparent url('twitterbird.png') center top no-repeat;">anchor</a>

不幸的是,您将无法:hover像其他人已经提到的那样包含该位。

于 2013-05-15T16:06:20.443 回答