tags:

views:

50

answers:

2

I have the following HTML and CSS:

<button id="myBtn" dojoType="dijit.form.Button">Testing</button>

#myBtn {
    margin-left: 100px;
}

The CSS is supposed to push the button in 100px. But since dijit applies some extra layers of HTML around the button, the button gets a 100px padding.

JSbin to show the problem

edit: Found one (not IE6-compatible) solution:

[widgetid=myBtn] { margin-left: 100px; }
+1  A: 

In this case you should not add the margin-left to the button itselft but to the additional HTML araound the button that is created. Try this:

.dijitLeft{
    margin-left: 100px;
}

But this will indeed add a margin to every button. If you don't want that, add the margin to the parent span using JavaScript after the additional HTML was created.

Kau-Boy
That's such a pain, though. Isn't there any option in the parser that I can tell to move the `id` attribute to the top-most layer when it's applying HTML elements around the original one?
peirix
No unfortunately not. There is even no change to get an element with CSS that has some specific child node. But as you already use a JS framework it should be no problem to assign the CSS with this framework. But as I don't know the dojo framework I can't tell you how the function is called.
Kau-Boy
dojo.style() will assign styles dynamically. Perhaps you could also put your button in an HTML element with an ID or class and use that in a static style rule.
peller
@peller: moving the button into an elemten with an ID is an excellent idea! Than the button will not "jump" after using dojo.style().
Kau-Boy
@peller Yeah, that idea did cross my mind, I was just hoping there was a better and less "useless" way of doing it. I would now have to surround every button with a "useless" `<div>` or `<span>`... But that's better than using javascript on all buttons.
peirix
@peirix: using another element around the button will also fix it for IE6. And as far as I know IE6 supports some attribute selectors (at least an equal selector) but not on custom attributes.
Kau-Boy
Yup, and it also fixes another problem I had with dijit widgets, using the HTML5 `data-` attributes: http://stackoverflow.com/questions/3053713/keep-data-attributes-in-dijit-widgets @peller if you write your comment as an answer, I'll set it as accepted.
peirix
+2  A: 

see above :-) Surround with a DIV and use that DIV in your static CSS.

I think decorating with HTML may actually be a simpler solution than trying to bake more into the widget or the widget's template.

peller