Chris
Chris

Reputation: 23

a tag inside div-class

Can I place <a href="#">test</a> inside <div class="test">

I am well aware of <div class="test"> <a href="#">test</a> </div> my problem with that code is that the a tag leaves some styling for me to do in the css and i would be happy to shrink down my code as much as possible.

Upvotes: 1

Views: 8094

Answers (1)

Obsidian Age
Obsidian Age

Reputation: 42384

Absolutely! There is no reason why an anchor can't reside within a div:

<div class="test">
  <a href="#">test</a>
</div>

Is perfectly valid syntax.

<body>
  <a class="test2" href="#">test</a>
</body>

Is also perfectly valid syntax.

It really just comes down to how you want to apply your styling. You can use either:

.test a {
  // Style the whole DIV, which can contain multiple <a> tags
}

Or:

.test2 {
  // Style the <a> tags that match the class `test2`.
}

Hope this helps! :)

Upvotes: 3

Related Questions