J.E.C.
J.E.C.

Reputation: 3012

For HTML, why does content inside div tags need to be "wrapped" with another div class?

This is probably a really basic question, but I just started learning code and finished the HTML and CSS track on Codecademy. Sorry for the CSS being on top.

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

This is from the build a website track on Codecademy. Earlier I asked why there needed to be so many divs for each class to edit in CSS. My question is this: why does Codecademy put in their example so many divs, say for the div class "learn more"? I deleted the extra divs and saw nothing happen to the constructed webpage. Maybe there is positioning or something I'm not seeing?

Upvotes: 0

Views: 96

Answers (1)

Miguel Garrido
Miguel Garrido

Reputation: 1151

First thing to understand is that HTML is just a Markup language. So apart of syntax and some complex elements such as header, body, ul, figure etc there's no special function for the div tag. I would recommend you to use front-end playgrounds (like codepen) and check how you HTML goes. An extra div might be useful for CSS or Javascript purpose:

Some useful links to carry on learning HTML:

HTML5doctor http://html5doctor.com/

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

Codepen (Front-end Playground): http://codepen.io/

Upvotes: 1

Related Questions