prepend HTML and CSS selectors with unique ID

158 views
Skip to first unread message

dl

unread,
Oct 4, 2011, 4:36:06 PM10/4/11
to phpQuery
I've just found and downloaded phpQuery to try out .. so I'm new to
its usage.

My google search was "php prepend css selectors" ...

Here is what I would like to try ..

Load two documents .. an HTML doc and a CSS style sheet .. and prepend
selectors each with a unique ID (to ensure uniqueness of embedded CSS
style amongst others in a drupal-7.8 PHP platform).

I do not want to use inline styles in the embedded HTML .. so the HTML
documents and linked CSS stylesheets both have to be parsed to change
the selectors throughout to be unique (by prepending a unique string).

Here is the jQuery equivalent I've found .. http://api.jquery.com/prepend/

I would appreciate some tips/examples to get started in phpQuery ..

load two documents (HTML and CSS)
prepend selectors
save documents




Nicolas VINCENT - JAM Difus

unread,
Oct 5, 2011, 3:20:58 AM10/5/11
to phpq...@googlegroups.com
Hello,

You can't parse CSS using phpQuery.
Anyway, I'm not sure to understand what you're trying to do...

2011/10/4 dl <dl.l...@ntlworld.com>




--
You received this message because you are subscribed to the Google Groups "phpQuery" group.
To post to this group, send email to phpq...@googlegroups.com.
To unsubscribe from this group, send email to phpquery+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/phpquery?hl=en.


dl

unread,
Oct 5, 2011, 5:53:51 AM10/5/11
to phpQuery
Thanks for at least confirming that phpQuery cannot parse css.

I now see that phpQuery follows the DOM model. So I really need a css
parser instead of phpQuery.

However I will explain what I'm trying to do.

To modify selectors in (embedded) HTML / CSS files so that the local
style (for the embedded content only) does not conflict with other
parent styles (e.g. as in a drupal site which has many other styles).

i.e. to create a localised style for content which can be embedded
into a region in a parent style.

Following the rules of CSS specificity the only way of avoiding CSS
conflicts (i.e. conflicts with higher level styles) is

EITHER
to use inline CSS in the HTML tags (not the best way to go)

OR
to prepend or append some unique string to each selector to ensure
that the style is unique.

e.g. "h2" becomes "h2_id_01" etc.

I do not want to permanently change the HTML and CSS syntax so I am
loading the html / css files through an html + css parser (php proxy)
which reads the html + css file, parses and returns the modified
content to be rendered by browser.

I have found another way which might solve this problem and that is to
use dynamic CSS using php.
And/or I can use a css parser php class.

I will still explore other uses of phpQuery.

Thanks.

Reply all
Reply to author
Forward
0 new messages