This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Make a Website: HTML Forum

View Course » View Exercise

210 points
4ada5643d901a006e8e5b248776055c3?s=140&d=retro
Submitted by
afsaja
over 2 years ago

[resolved] Why should we wrap the <a> element with a <p> element. What is the purpose of it?

<!DOCTYPE html>
<html>
  <body>

   <div class="nav">
    <div class="container">
    <ul>
      <li>Item 1</li>
    </ul>
    <ul>
      <li>Sign Up</li>
      <li>Log In</li>
      <li>Help</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>
     <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>
  </body>
</html>

0 votes

permalink

Hi afsaja,

  • the styles of the p elements could give a more consistent look to your page
  • a elements are inline and p elements are block. This will affect layout and positioning.

In your exercise, compare how these two examples look when you view the resulting web page:

      <a href="#">see how to travel on Airbnb</a>
      <a href="#">see how to travel on Airbnb</a>
      <a href="#">see how to travel on Airbnb</a>

with

      <p><a href="#">see how to travel on Airbnb</a></p>
      <p><a href="#">see how to travel on Airbnb</a></p>
      <p><a href="#">see how to travel on Airbnb</a></p>

3698 points
55df2afa95e3787b9200005e_359368177
Submitted by
Judy
over 2 years ago

5 Comments

4ada5643d901a006e8e5b248776055c3?s=140&d=retro afsaja over 2 years ago

Ok. Yes I see the difference. Thanks for the clarification. So it only has to do with style and layout and not necessarily needed?

55df2afa95e3787b9200005e_359368177 Judy over 2 years ago

I think that I can agree with you on that.

F372e6d607735cba858a0d8d2755dd22?s=140&d=retro Sandhya Saravanan over 2 years ago

@AlbionsRefuge couldn't we simply use the tag to position the links one below the other, adjusting the layout, assuming we're using only the tag and not the tag. It's probably easier using the tag, just asking.

55df2afa95e3787b9200005e_359368177 Judy over 2 years ago

Hi Sandhya, you could do that. This isn't the best example really. It is more likely that for a list of links one would create ul and li elements. When you are writing the HTML code you shouldn't be worried about how it looks but more about what it means. Then you use the CSS to take care of how it looks. You just have to make sure that you've used elements that behave the way you want and that you can then target with your CSS selectors.

F372e6d607735cba858a0d8d2755dd22?s=140&d=retro Sandhya Saravanan over 2 years ago

Oh right. Thanks a lot! :D