html - 代码在 Codecademy 上完美呈现,但在 Firefox 中的本地主机上却不完美,有什么不同?

标签 html css twitter-bootstrap

我最近完成了 Codecademy 的 'Build a Professional Website'教程。我的代码在 Codeacademy 上看起来不错,并且通过了他们的所有测试。当我将代码保存在我的笔记本电脑上并在 Firefox 中打开它,从本地主机提供它时,'Neighborhood guides 下的五个框中的三个放错了地方。

这是 HTML 代码:

<!DOCTYPE html>
<html>

  <head>
    <link href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/shift.css" rel="stylesheet">

    <link rel="stylesheet" href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css">
    <link rel="stylesheet" href="/static/css/main.css">

  </head>

  <body>
    <div class="nav">
      <div class="container">
        <ul class="pull-left">
          <li><a href="#">Name</a></li>
          <li><a href="#">Browse</a></li>
        </ul>
        <ul class="pull-right">
          <li><a href="#">Sign Up</a></li>
          <li><a href="#">Log In</a></li>
          <li><a href="#">Help</a></li>
        </ul>
     </div>
    </div>

<div class="jumbotron">
  <div class="container">
    <h1>Find a place to stay.</h1>
    <p>Rent from people in over 34,000 cities and 192 countries.</p>
    <a href="#">Learn More</a>
  </div>
</div> 
<div class="neighborhood-guides">
    <div class="container">
        <h2>Neighborhood Guides</h2>
        <p>Not sure where to stay? 
            We've created neighborhood guides for cities 
            around the world.
        </p>
        <div class="row">
            <div class="col-md-4">
                <div class="thumbnail">
                    <img src="http://goo.gl/0sX3jq"
                </div>
                <div class="thumbnail">
                    <img src="http://goo.gl/an2HXY">
                </div>
            </div>
            <div class="col-md-4">
                <div class="thumbnail">
                    <img src="http://goo.gl/Av1pac" 
                </div>
                <div class="thumbnail">
                    <img src="http://goo.gl/vw43v1"
                </div>
            </div>
            <div class="col-md-4">
                <div class="thumbnail">
                    <img src="http://goo.gl/0Kd7UO"
                </div>
            </div>
        </div>
    </div>
</div>

<div class="learn-more">
  <div class="container">
    <div class="row">
      <div class="col-md-4">
        <h3>Travel</h3>
        <p>From apartments and rooms to treehouses and boats: stay in unique spaces in 192 countries.</p>
        <p><a href="#">See how to travel on Airbnb</a></p>
      </div>
      <div class="col-md-4">
        <h3>Host</h3>
        <p>Renting out your unused space could pay your bills or fund your next vacation.</p>
        <p><a href="#">Learn more about hosting</a></p>
      </div>
      <div class="col-md-4">
        <h3>Trust and Safety</h3>
        <p>From Verified ID to our worldwide customer support team, we've got your back.</p>
        <p><a href="#">Learn about trust at Airbnb</a></p>
      </div>
    </div>
  </div>
</div>

这是 CSS 代码(依赖于 twitter bootstrap):

.nav a {
  color: #5a5a5a;
  font-size: 11px;
  font-weight: bold;
  padding: 14px 10px;
  text-transform: uppercase;
}

.nav li {
  display: inline;
}

.jumbotron {
  background-image:url('http://goo.gl/04j7Nn');
  height: 500px;
}

.jumbotron .container {
  position: relative;
  top:100px;
}

.jumbotron h1 {
  color: #fff;
  font-size: 48px;  
  font-family: 'Shift', sans-serif;
  font-weight: bold;
}

.jumbotron p {
  font-size: 20px;
  color: #fff;
}

.learn-more {
  background-color: #f7f7f7;
}

.learn-more h3 {
  font-family: 'Shift', sans-serif;
  font-size: 18px;
  font-weight: bold;
}

.learn-more a {
  color: #00b0ff;
}

.neighborhood-guides{
    background-color: #efefef;
    border-bottom: 1px solid #dbdbdb;
}

.neighborhood-guides h2{
    color: #393c3d;
    font-size:24px;
}

.neighborhood-guides p{
    font-size: 15px;
    margin-bottom: 13px;
}

这里是用Python启动本地主机的方法

$ python -m SimpleHTTPServer

请告诉我如何解决此格式问题。感谢您的时间。

编辑:我能够使用我的 github.io 重现该问题 here .代码位于此 repository .唯一的区别是我在 HTML 中将/static/css/main.css 更改为 main.css。

最佳答案

您的 HTML 代码已损坏。您有四个缺少结束括号的图像标签。

例如:

<img src="http://goo.gl/0sX3jq"

应该是:

<img src="http://goo.gl/0sX3jq">

浏览器在解析代码的时候会一直继续下去,直到找到一个匹配的括号,这个括号会在后面的</div>的末尾标签。这反过来意味着下一个结束标签将关闭那个 div 标签而不是它外面的标签。它们不是让图像周围的 div 标签彼此嵌套,而是彼此嵌套。带有 class="learn-more" 的 div最终在 div 中嵌套了四层 class="neighborhood-guides" .

关于html - 代码在 Codecademy 上完美呈现,但在 Firefox 中的本地主机上却不完美,有什么不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24357010/

相关文章:

jquery - 使用 jquery 作为 css nth child 的替代品

javascript - Bootstrap/AngularJs : How to set bold attribute for the active selection of nav class?

javascript - Gulp watch 破坏了生产文件

javascript - divs/spans/p/img/a/tr/td/ul/li 等的正确名称

css - 子 Div float 在父之外

css - 使用数字导航调整简易 slider 1.7 版的宽度和高度

javascript - 当 iframe src 更改时如何运行函数?

css - 我们可以在不使用任何框架的情况下在 css 中给出 if else 条件吗

css - float /容器类的 Bootstrap 问题

php - 如何在 Twitter Bootstrap 模式窗口中通过 AJAX 加载内容?