2012-03-22 93 views
1

當我在文本中輸入換行符時,以下文本在換行符前面開始。換行符忽略邊距

<li><a class="yourlinkclass" href="http://blah.com" class="blahlink" target="blank">this is really <br>annoying</a></li> 

<style> 
A.yourlinkclass { 
font-family: Arial; 
color: #595454; 
text-decoration: none; 
font-size: 11px; 
font-weight:; 
margin-left:80px; 
} 

A.yourlinkclass:hover { 
font-family: Arial; 
color: #BDBDBD; 
text-decoration: underline; 
font-size: 11px; 
font-weight:; 
margin-left:80px; 
</style> 

我該如何解決這個問題,所以文本後,換行符開始後80px像他們應該?

回答

1

這可以在保持換行的同時達到預期的效果。 http://jsfiddle.net/vasco/Dn8Sf/

<li><p id="parent"><a class="yourlinkclass" href="http://blah.com" class="blahlink" target="blank">this is really <br />annoying</a></p></li> 

a.yourlinkclass { 
font-family: Arial; 
color: #595454; 
text-decoration: none; 
font-size: 11px; 
} 

a.yourlinkclass:hover { 
font-family: Arial; 
color: #BDBDBD; 
text-decoration: underline; 
font-size: 11px; 
} 

#parent { 
margin-left:80px; 
} 
+0

感謝奏效,但有反正有沒有在 「P」 之間的空間?我的意思是在每個「p」(我不知道p表示段落?)部分之間,有一個空格。我不喜歡那 – user1284806 2012-03-22 03:20:32

+0

你能解釋一下你的問題嗎?你究竟在詢問什麼?沒有理解...... ru詢問p標籤間距或者給我們提供小提琴的例子.. – 2012-03-22 04:36:47

0

你應該避免麪包和黃油的代碼。 (谷歌它。)

結果谷歌搜索「麪包和黃油代碼」不會返回任何有意義的結果。這意味着你應該避免使用「br」標籤,因爲它們不能用CSS進行樣式化。 (還有一些關於不使用已棄用的HTML標籤的東西,但這不相關。)

所以,不要使用br的。你有嘗試過使用div的嗎?

<li><a class="yourlinkclass" href="http://blah.com" class="blahlink" target="blank"><div>this is really</div><div>annoying</div></a></li> 

聲明:即無效的HTML,因爲DIV是塊級元素和一個內聯是,這樣的div不應該被嵌套在「一」元件的內部。正確的方法是:

<div><a href="blah">This is really</a></div> 
<div><a href="blah">Annoying</a></div> 

但是,這是不可接受的所有用途。 HTML5通過允許任何元素成爲鏈接來修復這個問題,但是您仍然不能依靠瀏覽器支持。你應該真的用和/或來標記這個問題。 「line margin break ignore」不會告訴任何人任何事情。