why resultant(after running html/css code) box sizes are different for div and a tag when applied the same set of properties?

huangapple go评论106阅读模式
英文:

why resultant(after running html/css code) box sizes are different for div and a tag when applied the same set of properties?

问题

  1. <!-- 开始代码片段:不隐藏 JS,显示控制台,不使用 Babel -->
  2. <!-- 语言:CSS -->
  3. div, a {
  4. height: 100px;
  5. width: 200px;
  6. border: 5px solid black;
  7. margin: 15px;
  8. }
  9. <!-- 语言:HTML -->
  10. <div>这是一个 div 标签</div>
  11. <a href="https://www.google.co.in" target="_blank">Google</a>
  12. <!-- 结束代码片段 -->
  13. 我期望得到相同大小的框,但发现它们不同。
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

  1. div, a {
  2. height: 100px;
  3. width: 200px;
  4. border: 5px solid black;
  5. margin: 15px;
  6. }

<!-- language: lang-html -->

  1. &lt;div&gt;This is a div tag&lt;/div&gt;
  2. &lt;a href=&quot;https://www.google.co.in&quot; target=&quot;_blank&quot;&gt;Google&lt;/a&gt;

<!-- end snippet -->

I expected to get the same size of boxes but found different ones.

答案1

得分: 0

只需将display: block;添加到您的CSS中。

就像这样:

  1. div, a {
  2. display: block;
  3. height: 100px;
  4. width: 200px;
  5. border: 5px solid black;
  6. margin: 15px;
  7. }
英文:

Just add display: block; to your CSS.

Like this:

  1. div, a {
  2. display: block;
  3. height: 100px;
  4. width: 200px;
  5. border: 5px solid black;
  6. margin: 15px;
  7. }

huangapple
  • 本文由 发表于 2023年6月8日 03:21:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定