Opened 12 years ago

Closed 12 years ago

#3582 closed defect (wontfix)

dojo.style inconsistent?

Reported by: dante Owned by: sjmiles
Priority: high Milestone: 1.0
Component: HTML Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description

in trying to document _base/html.js I noticed some weirdness in the way dojo.style works ... not sure if is bug or improper use, but various 'styles' get interpreted differently on different browsers. eg, margin and padding: supposed to be 4 sets of values or four styles (margin:4px 4px 4px 4px or margin-top:4px; margin-bottom:4px; etc.) setting margin:4px in CSS makes dojo.style return 0 for 'margin' in FF, but 4 in IE. colors in FF are returned as rgb(#,#,#) and #hex in IE ... in IE, a 'set margin' then calling getComputedStyle returns the 4 value string as expected, FF null.

testcase attached showing style info on a css-styled node, versus computedStyle of that node, then using dojo.style() to assign a style to a node, and then getting the new "style" value, and then re-running getComputedStyled ... some come back as undefined, some set styles and return nothing.

and cannot determine any useful way to know a node's border-properties, but can be set via dojo.style(node,"borderColor","#000") or borderWidth or borderTop ... though dojo.style returns null for each of the above.

Attachments (1)

style.html (3.4 KB) - added by dante 12 years ago.

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by dante

Attachment: style.html added

comment:1 Changed 12 years ago by Adam Peller

Owner: changed from Bryan Forbes to sjmiles

comment:2 Changed 12 years ago by sjmiles

Status: newassigned

When setting properties, dojo.style is using a CSSStyleDeclaration interface (viz. node.style). That interface allows you to set properties using shorthand notations, e.g. "margin: 2px" is actually setting all four margin properties.

When inspecting properties dojo.style is using a CSS2Properties interface (viz. getComputedStyle). Therefore combined properties like "margin" or "border" are (generally) not available. Only specific properties should be queried, e.g., "marginLeft" or "borderRightWidth" (see the property list linked above).

Note that for common metrics, dojo.style attempts to return (numeric) pixel values parsed out of the strings that would normally be returned from getComputedStyle. By the same token, I imagine colors should be normalized. Todo: make a separate ticket for that.

All this flows from the way CSS support is designed on browsers. Fwiw, personally, I'm not fond of dojo.style, because these details become magic (but therefore also convenient).

comment:3 Changed 12 years ago by sjmiles

Summary: dojo.style horribly inconsistant?dojo.style inconsistent?

comment:4 Changed 12 years ago by sjmiles

Resolution: wontfix
Status: assignedclosed
Note: See TracTickets for help on using tickets.