Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can CSS be applied to components from Google Closure Library?

I'm getting my feet wet with Google's Closure Library. I've created a simple page with a Select Widget, but it clearly needs some styling (element looks like plain text, and in the example below the menu items pop up beneath the button).

I'm assuming the library supports styles -- how can I hook into them? Each example page in SVN seems to use its own CSS.

Abbreviated example follows:

<body>

<div id="inputContainer"></div>

<script src="closure-library-read-only/closure/goog/base.js"></script>
<script>
    goog.require('goog.dom');
    goog.require('goog.ui.Button');
    goog.require('goog.ui.MenuItem');
    goog.require('goog.ui.Select');
</script>
<script>
    var inputDiv = goog.dom.$("inputContainer");

    var testSelect = new goog.ui.Select("Test selector");
    testSelect.addItem(new goog.ui.MenuItem("1"));
    testSelect.addItem(new goog.ui.MenuItem("2"));
    testSelect.addItem(new goog.ui.MenuItem("3"));
    var submitButton = new goog.ui.Button("Go");

testSelect.render(inputDiv);
submitButton.render(inputDiv);
</script>

</body>
like image 860
Jason Avatar asked Dec 26 '09 13:12

Jason


3 Answers

In practice, the search for the right CSS should start with the demo page for the widget you want to use. By examining the HTML of the page, it should be easy to identify the stylesheets that the demo depends on by finding the tags. In the case of goog.ui.HoverCard, the appropriate elements from hovercard.html are:

<link rel="stylesheet" href="css/demo.css">
<link rel="stylesheet" href="../css/hovercard.css">

Ignore css/demo.css, which defines CSS rules to ensure that the look of the demo pages is consistent, so most of the code in css/demo.css is specific to the demos, not the widget, so it should not be included in your application. Do not forget to look at css/common.css, which contains a display inline block xbrowser implementation, which many widgets use.

like image 140
Daniel Steigerwald Avatar answered Oct 19 '22 19:10

Daniel Steigerwald


I just use incantations like (for your case):

<link rel="stylesheet" href="closure-library/closure/goog/demos/css/menubutton.css"> 

There doesn't seem to be a better way, although I haven't found any explanation behind having the styles in demos/ dir...

like image 39
Nickolay Avatar answered Oct 19 '22 19:10

Nickolay


Closure adds a series of CSS classes to the HTML nodes and the library provides several CSS to give components a style.

I suggest you go through the source of the demos and find out the css ids and classes. Or figure out the id's / classes using Firebug (for firefox) or IE Developer Tools (for Internet Explorer 7/8) and then style them using your own CSS.

like image 1
user297006 Avatar answered Oct 19 '22 17:10

user297006