If I have a table cell that's X pixels high, can I see what exactly makes it so – whether it's the height of a sibling <td>
or it has a child div
somewhere with the height of X pixels?
Basically, I have and I want to see why it's 172 pixels and not, say, 150. The height is never set explicitly in code.
Is there a browser extension somewhere that shows this kind of thing, and saves me the trouble of clicking through each child/sibling node to inspect it CSS?
Edit: I already know that most browsers have built-in DOM inspectors. However, not all CSS attributes are inherited or set directly on the element, as I've said in my first paragraph. I'd like to know if there is a better tool that shows the way an attribute is computed.
CSS properties such as height , width , border , margin , padding , etc. are not inherited.
Inherited properties When no value for an inherited property has been specified on an element, the element gets the computed value of that property on its parent element. Only the root element of the document gets the initial value given in the property's summary.
The computed value of a CSS property is the value that is transferred from parent to child during inheritance. It is calculated from the specified value by: Handling the special values inherit , initial , revert , revert-layer , and unset .
There is no easy way to narrow down which element is causing a parent element to change its height. Depending on the situation, it could be a direct style applied to the parent element, it could be one child, or many of the children combined. Most browsers have tools built-in or available via an Add-on that can help make the task of tracking down the problematic style easier, but not quite "easy."
Note that in Firebug, when you have the selection tool enabled, it will outline the element under your cursor showing you on the page the how large the element is (as if you applied a border: 2px solid blue
style to it. It will also highlight the respective element in the HTML inspector so you know exactly which element you're dealing with. While this isn't going to magically say "oh hey, this particular element and style is the one giving you problems" it will help you get a clearer visual on the problem.
Typically I would just highlight the nodes in the DOM tree in the developer console however I occasionally come across oddities with height
myself so this will be a nice tool to have at my disposal from this point onward. There were some technicalities to consider how this works:
childNodes
only apply to the first generation of descendants though not also their child nodes.scrollHeight
. Things like getComputedStyle
will return the visually rendered height though not the fully rendered height.return false
if there are no descendant elements.To use just call something such as element_find_descendant_tallest(document.getElementById('test1'));
.
function element_find_tallest_descendant(e)
{
var walker = document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,null,false),
height_current = 0;
tallest = false;
while (walker.nextNode())
{
var n = parseInt(walker.currentNode.scrollHeight);
if (n != 'NaN' && n > height_current)
{
height_current = n;
tallest = walker.currentNode;
//Update console every time new tallest descendant found:
console.log(walker.currentNode);
console.log(n);
console.log('---');
}
}
return tallest;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With