Hi Everyone! Welcome to the 6th and final post in the HTML series. If you have just stumbled onto this post, use the links below to catch up on the series.
CSS with Style
This post picks up where post 4 left off with CSS. To review, CSS can be written in
3 ways 4 ways (updated 4/24/2018).
- Inside an HTML tag using the style attribute (see post Containers and Style Attributes).
- Inside a style tag.
- In a separate CSS file.
This blog post is going to focus on CSS in a style tag. I will break it down into 4 parts.
- Example of CSS in a style tag
- Explanation of the basic syntax and rules
- Other syntax and rules
- Explanation of how to decipher the “Spotfire” elements
Let’s start off with an example so you have a frame of reference. Download this Ruths.ai template NFL Expectancy Win Calculator. (Note: The button says subscriber-only, but click it anyway. It will take you to a different website. You might have to create an account, but the template is free.). Go to the Expected Wins Page. In the Pythagorean Win Expectancy Text Area, right-click and select Edit HTML to see the code… A LOT of code. Scroll down in the sample template to make sure you know where the end is. I’ve taken a small screenshot below. This was all written by Lucas Wood of Ruths.ai.
In this example, the code is controlling the appearance of the entire template. It can be copied and pasted into other DXPs to achieve the same look and feel. Next, let’s look at the rules and structure for writing this type of code.
It’s very simple syntax that consists of a selector and a declaration block. The declaration block uses property-value pairs where the property and value are separated by a colon and multiple property-value pairs are separated by semi-colons. The declaration block itself is wrapped in squiggly braces.
Now, selectors are important. They find HTML elements and format all elements of that type on a page (or in our case, in a Text Area or DXP file). This is the efficiency I have been talking about. CSS formats everything with one block of code so you don’t have to format individual elements (like buttons) or add attributes to all HTML tags to format them.
There are many different types of CSS selectors, and you should definitely review them at W3Schools . Here is a simple example of an element selector. The “p” references the <p> tag, and the selector is selecting all of the <p> tagged content and formatting it.
Here is an example of a class selector from the Ruths.ai template. The selector is looking for the .sf-element-page-tab class. It will select all page tabs and change the border and padding accordingly.
Now that you know the basic syntax, let’s look at some specific code in the template that might not yet make sense. For example, you may be wondering what @import and !important are doing.
Other Rules & Syntax
CSS also utilizes “at-rules”. The “@import” is an example of an “at-rule”. At-rules are special instructions that control how styles are applied. In the case of this example, @import is pulling in a Google font. Other examples include @media, @font-face.
Each line of CSS in the template has “!important” at the end of it. “!important” establishes priority. It is telling SPotfire this code takes precedence over any other formatting that might be in the template, such as formatting in HTML tags or formatting from the set theme. The exclamation mark is called a delimiter token, and “important” is a keyword.
You may also have noticed that a line can be commented out with a forward slash and an asterisk.
Okay, that was a lot of talk about syntax. However, there is still more to learn. Next, we are going to talk about how to decipher the classes used by Spotfire. For example, if we want to change the active page tab color, how do we know to write “.sf-element-page-tab.sfpc-active”?
CSS for Spotfire
To figure this out, you can use the Developer Tools native to the application. Developer Tools are NOT turned on by default, so to even see the menu, go to Tools > Options > Application > Scroll to the bottom and check the box for Show Development menu. Now, you will see this menu in Tools.
Select Developer Tools, and a popup window appears. Click on the button that looks like this to inspect page elements. Now, move the mouse around the DXP and hover over elements to get the element names. I’ve taken some screenshots below for example. I realize these screenshots aren’t the best. I actually tried to make a video, but when you move and hover, stuff is constantly flashing on the screen. It was painful to watch.
Now, take note that an element can have multiple classes. Each class is denoted by a period, such as “.sf-element” and “.sf-element-visual-title”. The element “.sf-element” is a referring to something less specific than “.sf-element.sf-element-visual-title”, and “sf.element.sf-element-visual-title.sfpc-top” is even more specific.
For example, for the element shown below, to format the text box, use “sf-element-text-area”. You don’t need to dig all the way into “sfpc-first.row”.
You’ll get better identifying the right element and class with practice and trial and error.
I know this is turning out to be quite a long post, but just hold on. I’m about to wrap it up. There are just a few more things to note. First, in order to have CSS apply to an entire DXP, you need to have the <style> tag and accompanying CSS in at least one Text Area on each page. With that said, be careful when you edit. You might drive yourself crazy trying to figure out why the CSS isn’t doing what you want when there are conflicting pieces of code on different pages.
Well, that wraps it up. Thanks for sticking with me to the end. Clearly, there is much more to learn about CSS than one blog post can handle, but this will get you started.
We’re almost done folks! Only two posts left in the HTML series. This week, I’m going to focus on writing the HTML for lists because bullets and numbers are where the Spotfire GUI fails early and often. In case you are new to the series, go back and check out the earlier posts covering these four topics:
Before learning to write HTML, I had more trouble with lists than any other function in the Text Area, and I’m talking about “throw your computer out the window” kind of rage. Fortunately, bullets and lists are one of the easiest things to write in HTML. Master three tags — <ol>, <ul>, and <li> — and you are ready to rock and roll.
HTML for Lists
Lists are created with <ol> and <ul> tags. Use <ol> for ordered lists (numbers) and <ul> for unordered lists (bullets) . Each line in the list will also use the <li> tag.
Of course, there are a few rules to abide by.
- Start the list with <ol> or <ul>.
- Use the <li> tag for each line in the list.
- Always close the <li> tag. You’ll notice weird spacing if you don’t close each <li> tag.
- Add another <ol> or <ul> to indent a level.
- Close the <ol> or <ul> to go back up a level.
- Make sure to close the final <ol> or <ul> when the list is complete.
Here are two examples demonstrating the rules above. The first example is fairly simple and just demonstrates the use of the <ol> and <li> tags.
In the second example, I have highlighted the <ul> tags used to move up and down levels in the list.
Now, you might be asking whether putting each tag on a new line is required, and the answer is no. I do this to make tracing my start and end tags easier. Add the tags in whatever manner is easiest for you to follow and understand. These few simple rules are all you need to work around the GUI and correct the text area when it goes awry.
Attributes for <ol> and <ul>
Now, because I know you are going to Google it, I want to mention that the <ol> and <ul> tags do have HTML attributes. You can read about them here for <ol> and here for <ul>. An example is provided below. Just remember to use the attribute in the <ol> or <ul> tag, not the <li> tag, or it won’t work. I definitely made that mistake.
In closing, I want to note that when I first started using HTML for lists, I printed out the syntax and kept it on my desk. A week later, I threw that paper in the trash. You’ll pick this up and have it memorized in no time.
Welcome to part 4 of my HTML series! This week, we are going to build upon what we know by discussing HTML containers. I will also elaborate on the use of the style attribute inside HTML tags, which is where I left off last week. These two subjects go together nicely, as you’ll see how different containers apply formatting and style differently.
If you need a review, here are links to the other parts of the series — Part 1 Tags, Part 2 Attributes, Part 3 HTML & CSS. I’ll kick off this week by explaining the different types of HTML containers. It’s simple, there are only 2 types to worry about.
HTML Containers — Block versus inline
When building web pages, a developer will divide the page into sections using containers. The containers will then have content placed into them, and CSS is used to format and style the container. That’s the quick and dirty explanation anyway.
HTML uses two types of containers — block and inline. VSchool Web Development explains this really well by saying, “Block elements are those that take up the full width available on a web page, effectively blocking out any other elements from sitting next to it on the left or right. Inline elements are those who only take up as much width as is needed to display the contents of the element, thereby allowing other elements to be in line with the inline element.”
As a Spotfire developer, simply think of the Text Area as a web page. Thus, block elements will take up the full width of the Text Area. Inline elements only take up as much width as needed to display your text or other elements.
Examples of block elements you will use in Spotfire:
- Paragraphs <p>
- Headers <h1> thru <h6>
- Divisions <div>
- Lists and list items <ol>, <ul>, <li>
If you have been following the series, you should already have some experience working with <p> and <h1>-<h6>. Lists (<ol> and <ul>) will be covered next week. If you aren’t familiar with <div>, don’t worry, examples will be shown below.
Examples of inline elements you will use in Spotfire:
- Spans <span>
- Images <img>
Now that you understand the difference between block and inline, it would make sense to talk about when to use block versus inline, but that would make this post drag on a bit too long, so I’ll simply direct you to this link for more information on that subject.
Now, back to Spotfire. Here is an example of what these containers look like in Spotfire. Notice the use of background color and how far the color extends for each type of container.
As you can see, <span> and <img> do not take up the full width of the Text Area, but <p>, <h1>, and <div> do. This stands out after applying background color.
Now that you understand how different containers work, let’s go back to the style attribute. The style attribute can be used to format an individual tag OR all of the contents of a container. As a reminder, the syntax uses a property/ value pair separated by a colon. Multiple property/value pairs can be used inside a single tag. Simply separate them with a semicolon. Don’t forget to wrap the property/value pairs in quotes. Lastly, just a small warning, know that not everything you find on the internet will work in Spotfire.
Common properties to test
- height, width
To make this a little easier, I have created a free Spotfire template with examples of everything in the list above. Download it and review the examples provided. This is by no means an exhaustive list of everything you can do with style attributes, but it will certainly cover many of the common tasks performed in the Text Area. That wraps up this week’s post. Next week, I’ll explain how to create ordered and unordered (bulleted) lists in HTML.
To set the stage for this post, here is a simple example clearly demonstrating where we are going. In the Text Area below, 2 lines are duplicated. As you can see, the lines look the same, but the code is different. One is using CSS, and one is not. That’s what this post is all about.
Now, let’s talk about what CSS is and why it’s important.
What is CSS?
CSS stands for Cascading Style Sheets, and it is used to specify the format or style of content provided by the HTML. This might be confusing because it is possible to specify formatting with HTML tags. After all, some of the tags I pointed out in the Intro were tags for formatting, like <b>, <i>, <em>, <strong>, and <font>. That’s what italics and bold are — Formatting!
Really, this was all just one giant mistake in coding history. HTML was not intended to be used for formatting. As W3School notes:
“HTML was created to describe the content of a web page, like:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large websites, where fonts and color information were added to every single page, became a long and expensive process. To solve this problem, the World Wide Web Consortium (W3C) created CSS.”
Why use CSS?
The answer to that question is simple — EFFICIENCY. CSS is how Ruths.ai and Big Mountain Analytics are able to quickly produce beautiful templates. We definitely aren’t formatting each and every button or Text Area. That takes too long.
To demonstrate, download this free template from the Ruths.ai Exchange. In the DXP, right-click on the Text Area in the Terms page, select Edit HTML, and look at the code. It’s using the <style> tag, and CSS attributes control the appearance of the entire DXP.
Now, when building web pages, CSS can control the layout of multiple web pages all at once. When building DXP files, CSS can control the appearance of multiple text areas and other Spotfire elements (like the legend and your buttons) without having to format each and every one of them individually. It also opens up the ability to control formatting where there is no GUI, such as with the legend. Formatting the legend requires HTML/CSS.
How to Use CSS in Spotfire
The DXP example you downloaded uses CSS with the <style> tag, and that’s perfectly valid. For a complete understanding, know that there are three ways or places to write CSS.
- In a separate CSS file (.css extension) — This is only really applicable to building web pages, so don’t even worry about this.
- Inside a style tag — This is what you saw in the DXP download. This is referred to as “inline style” (knowing the right terms to Google is half the battle). In web design, this is not considered a best practice, but we aren’t building web pages.
- Inside an HTML tag using the style attribute.
Which Method to Use
As a Spotfire users, you should familiarize yourself with methods 2 and 3. The next logical question to ask would be — when do I use which method? Here is a quick summary of the pros and cons of each.
- Most efficient
- Reusable across DXP files
- Write a little or write a lot
- Able to access what the GUI cannot
- Need to know how to reference Spotfire elements
- May take longer to build
- Quick and easy to write
- Can be reused
- Must be written for individual tags
- Not as efficient
Style Attribute Syntax
The general rules for style attribute syntax are…
- The style attribute will use property/value pairs.
- The pair must be in quotes
- Separate Multiple pairs with a semicolon.
- Enclose the pair in double quotes.
Style Tag Syntax
Using the style tag, the syntax looks a little bit different. Note the use of brackets and the reference to specific pieces of Spotfire. This is where the waters start to get deep again, so I am going to wrap this post up with the example shown below. A future post will talk about this syntax in more detail.
In conclusion, if you new to HTML and CSS, consider these two suggestions.
- Start using the style attribute immediately in your own work. It’s super easy.
- Review the CSS in the template download. Alter and play with it to develop an understanding of what each element of the code controls in Spotfire.
These two suggestions will go a long way in terms of developing your skills and improving the appearance of your Spotfire projects. Now, this post is getting a bit long, but I wouldn’t be doing a good job if I didn’t talk about syntax.
As always, thanks for reading and feel free to leave comments! Lastly, since I haven’t said it since the intro, don’t forget that once you start editing HMTL, you shouldn’t use the Edit Text Area option. It will wipe out your code.
Last week, I kicked off a HTML series with the post — Intro to HTML. The Intro article discusses the languages users can employ in Text Areas and introduced the concept of HTML tags. It concluded by specifying a few tags to practice with in order to get comfortable with HTML. This week, I will talk HTML tag attributes because you won’t get very far in HTML without attributes. I started this post thinking I was also going to dive into what CSS is and how it fits in with HTML, but the post got long quickly. That will be the subject for next week. So, let’s look at attributes!
HTML Tag Attributes Examples
I’m going to explain what an attribute is, but before I do that, here are two examples in the code.
<img> — used for images, such as this easy button image
width and height are attributes of the <img> tag
<a> — used to create links
href is an attribute of the <a> tag
Characteristics of Attributes
Now that you know what you are looking at, here are the important things to know about attributes (sourced from W3Schools HTML Attributes).
- All HTML elements (tags) can have attributes.
- Attributes provide additional information about an element.
- They are always specified in the start tag.
- Attribute syntax is usually a name/value pair like: name=”value“. Separate the name from the value with an equals sign and put the value in double quotes.
- <h1 align=”center;”>Header</h1>
- <p align = “center;” </p>
- <a href=”hope.html”>Computer Hope</a>
- Add multiple attributes to a single tag. Separate them with a space as shown in Example 1.
- Some attributes can be used across multiple elements, such as the align attribute shown above. Other attributes may be unique to a tag.
- Not all tags and attributes are supported in Spotfire.
Googling attributes for individual tags is very easy, and W3Schools has a great attribute reference. To help you get started, here is a list of a few common attributes that users will employ in Spotfire.
- Attributes for <div>, <p> and <h1-h6>
- align — to specify text alignment
- Attributes for <img>
- height — to specify the height of images
- width — to specify the width of images
- border — to specify whether or not an image should have a border and how thick it should be
- Attributes for <hr>
- size — changes the size or width of the line
- color — changes the color of the line
- Attributes for <font>
- size — changes font size
- face — changes font style
- color — changes font color
Here is an example of each of these attributes.
Now, I am intentionally not diving very deep into attributes, and that is because next week, I will talk about CSS and formatting. You will do much more with CSS than with simple HTML tag attributes. Until then, take a look at the tags used in your existing DXPs. Google their associated attributes and see what you can add to the Text Area.
Hey everyone! Here is a quick and dirty HTML code snippet for those of you who are working on your HTML skills. Earlier this week, I was building a template with a Text Area containing several buttons. I wanted to center the buttons in the Text Area, which is really easy to do with HTML. You can also do this with CSS and <style>, but I’m just going to show you the two HTML versions that I worked with.
HTML Snippet No. 1
In this case, I have wrapped the buttons with <p> and </p> and simply added the align attribute with the “center” value. Here’s what it looks like. Note, the buttons sit on their own line because they are individually wrapped with <p> and </p>. <p> is a block level element that always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can in the Text Area). Compare this to the second code snippet below.
HTML Snippet No. 2
In this case, I have placed all buttons inside a <div> container and added the align attribute with the “center” value. Now, <div> is also a block level element, but in this case, the buttons are not on their own line because they are inside of one container. They would be on their own lines if I had placed them in individual <div> containers, but I was just seeing what I could do with less code. Personally, I prefer the first look.
I highly suggest reading up on the different block and inline elements. Understanding what space will be taken up with a given element will help you better design Text Areas. Please feel free to comment and provide suggestions for better code. I am still very much working on HTML and CSS. Thank you!
- Are you frustrated with the Spotfire Text Area?
- Do you find all the different languages that can be implemented in Text Areas confusing?