如何编写干净的 HTML?

问题描述 投票:0回答:1

我正在学习 HTML 和 CSS。有些老师说你应该使用大量的 div 和类,而另一些老师则持相反的观点,建议不要使用太多的 div 和类。我应该使用哪一个? 例子:

<section class="section-pricing">
          <div class="container">
            <span class="subheading">Pricing</span>
            <h2 class="heading-secondary">Eating well without breaking the bank</h2>
  
          
          </div>
</section> 

VS

<section class="section-pricing">
          <div class="container">
            <span>Pricing</span>
            <h2>Eating well without breaking the bank</h2>
  
          
          </div>
</section> 
html css frontend coding-style
1个回答
0
投票

使用 div 包含用于样式和编码的内容。应该有一个快乐的媒介。

就像在每个元素上使用容器 div 一样,如果该容器无用,那么就不干净。您始终可以在事物上使用

ID's
,而不是使用大量 div。
ID's
也适合根据您正在做的事情进行编码。

© www.soinside.com 2019 - 2024. All rights reserved.