2015-04-12 48 views
-1

我创建了一个带有包含图像的标题的示例页面。但该页面没有响应。我将类img-responsive添加到img标签,但它不响应。下面是代码:Twitter Boostrap 3页无响应

<!DOCTYPE html> 
<html> 
    <head> 
     <title>A Sample Bootstrap Page</title> 
     <meta charset="utf-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
     <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> 
     <link href="css/style.css" rel="stylesheet"> 
     <script src="http://code.jquery.com/jquery.js"></script> 
     <script src="js/bootstrap.min.js"></script> 
    </head> 
    <body> 
     <div class="container"> 
      <div class="page-header" id="header"> 
       <img id="logo" src="img/logo.png" height="100" alt="Image" class="img-responsive"> 
       <p>Some text here</p> 
      </div> 
     </div> 
    </body> 
</html> 

的style.css中包括下列各项:

#header #logo 
{ 
    display: block; 
    margin-left: auto; 
    margin-right: auto; 
} 
+0

你是用硬编码高度IMG高度= “100”,删除下手。 –

+0

'style.css'是否包含'.page-header'的任何样式? – Last1Here

+0

@ Last1Here style.css只包含#header #logo定义 –

回答

0

卸下img标签高度= “100” 如上述提出并添加到您的style.css

#header #logo { 
    display: block; 
    margin-left: auto; 
    margin-right: auto; 
    height: 100px; 
} 

对于图像不响应,确保引导样式.IMG响应正在使用

萤火/开发工具,你应该看到一个类的

.img responsive { 
    max-width: 100%; 
    height: auto; 
    display: block; 
} 

至于解决您的问题,我会很高兴来解决它,如果你可以做一个codepen /片断例子给我看看/看

0

你应该这样做,即使不需要使用自定义类风格,bootstrap提供了足够的。

<div class="container-fluid"> 
    <div class="row"> 
     <div class="col-xs-12"> 
     <img src="http://lorempixel.com/1900/100/" alt="" class="img-responsive"> 
     </div> 
    </div> 
    </div> 

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="//code.jquery.com/jquery.min.js"></script> 
 
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> 
 
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> 
 
    <meta charset="utf-8"> 
 
    <title>JS Bin</title> 
 
</head> 
 
<body> 
 
    <div class="container-fluid"> 
 
    <div class="row"> 
 
     <div class="col-xs-12"> 
 
     <img src="http://lorempixel.com/1900/100/" alt="" class="img-responsive"> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</body> 
 
</html>

+0

我只是推荐使用“容器”类作为Java Enthusiast做的“容器流体”类的宽度:100%不像“容器”。 – TeeJay

+0

你能澄清你的答案,这种方法是不同的,为什么它更好?没有评论的仅有代码的答案很少有用。 – Mast