【问题标题】:Convert From CSS To Pure HTML从 CSS 转换为纯 HTML
【发布时间】:2013-05-10 07:23:37
【问题描述】:

代替

<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>

【问题讨论】:

  • 你不能 use pseudo-classes 在内联样式中,但在你的例子中一切都是可能的。
  • 为什么你想这样做?
  • 你为什么要这样做?
  • 你的意思是我不能使用悬停?
  • 不幸的是,不只是 CSS .. :(

标签: html css button hyperlink href


【解决方案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 位。

【讨论】:

    【解决方案2】:

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

    放...

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

    在您的 &lt;head&gt; 部分中。

    获取所有样式并将其保存在该行的 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 一样。

    【讨论】:

    • 不知道这是可能的。谢谢。
    • 顺便说一句,我在第 4 行有一个 head 标签。在你的头部是你应该链接的地方。
    【解决方案3】:

    试试这个

    <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

    【讨论】:

    • 酷。但我认为我不能使用 javascript,但它会在其他用途​​中派上用场。
    • 那么它不可能:)
    猜你喜欢
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 2018-05-11
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 2014-04-21
    相关资源
    最近更新 更多