2014-12-06 113 views
1

要開始我是非常新的自舉,但我想要做一些類似於這個例子:text over background image但在一個引導框架內。我曾嘗試在導航欄下面的容器內創建一個div,但似乎在背後的文字背後放置了白色背景......您可以在此處看到我的代碼:JSFiddle:my code。或者是如下:如何創建背景圖片並在其上添加文字

CSS

body { 
margin-top: 50px; /* Required margin for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ 
} 

@import url(http://fonts.googleapis.com/css?family=Oswald:700); 

html { 
background: url(http://3.bp.blogspot.com/_6r-mOI0OuO0/S6q3VodCqI/AAAAAAAAB5A/Uycl8dCr92A/s1600/NYC15BrooklynBridge02.jpg) no-repeat center center fixed; 
-webkit-background-size: cover; 
-moz-background-size: cover; 
-o-background-size: cover; 
background-size: cover; 
font-family: 'Oswald', sans-serif; 
} 

h1 { 
color: #fff; 
text-align: center; 
font-size: 120px; 
text-transform: uppercase; 
} 

span { 
font-size: 130px; 
color: transparent; 
text-shadow: 0 0 10px #fff; 
} 

HTML

<head> 

<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<meta name="description" content=""> 
<meta name="author" content=""> 

<title>Full - Start Bootstrap Template</title> 

<!-- Bootstrap Core CSS --> 
<link href="css/bootstrap.min.css" rel="stylesheet"> 

<!-- Custom CSS --> 
<link href="css/full.css" rel="stylesheet"> 

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> 
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
<!--[if lt IE 9]> 
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> 
<![endif]--> 

<style type="text/css"> 
    @import url(http://fonts.googleapis.com/css?family=Oswald:700); 


h1 { 
color: #FF6600; 
text-align: center; 
font-size: 120px; 
text-transform: uppercase; 
} 

span { 
font-size: 130px; 
color: transparent; 
text-shadow: 0 0 10px #FF6600; 
} 
</style> 

</head> 

<body> 
<!-- Navigation --> 
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> 
<div class="container"> 
    <!-- Brand and toggle get grouped for better mobile display --> 
    <div class="navbar-header"> 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
      <span class="sr-only">Toggle navigation</span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
      <span class="icon-bar"></span> 
     </button> 
     <a class="navbar-brand" href="#">Start Bootstrap</a> 
    </div> 
    <!-- Collect the nav links, forms, and other content for toggling --> 
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
     <ul class="nav navbar-nav"> 
      <li> 
       <a href="#">About</a> 
      </li> 
      <li> 
       <a href="#">Services</a> 
      </li> 
      <li> 
       <a href="#">Contact</a> 
      </li> 
     </ul> 
    </div> 
    <!-- /.navbar-collapse --> 
</div> 
<!-- /.container --> 
</nav> 

<div class="container"> 
<h1> 
    <span>some text</span><br>some other text 
</h1> 
</div> 
<!-- jQuery --> 
<script src="js/jquery.js"></script> 

<!-- Bootstrap Core JavaScript --> 
<script src="js/bootstrap.min.js"></script> 

</body> 

</html> 
+1

這將使它更容易一點讓別人左右你的代碼,如果你發佈你的樣品多達上[的jsfiddle(http://jsfiddle.net/)玩。您可以在側邊欄中包含引導程序和其他外部資源(請參閱此處)(http://stackoverflow.com/questions/17251586/using-twitters-bootstrap-in-jsfiddle)以獲取幫助)。 – 2014-12-06 06:02:56

+1

只需將您的代碼應用於正確的容器。 http://codepen.io/alexincarnati/pen/NPxRKM – 2014-12-06 06:09:10

回答

1

我看到您已將CSS樣式添加到整個身體,這意味着您必須關閉所有位於其上的所有背景。但是您可以將創建的樣式添加到包含文本的容器中。然後,您可能需要設置樣式才能看到文字。

<div class="container full"> 
    <h1>some text</h1> 
    <h1>some other text</h1> 
</div> 

btw你真的不應該有兩個標頭文本拆分與休息,使用兩個標題和位置他們。如果你打算使用它,你也應該關閉break標籤。 :)

+0

感謝語義幫助。就像我說的我很新 – StillLearningToCode 2014-12-06 07:22:54