2017-03-28 37 views
0

這是我第一次問Stack Overflow,所以如果格式不完美,我很抱歉。無論如何,我正在使用Bootstrap 3的網站上工作。它具有一個垂直和水平居中在頁面中間的圖像。它也有一個背景圖片。我正在試圖將標題放在圖片的中間,但標題會顯示在頁面的頂部。頁面底部有一個固定的導航欄。如何在Bootstrap 3中將標題保留在居中圖片下?

這裏的HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
    <head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
       <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> 
     <title> 
      App 
     </title> 
     <style> 
      html { 
       background-image: url("gradiant.png"); 
      } 
      .logo { 
       position: absolute; 
    top: 40%; 
    left: 50%; 
    width: 500px; 
    height: 500px; 
    margin-top: -216.5px; 
    margin-left: -236.25px; 
      } 
      .nav-pills li a { 
       color: white; 
       font-size: 250%; 
      } 
       .nav-pills li a { 
    background-color: transparent; 
    color: #ffffff; 
    transition: all .5s; 
border: 2px solid transparent; 
} 
.nav-pills li a:hover{ 
    background-color: transparent; 
    color: #ffffff; 
    border-color: #ffffff; 

} 
.dropdown{ 
    background-color: transparent; 
    color: #ffffff; 
    border-color: #ffffff; 

} 
.nav-pills > li > .dropdown-menu { 
    background-color: transparent; 
    border-color: #ffffff; 
    } 
    .dropdown-toggle { 
     background-color: transparent !important; 
    } 
.dropdown-toggle:active, .open .dropdown-toggle { 
    background-color: transparent !important; 
    color: white !important; 
    border-color: #ffffff !important; 
    } 
.nav-pills { 
    float:none; 
    margin:0 auto; 
    display: block; 
    text-align: center; 
} 

.nav-pills > li { 
    display: inline-block; 
    float:none; 
} 
h1 { 
    position: absolute; 
    color: #ffffff; 
} 
    </style> 
    </head> 
    <body> 
<img alt="App" src="app.png" width=472.5 height=433 class="logo" align="middle" > 
<h1>App</h1> 
<ul class="nav nav-pills navbar-fixed-bottom"> 

      <li><a href="index.html">Home</a></li> 

    <li class="dropdown"> 
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Apps <span class="caret"></span></a> 
      <ul class="dropdown-menu"> 
      <li><a href="app.html">App</a></li> 
      </ul> 
     </li> 

    <ul class="dropdown-menu"> 

    </ul> 
    </li> 
       <li><a href="contact.html">Contact</a></li> 

</ul> 
    </body> 
</html> 
+0

您使用的是圖像的梯度,而不是隻是在做與CSS線性漸變有什麼特別的原因嗎?看看這個問題,如果你不熟悉:http://stackoverflow.com/questions/28046721/how-to-use-bootstrap-3-gradient-for-background-in-css –

+0

我使用的圖像,因爲我的標誌使用相同的梯度。 –

回答

0

這是不是一個特定的自舉的答案,但你可以做的是標誌創建容器和應用CSS,你目前正在申請的形象,到容器。然後,只需把圖像下方的標題容器:

html { 
 
    background-image: url("gradiant.png"); 
 
} 
 
.logo-container { 
 
    position: absolute; 
 
    top: 40%; 
 
    left: 50%; 
 
    width: 500px; 
 
    height: 500px; 
 
    margin-top: -216.5px; 
 
    margin-left: -236.25px; 
 
} 
 
    .logo-container img { 
 
    width:100%; 
 
    } 
 
.nav-pills li a { 
 
    color: white; 
 
    font-size: 250%; 
 
} 
 
.nav-pills li a { 
 
    background-color: transparent; 
 
    color: #ffffff; 
 
    transition: all .5s; 
 
    border: 2px solid transparent; 
 
} 
 
.nav-pills li a:hover { 
 
    background-color: transparent; 
 
    color: #ffffff; 
 
    border-color: #ffffff; 
 
} 
 
.dropdown { 
 
    background-color: transparent; 
 
    color: #ffffff; 
 
    border-color: #ffffff; 
 
} 
 
.nav-pills > li > .dropdown-menu { 
 
    background-color: transparent; 
 
    border-color: #ffffff; 
 
} 
 
.dropdown-toggle { 
 
    background-color: transparent !important; 
 
} 
 
.dropdown-toggle:active, 
 
.open .dropdown-toggle { 
 
    background-color: transparent !important; 
 
    color: white !important; 
 
    border-color: #ffffff !important; 
 
} 
 
.nav-pills { 
 
    float: none; 
 
    margin: 0 auto; 
 
    display: block; 
 
    text-align: center; 
 
} 
 
.nav-pills > li { 
 
    display: inline-block; 
 
    float: none; 
 
} 
 
h1 { 
 
    position: absolute; 
 
    color: #ffffff; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="logo-container"> 
 
    <img alt="App" src="http://lorempixel.com/500/500/" class="logo" align="middle" > 
 
    <h2>Title goes here</h2> 
 
</div> 
 
<h1>App</h1> 
 
<ul class="nav nav-pills navbar-fixed-bottom"> 
 
    <li><a href="index.html">Home</a></li> 
 
    <li class="dropdown"> 
 
     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Apps <span class="caret"></span></a> 
 
     <ul class="dropdown-menu"> 
 
     <li><a href="app.html">App</a></li> 
 
     </ul> 
 
    </li> 
 
    <li> 
 
    <ul class="dropdown-menu"> 
 
    </ul> 
 
    </li> 
 
    <li><a href="contact.html">Contact</a></li> 
 
</ul>

+0

非常感謝!這很好! –