byronyasgur
byronyasgur

Reputation: 4747

Is there a css selector based on whether an element has a particular property?

I am working with Magento which doesn't allow for classes on images in the visual editor; so I want to program it to automatically apply right margin to an image if the image has the property float:left ... and visa versa. Is this possible without using javascript?

Upvotes: 0

Views: 967

Answers (3)

Paulo R.
Paulo R.

Reputation: 15619

Assuming all of your styles are placed in an external stylesheet the answer's 'not without javascript'.

If, however, you're placing that specific style on the html (inline styles, that is) then what Kolink suggested does work.

Anyway, using javascript(jQuery) here's a possible solution: http://jsfiddle.net/joplomacedo/TECWM/
If you can't see the fiddle, it goes something like this:

    if (el.css('float') === 'left') {
        el.css({
            'margin-left': '50px'
        });
    }

Upvotes: 0

Zeta
Zeta

Reputation: 105955

No, there isn't a selector based on CSS properties, apart from scanning selecting on the style attribute - after all you set them with CSS.

The easiest way would be to set the margin-right property at the same place where you set the float property.

See also:

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324790

If it's part of the style attribute, then sure: [style*='float:left']

Upvotes: 3

Related Questions