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评论67阅读模式
英文:

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

问题

<!-- 开始代码片段:不隐藏 JS,显示控制台,不使用 Babel -->

<!-- 语言:CSS -->

div, a {
    height: 100px;
    width: 200px;
    border: 5px solid black;
    margin: 15px;
}

<!-- 语言:HTML -->

<div>这是一个 div 标签</div>
<a href="https://www.google.co.in" target="_blank">Google</a>

<!-- 结束代码片段 -->

我期望得到相同大小的框,但发现它们不同。
英文:

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

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

div, a {
    height: 100px;
    width: 200px;
    border: 5px solid black;
    margin: 15px;
}

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

&lt;div&gt;This is a div tag&lt;/div&gt;
&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中。

就像这样:

div, a {
    display: block;
    height: 100px;
    width: 200px;
    border: 5px solid black;
    margin: 15px;
}
英文:

Just add display: block; to your CSS.

Like this:

div, a {
    display: block;
    height: 100px;
    width: 200px;
    border: 5px solid black;
    margin: 15px;
}

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:

确定