对于HTML,为什么div标签内的内容需要与另一个div类“包装”?

时间:2015-02-22 23:13:06

标签: html

这可能是一个非常基本的问题,但我刚开始学习代码并完成Codecademy上的HTML和CSS跟踪。对不起,CSS就在最重要的位置。



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

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

.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;
}

<!DOCTYPE html>
<html>
  <head>
    <link href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/shift.css" rel="stylesheet">
    <link rel="stylesheet" href="main.css">
  </head>
  
  <body>
    <div class="nav">
      <div class="container">
        <ul>
          <li><a href="#">Airbnb logo</a></li>
          <li><a href="#">Browse</a></li>
        </ul>
        <ul>
          <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>
      </div>
    </div> 

    <div class="learn-more">
	  <div>
		<div>
	      <div>
			<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>
			<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>
			<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>
  </body>
</html>
&#13;
&#13;
&#13;

这是来自Codecademy的网站跟踪。之前我曾问过为什么每个类需要有这么多div来编辑CSS。我的问题是:为什么Codecademy在他们的例子中放了这么多div,比如div类&#34;了解更多&#34;?我删除了额外的div,看到构建的网页没有任何变化。也许有定位或我没看到的东西?

1 个答案:

答案 0 :(得分:1)

首先要理解的是HTML只是一种标记语言。因此,除了header, body, ul, figure等语法和一些复杂元素之外,div标签没有特殊功能。我建议你使用前端游乐场(比如codepen)并检查HTML的运行方式。额外的div可能对CSS或Javascript目的有用:

继续学习HTML的一些有用链接:

<强> HTML5doctor http://html5doctor.com/

MDN Mozilla参考 https://developer.mozilla.org/en-US/

Codepen (前端游乐场): http://codepen.io/