如何判断元素是使用Java脚本还是工具建立了新的块格式上下文? [英] How can I tell whether an element establishes a new block formatting context using Javascript or a tool?

查看:32
本文介绍了如何判断元素是使用Java脚本还是工具建立了新的块格式上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些元素建立了新的以获取更多信息.

除此之外,在以前的问题中还有一些有趣的建议,例如,讨论我认为大致相同的问题.

Some elements establish a new block formatting context, depending on whether they meet certain conditions. Understanding this is quite important to be able to use floats correctly in CSS, among other things.

I would like a tool to see whether a given element does establish a new block formatting context. An additional line of text in the inspector tool of Firefox like this would be ideal: Apparently, a tool like this does not exist.

If since something like this doesn't already exist in a browser, I would like to develop an extension that does this myself, and to do that, I will need to be able look at each element using Javascript. Is there a DOM API call that will tell me whether a certain element establishes a new block formatting context? Something like this would be ideal:

var res = doesElementEstablishNewBlockFormattingContext(document.getElementById("foo"));

If not, I could check with Javascript whether all the conditions are met, but that would be a last resort.

TLDR: Is there already a tool or extension or an API call that will tell me if an an element establishes a new block formatting context?

解决方案

Something like this, but not exactly this, exists in Internet Explorer. As a proprietary part of the IE rendering engine the hasLayout property is used. It corresponds, roughly, to the creation of a new block formatting context.

console.log(document.getElementById("id").currentStyle.hasLayout) will show you what IE thinks. Read this blog post for more information.

Aside from that, there are some interesting suggestions in previous questions like this one, discussing what I think is roughly the same problem.

这篇关于如何判断元素是使用Java脚本还是工具建立了新的块格式上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆