2014-02-15 12 views
1

所以我試圖做一個簡單的邊框網站,在CSS:將文本放在與CSS的邊界上?

html{ 
    border-top:3em solid #26282B; 

} 

我想有在它上面的一些白色的文字,我該怎麼辦呢?我嘗試了一堂課,但它總是出現在邊界之下。

+0

您可以發佈你HTML嗎? – Popo

+1

你的字面意思是把文本作爲邊界的一部分嗎?或者你的意思是位於邊界之上? – thgaskell

+0

[Text in Border CSS HTML]可能的重複(http://stackoverflow.com/questions/7731310/text-in-border-css-html) –

回答

1

CAN NOT作任何TEX t在邊界。使用div什麼的。

這裏是例子:

<html> 
<head> 
    <style> 
     body{margin:0;padding:0;} 
     .someclass { 
      width:100%; 
      height:3em; 
      background-color:#26282B; 
      color:white; 
     } 
    </style> 
</head> 
<body> 
    <div class='someclass'> 
     Sometext Here 
    </div> 
</body> 
</html> 
+0

這很好。謝謝。 –

0

你不能在邊界上寫東西 - 技術上是的,但是對於這裏的所有目的而言,不,你不能。

所以,如果你想在上面很短的深色背景上的文字,你寫這樣的事情:

喲HTML:

<div>My suppa text</div> 

喲CSS:

div { 
    background: #26282B; 
    color: #fff; 
} 

<div>這裏作爲<body>之內的第一個元素,它仍然會有一定的餘量,這是因爲瀏覽器的默認樣式。

您可以通過這樣做,喲CSS擺脫它:

html, body { 
    margin-top: 0; 
    padding-top: 0; 
} 

現在我建議你閱讀有關CSS resets

1

你可以把一個跨度文本或DIV設置一個類名和使用左,上,右,下,解決這樣的位置: 如類=「榜樣」

.example { 
    position:absolute; 
    left: 5px; 
    top: 50px; 
} 

別處此可能是幫助你:http://www.w3schools.com/tags/tag_legend.asp

0

如何:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
#container { 
    border: 10px solid; 
    padding: 5px; 
} 

#title { 
    float: left; 
    padding: 0 5px; 
    margin: -20px 0 0 30px; 
    background: #fff; 
} 
</style> 
</head> 
<body> 
    <div id="container"> 
     <div id="title">Border title</div> 
     <p>Some content...</p> 
    </div> 
</body> 
</html>