简体   繁体   English

为什么HTML5上的默认样式 <progress> 吧有垂直对齐?

[英]Why does the default styling on a HTML5 <progress> bar have vertical-align?

The default stylesheet for Webkit puts the vertical alignment on a <progress> element to be -0.2em. Webkit的默认样式表将<progress>元素上的垂直对齐方式设置为-0.2em。 Why -0.2em rather than 0? 为什么-0.2em而不是0?

Interesting question. 有趣的问题。 According to vertical-align documentation when the value is specified as a length then it 根据vertical-align 文档,当值指定为长度时,它

Aligns the baseline of the element at the given length above the baseline of its parent. 将给定长度的元素基线与其父元素的基线对齐。

By default the height of the progress element defined as 1em . 默认情况下, progress元素的高度定义为1em This means that making it -0.2em ensures that progress bar stays perfectly alligned vertically with adjacent inline/inline-block elements. 这意味着使其成为-0.2em可确保进度条与相邻的内联/内联块元素保持完美-0.2em

 var progress = document.querySelector('progress'); setInterval(function() { progress.classList.toggle('va0'); }, 2000); 
 body { font-size: 2em; } progress { width: 200px; } .va0 { vertical-align: 0; } div:after { position: absolute; top: 50px; content: '<progress> vertical-align: -0.2em'; } .va0 ~ div:after { content: '<progress> vertical-align: 0'; } 
 <progress></progress> Some text. <div></div> 

Try making progress bar vertical-align: 0 and you will see that it no longer looks nice next to its inline neighbors. 尝试使进度条vertical-align: 0 ,你会看到它的内联邻居旁边看起来不再好看了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM