[ 5 posts ]

Kristopher Bishop

  • Username: douloscristou
  • Joined: Fri Apr 16, 2010 12:10 pm
  • Posts: 34
  • Location: St. Louis, MO
  • Offline
  • Profile

Help manipulating stylesheet

Post Posted: Fri Aug 26, 2011 7:22 pm
+0-
Since the Layout Manager widget doesn't yet exist, I'm trying to create some code that mimics it's basic behavior (no animation, just creates the basic layout). So far I have the following:

Code:
    YUI().use('node','stylesheet',function(Y){
        //Afix the footer to the bottom of the screen
        var head=Y.one('#header');
        var headDim=head.get('region');
        var main=Y.one('#main');
        var foot=Y.one('#footer');
        var footDim=foot.get('region');
        var view=main.get('viewportRegion');
        var mainHeight=view.height-headDim.height-footDim.height;
        main.setY(headDim.height);
        main.setStyle('height',mainHeight);
        foot.setY(view.height-footDim.height);
        var myStyles=Y.StyleSheet('myStyles');
        myStyles.set('#container',{minHeight:mainHeight});
        myStyles.set('#sidebar',{minHeight:mainHeight});
        myStyles.set('#content',{minHeight:mainHeight});
    });


Everything is working except for the min-height of container, sidebar, and content property being set in the stylesheet. I have to set the min-height using the stylesheet because not all screens will have a sidebar and the element won't always exist when this code runs.

The code is not producing any errors, but it is not working either (when I check the stylesheet the min-height property does not exist.

I am guessing the problem is the way I am referencing the id of the rule to update. All the examples I found were updating classes and not the named element. I tried it with and without the # but no dice either way.

Any help or insight would be greatly appreciated.

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 619
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile

Re: Help manipulating stylesheet

Post Posted: Sat Aug 27, 2011 7:22 am
+0-
There is a Layout widget in the Gallery that seems to work very well. Here's an example: http://axosoft.github.com/yui3-gallery/ ... ayout.html

Kristopher Bishop

  • Username: douloscristou
  • Joined: Fri Apr 16, 2010 12:10 pm
  • Posts: 34
  • Location: St. Louis, MO
  • Offline
  • Profile

Re: Help manipulating stylesheet

Post Posted: Sat Aug 27, 2011 7:47 pm
+0-
Thanks. I looked at that before, but I thought I would rather write my own as I really do not need anything that complex. Just a fixed header/footer and in certain contexts a left hand sidebar. The header/footer were easy enough, but the sidebar only exist in certain contexts which is why changing the stylesheet should be a good solution. If I set the min-height property in css, it functions just the way I need it to. The problem is I need to set the min-height property dynamically based on the viewport. You can't do this for an element that doesn't exist in the DOM yet, but manipulating the stylesheet should do the trick if I can figure it out.

All the examples seem to show using classes instead of the id. That wasn't my preference but I'll give that a try and see if it makes a difference.

Francesco Pongiluppi

YUI Contributor

  • Username: willywongi
  • Joined: Fri May 15, 2009 4:28 am
  • Posts: 41
  • GitHub: willywongi
  • Gists: willywongi
  • Offline
  • Profile

Re: Help manipulating stylesheet

Post Posted: Mon Aug 29, 2011 4:49 am
+0-
Ciao Kristopher,
I would suggest you to avoid messing up with the stylesheets in javascript. Everytime you touch the definitions the browser would redraw the entire page, even if you don't really change a thing. This could be a huge performance problem. Beside that, the browser oddities in handling the stylesheet rules are a pain that could kill that "not that complex" solution.

Try to use the -debug version and look for the warnings that the StyleSheet module throws (maybe it's a somehow invalid selector).

If anything else helps, use that gallery module ;-)

Kristopher Bishop

  • Username: douloscristou
  • Joined: Fri Apr 16, 2010 12:10 pm
  • Posts: 34
  • Location: St. Louis, MO
  • Offline
  • Profile

Re: Help manipulating stylesheet

Post Posted: Thu Oct 27, 2011 6:57 pm
+0-
I "sort of" figured out the problem. The part of the code that is not working is the part that references my existing style sheet. If I delete the container, sidebar, and content elements from my existing css sheet and remove the reference to myStyles then all works as expected.
  [ 5 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