The Noob's (in)complete guide to CSS for Hubitat

Boy, this is from a long time go! @BrianP graciously helped me figure out how to vertically center text on a Link tile or a Text tile. Now I’m trying to do the same with a Hub Variable tile. Can’t get it to work.

Here’s the CSS @BrianP helped me with last time that I’m now trying to translate for Hub Variables. Any ideas? For bonus,I’m also trying to append unit-of-measure text to a hub variable. TIA!

/* vertically center Link and Dashboard tiles */
.link .tile-contents {
padding: 0;
display: table;
width: 100%;
height: 100%;
}
.dashboard .tile-contents {
padding: 0;
display: table;
width: 100%;
height: 100%;
}

Can you share the css that gives it a true button look and feel?

@mluck

For a Variable Number tile, it should be:

.variable-number .tile-contents {
padding: 0;
display: table;
width: 100%;
height: 100%;
}

Variable Boolean is similar, using .variable-bool, and Variable Date uses .variable-date, Variable Decimal uses .variable-decimal, and Variable Time uses .variable-time in the CSS selection.

It looks to be different for a Variable String tile. This won't work for that. Try right-clicking the tile and choosing "Examine" or "Inspect" on the element. Maybe then you can find the correct CSS selector to make this work. It might be something like .variable-string .items-center or .variable-string .justify-center instead of .variable-string .tile-contents.

Good luck!

1 Like

Appreciate the ideas @BrianP!

I always struggle finding the correct selector from inspect. Take this variable-string tile as an example. When I expect, I see this (below). Where do I look (and how far up the hierarchy do I look) to try to find the correct version of .variable-string, because .variable-string doesn't seem to work.

EDIT: I noticed in the Inspect view that was a little info note that said, "The display-table property prevents justify-content from having an effect. Try setting display to something other than table." What are the other options?

You might try adding an exclamation point to force display table... Maybe for the other styles also, removing the exclamation points one at a time if that works until it breaks again.

The CSS selector with .variable-string .text-center will select an element with the class .text-center that is also contained within an element with the class .variable-string. You could also use .text-center as the CSS selector, but that would also modify any element with that class regardless if it overlaps with a .variable-string element or not.

You're looking at the correct divs, starting with tile-48, including the next two divs. You want to pick a class in one of those divs to use in the CSS selector. I'd use text-center, justify-center, or items-center, since the other classes (i.e. flex, flex-col, etc) seem to be less specific.

Hi @mluck - Cannot promise you I can help you, but for us visual folks would you mind posting a picture of the tile you are speaking of and identifying the item you are trying to center?

I appreciate the question. Here's one (er, two) of many examples where I'm using a tile on a dashboard to show a hub variable. This particular use-case is tracking whether the dogs have been fed by my oh-so-irresponsible teenagers ;). Note how I can't get the text to vertically center no matter what I try.

Screenshot 2023-06-18 at 12.46.52 PM

I figured out the mystery of vertically centering string variables. With @BrianP's awesome help, the CSS below works, but only if you use "display: none" rather than "visibility: hidden" when hiding the tile name text at the bottom of the cell. I have no idea why this is required, but I just tried everything I could think of and this was the combo that worked. Hope this helps the next person.

.variable-number .justify-center {
padding: 0;
display: table;
width: 100%;
height: 100%;
}

2 Likes

Curious if anyone has cracked the code on manipulating an inbox box like @markbellkosel84's example above? Like him, I'd like to change the size, but I'd also like to keep the input box horizontally centered in the tile when it's interacted with. Every time I try to change the value in an inbox (even a value with one or two characters), it scrolls off the left edge of the tile, rendering the input box useless.

If you want the text input box bigger, I might use something like this:

.variable-string .justify-center input.text-black.outline-none {
    font-size: 2rem !important;
}

Since the input box has font-size: 1rem; coded in the HTML instead of in the CSS, you need to use !important.

1 Like

Hmmm this didn’t change the size or position of the input box.

I only tried this in Firefox, where it worked fine on the input box.

If you wanted to change the text that appears before clicking to get the input box, it would also be something like:

.variable-string div.flex.flex-col.w-full.text-center.h-full div.flex.flex-grow.w-full.justify-center.items-center {
    font-size: 2rem !important;
}

If I put both of those in,. I got a larger text size, and a larger input box after clicking the text. For example, default:
image
image

With custom CSS:

.variable-string .justify-center input.text-black.outline-none {
    font-size: 2rem !important;
}
.variable-string div.flex.flex-col.w-full.text-center.h-full div.flex.flex-grow.w-full.justify-center.items-center {
    font-size: 2rem !important;
}

image
image

You can also make that first bit of CSS more specific, but what I included got the job done.

I really appreciate your multiple attempts at helping me, but I just can't get this to work, and I don't want to impose further. My tile is a number variable, so when I used your CSS, I replaced variable-string with variable-number, but still no joy.

@mluck

.variable-number is different from .variable-string. Doesn't this work?

.variable-number .tile-contents {
padding: 0;
display: table;
width: 100%;
height: 100%;
}

I noticed that this CSS works for a device that is a global variable (number), but doesn't work for a Hub Variable that's a number. If you know what I mean.

Guess that's my work around. I could add a connector to my hub variable and use that device in the dashboard, rather than using the variable itself. For some reason, CSS seems much more difficult when the tile comes from a variable rather than a device.

Thanks again for your generosity.

Something interesting I've just run across - the following construct:

#tile-3 {.tile-title {visibility: visible}; .tile-primary {visibility: hidden}}

works exactly as you'd hope when viewed through the Hubitat android app - both of the "visibility" modifiers are applied.

But, when viewed through a browser (every one I've tried, PC and 'droid), neither modifier is applied - it's as though the line didn't exist. Splitting it into two, like

#tile-3 .tile-title {visibility: visible}
#tile-3 .tile-primary {visibility: hidden}

works perfectly on both app and browser(s). :astonished:

1 Like

For further frustration try looking at overflow :wink:

I'm trying to do something similar to this but I'd like a certain switch (tile# 10) to have a white icon and text whether it's on or off but when it's on have the background color rgba(255,0,0,0.4) and when it's off have the background coloring rgba(60,60,60,0.4).

How would I go about this? I've tried tweaking this CSS code but no luck...

Is it only the one tile where you want that to be the case and you have others using the same template where you don't want that colouring to be applied? Where I'm heading is, could you just use the template colours in the options rather than CSS?

Correct, it's just a single switch that I want to act this way. The rest of the swtiches should follow the template I created.