2013-10-28 92 views
1

任何人都知道一個CSS破解的改變在這裏的鏈接文字:CSS hack修改html鏈接文本?

<div id = "foo"> <a href="/" rel="bookmark">Long Text for Regular site</a> </div> 

這個較短的版本。

<div id = "foo"> <a href="/" rel="bookmark">Shorter Text</a> </div> 

我能之前或鏈接後添加文本,使用pseudoselectors但沒有運氣修改鏈接文本本身。

我使用的是squarespace模板,所以我無法使用javascript來執行此操作或生成更好的html。

+0

根據這個幫助頁面,Squarespace讓你的JavaScript添加到您的網頁。 http://help.squarespace.com/customer/portal/articles/438262-can-i-add-custom-html-css-and-javascript- –

回答

2

可以完成類似的東西,你想要做什麼用CSS3 text-overflow屬性:

HTML

<p>The quick brown fox <a href="#" class="truncate">jumped over the lazy</a> dogs.</p> 

CSS

P { 
    font-size:12pt; 
    line-height:12pt; 
} 

.truncate { 
    display:inline-block; 
    max-width: 100px; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    line-height:11pt; 
} 

的jsfiddle

http://jsfiddle.net/LcS7a/

1

嘗試:

#foo a{ 
    text-indent: -9999px; 
    visibility: hidden; 
    word-spacing:-999px; 
    letter-spacing: -999px; 
} 
#foo a:after{ 
    content: "New Text"; 
    visibility: visible; 
    word-spacing:normal; 
    letter-spacing: normal; 
} 

演示:http://jsfiddle.net/8DK9g/

1

**編輯**

剛纔看了你不能改變正在生成的HTML,離開這個這裏對於任何可能發現它有用的人

**/E Dit **

使用Duver Jaramillo的示例,我使用數據屬性將縮短的文本移動到標記上。

http://jsfiddle.net/3n1gm4/KrwWL/

HTML

<div id = "foo"> 
    <a href="/" rel="bookmark" data-short-text="Shortened Text">Long Text for Regular site</a> 
</div> 

而CSS

#foo a{ 
    text-indent: -9999px; 
    visibility: hidden; 
    word-spacing:-999px; 
    letter-spacing: -999px; 
} 
#foo a:after{ 
    content: attr(data-short-text); 
    visibility: visible; 
    word-spacing:normal; 
    letter-spacing: normal; 
} 
+0

我不確定,但我假設他可以'改變它的html,爲了使用你的解決方案,他將需要在html中添加data-short-text屬性,但是如果他可以編輯html,這個解決方案會更好,更乾淨,從而將內容與樣式分開。 – Duver

+0

是的,我在提交答案後閱讀了這部分內容。留下任何未來的使用或任何東西 –