2013-05-15 65 views
0

而不是從CSS轉換爲純HTML

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

你不能[使用僞類] (http://stackoverflow.com/questions/5293280/css-pseudo-classes-with-inline-styles)內聯樣式,除了在你的例子中的所有內容。 – Adrift

+4

*爲什麼*你想這樣做? –

+1

你爲什麼要這樣做? – eidsonator

回答

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一樣。

+0

不知道這是可能的。謝謝。 – Zox

+0

順便說一下,我在第四行有一個標籤。部分是你應該鏈接的地方 –

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有點像別人已經提及。

+0

感謝您的解決方案。 – Zox

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的

+0

很酷,但我認爲我不能使用JavaScript,但它會派上用場,用於其他用途 – Zox

+0

那麼它不可能:) – iConnor