Apps in App Lab are composed of HTML elements, such as buttons. While these elements can be styled to some extent using the Design Tab, more advanced styling (or any styling of programmatically created elements) can be achieved by using CSS. This advanced function allows assigning CSS styles to HTML design elements in an app.
Apply several different styles to a single element
setStyle("fancyButton", "font-family: monospace;"); setStyle("fancyButton", "font-size: 40px;"); setStyle("fancyButton", "font-weight: bold;"); setStyle("fancyButton", "border-radius: 50px;"); setStyle("fancyButton", "background: linear-gradient(red, yellow);"); setStyle("fancyButton", "border: 2px solid red");
Apply style to make a programmatically created text label bold and large.
textLabel("myLabel", "some text to style"); setStyle("myLabel", "font-weight: bold; font-size: 30px;");
setStyle(id, css)
Name | Type | Required? | Description |
---|---|---|---|
id | String | The ID of a design element to be styled. | |
css | String | A string of CSS, using inline syntax. |
Found a bug in the documentation? Let us know at documentation@code.org