Using Twitter Bootstrap CSS styles inside custom elements

1,173 views
Skip to first unread message

Leandro Cruz

unread,
Jul 7, 2014, 9:44:46 AM7/7/14
to webcom...@googlegroups.com
Hi all,

I installed a new Linux distro, and with it a new Chrome (35.0.1916.153). Before that, all styles defined in Twitter Bootstrap were inherited by my custom elements. Now, with the new Chrome, that's not the case anymore.

Is it possible to override the default css inheritance behavior? I don't want to change Twitter Bootstrap to use /deep/ and make it work. Also, I can't compose my elements easily and style them from "outside" without css inheritance. Example:

<my-page><my-menu></my-menu></my-page>

I can't write my css like this (my-page my-menu .menu {width: 100px;}), becase <my-menu> belongs to <my-page> shadow dom.

Am I missing something?

--
Leandro

Eric Bidelman

unread,
Jul 7, 2014, 12:55:47 PM7/7/14
to webcom...@googlegroups.com
See http://stackoverflow.com/questions/24108315/bootstrap-styles-not-applying-within-a-shadow-dom-on-chrome-35

Style scoping is a core feature of Shadow DOM. You'll need to either include boostrap's css in your element (so the selectors are picked up), or modify it to use ::shadow and /deep/.


--
You received this message because you are subscribed to the Google Groups "Web Components Organisation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webcomponent...@googlegroups.com.
To post to this group, send email to webcom...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/webcomponents/db0442af-5c83-4a61-8d01-2f8de3001fd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leandro Cruz

unread,
Jul 8, 2014, 8:32:04 AM7/8/14
to webcom...@googlegroups.com
Hi Eric,

Thanks for your quick reply. I added "body /deep/" to my bootstrap.css file. It's a painful experience. I think there are two solutions for this problem:

1. The Twitter Bootstrap team will provide a polymer version of their components, or
2. Add an attribute, when you import the css file, telling the browser that all selectors/rules defined in that resource should "bleed" into custom components/shadow dom.

What do you think?

--
Leandro Rodrigo Saad Cruz

Eric Bidelman

unread,
Jul 8, 2014, 9:30:29 AM7/8/14
to webcom...@googlegroups.com

Have you tried including bootstrap.css in your component. That will be the least amount of pain.

--
You received this message because you are subscribed to the Google Groups "Web Components Organisation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webcomponent...@googlegroups.com.
To post to this group, send email to webcom...@googlegroups.com.

Revath S Kumar

unread,
Jul 8, 2014, 11:12:25 AM7/8/14
to webcom...@googlegroups.com
Eric,

If I have more than one component depending on bootstap.css, this may lead
to duplicate request right?
I hope browser will handle this and serve it from cache for the second
request onwards.



For more options, visit https://groups.google.com/d/optout.



--
with regards,
Revath S Kumar,
Rubyist / JavaScripter / PHP

markdownblogger.herokuapp.com

www.phprepo.in

    
     normal-1.png

Eric Bidelman

unread,
Jul 8, 2014, 6:05:22 PM7/8/14
to webcom...@googlegroups.com
Resources from the same URL are only requested by the browser once. Try loading jquery.js twice on the page: 

<script src="/path/to/jquery.js"></script>
<script src="/path/to/jquery.js"></script>

You'll only see one request.


Reply all
Reply to author
Forward
0 new messages