Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 为什么svg的span with height:auto和display:inline块父级的高度比其svg子级的高?_Html_Css_Svg - Fatal编程技术网

Html 为什么svg的span with height:auto和display:inline块父级的高度比其svg子级的高?

Html 为什么svg的span with height:auto和display:inline块父级的高度比其svg子级的高?,html,css,svg,Html,Css,Svg,简单问题: 父项:span带显示:内联块和宽度和高度设置为自动 子项:svg,将高度和宽度设置为35px 问题: 为什么span获取高度=39px(请参见下面的图片和代码片段) const svg=document.getElementById('svg1'); const svgStyle=window.getComputedStyle(svg); const span=document.getElementById('span1'); const spanStyle=window.

简单问题:

  • 父项
    span
    显示:内联块
    宽度
    高度
    设置为
    自动

  • 子项:
    svg
    ,将
    高度和
    宽度设置为
    35px


问题:

为什么
span
获取高度=
39px
(请参见下面的图片和代码片段)

const svg=document.getElementById('svg1');
const svgStyle=window.getComputedStyle(svg);
const span=document.getElementById('span1');
const spanStyle=window.getComputedStyle(span);
const p=document.getElementById('p1');
p、 innerHTML=`
svg宽度=${svgStyle.width}
svg高度=${svgStyle.height}
span width=${spanStyle.width}

span height=${spanStyle.height}如果使用
元素的
垂直对齐
属性,则
将是所需的高度。我很幸运地在svg元素中使用了
bottom
top

检查垂直对齐上的MDN