[ 7 posts ]

Lewis Valentine

  • Username: lewisvalentine
  • Joined: Sat Feb 04, 2012 9:59 am
  • Posts: 20
  • Offline
  • Profile

Get.css and insertBefore

Post Posted: Tue Aug 07, 2012 6:14 am
+0-
I am dynamically loading a css page after a user logs in.

But I can not figure out how to load and and override the defualt yui css.
I have read about insertBefore but I can not get it to work.

I have
<style id="styleoverrides" type="text/css"></style>

as the first item in the body

then in my js i call.
var options = {
insertBefore: 'styleoverrides'
};
Y.Get.css(data.css, options);

- data.css contains my css file name

i am trying to override an accordion node object that is created a little later in the script.
How do i do this?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: Get.css and insertBefore

Post Posted: Tue Aug 07, 2012 6:39 am
+0-
What you have to do is make sure that you inject your CSS after where YUI injects it.

I would suggest doing this:

* Create a `yui-inject` element in head and set your YUI config to `insertBefore` that element.
* Create your `styleoverrides` element after that in the DOM.
* Then when using `Y.Get.css` with the overrides you can be certain that your css is always after YUI's injected CSS.

Make sense?

Lewis Valentine

  • Username: lewisvalentine
  • Joined: Sat Feb 04, 2012 9:59 am
  • Posts: 20
  • Offline
  • Profile
Tags:

Re: Get.css and insertBefore

Post Posted: Tue Aug 07, 2012 8:39 am
+0-
Yes and No
I understand what we are trying to do, but exactly the way is alluding me.

I have
<link id="yuiinject" />
before any css links in the head ( i tried it after as well)
I have
<style id="styleoverrides" type="text/css"></style>
after my head closes and before the body

My script
YUI({
insertBefore: 'yuiinject',
...
}).use( ...

and my get.css - called after a io calls and stuff

var options = {
insertBefore: 'styleoverrides'
};
Y.Get.css(data.css, options);

I can look in firebug and see where my css is overridden by the yui css classes
What am I missing?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile
Tags:

Re: Get.css and insertBefore

Post Posted: Tue Aug 07, 2012 10:04 am
+0-
Can you post an example to jsfiddle.net so I can see it? That config looks right, but your override CSS might not be specific enough to overwrite the YUI CSS.

Lewis Valentine

  • Username: lewisvalentine
  • Joined: Sat Feb 04, 2012 9:59 am
  • Posts: 20
  • Offline
  • Profile
Tags:

Re: Get.css and insertBefore

Post Posted: Tue Aug 07, 2012 1:59 pm
+0-
Ok here is the link on jsFiddle

http://jsfiddle.net/EKFZW/

I don't know how well it translates since i am loading the css on the fly
On my side the padding of 0px is being overridden by the yui3 padding of 5px

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile
Tags:

Re: Get.css and insertBefore

Post Posted: Tue Aug 07, 2012 2:19 pm
+0-
From your simple example, it looks like your extra CSS is not specific enough.

You are using:

Code:
.yui3-accordion-item-hd {
  //Rules
}​


When you should be using:

Code:
.yui3-skin-sam .yui3-accordion .yui3-accordion-item .yui3-accordion-item-hd {
  //Rules
}​


You need to be at a greater specificity than the original rule to override it.

Lewis Valentine

  • Username: lewisvalentine
  • Joined: Sat Feb 04, 2012 9:59 am
  • Posts: 20
  • Offline
  • Profile

Re: Get.css and insertBefore

Post Posted: Wed Aug 08, 2012 4:10 am
+0-
that did it thanks!
  [ 7 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum