Lesson 35 of 56 · Web pages

Colours and backgrounds

A background is a paint: a colour, a gradient or an image. This lesson shows the paints, how to layer them, and the effects that change how a whole element is drawn.

Paints

background takes a colour, and a hex colour with an alpha pair is partly transparent. The standard also has gradients and images as paints; see the reference.

dsl-background.salam
page:
    title = "Backgrounds"
    box:
        layout = "row"
        gap = 12
        padding = 16
        background = "#f3f4f6"
        box:
            width = 120
            height = 80
            background = "#3366aa"
        end
        box:
            width = 120
            height = 80
            background = "#3366aa"
            opacity = 0.5
        end
        box:
            width = 120
            height = 80
            background = "#3366aa40"
            border = 2, "solid", "#3366aa"
        end
    end
end
Result

Images as background

background size is cover, contain, auto or a length. background position takes words such as center or lengths, and background repeat is true, false, x or y.

Effects on the whole element

opacity goes from 0 to 1. The filters brightness, contrast, grayscale, saturate, sepia, invert and hue rotate change how the element is drawn, and the same names with backdrop in front change what shows behind it. translate, rotate, scale and skew move and bend an element after layout, so neighbours do not move.

dsl-filters.salam
page:
    title = "Filters"
    box:
        layout = "row"
        gap = 12
        padding = 16
        box:
            width = 80
            height = 80
            background = "#3366aa"
        end
        box:
            width = 80
            height = 80
            background = "#3366aa"
            grayscale = 1
        end
        box:
            width = 80
            height = 80
            background = "#3366aa"
            saturate = 3
        end
        box:
            width = 80
            height = 80
            background = "#3366aa"
            hue rotate = 90
        end
        box:
            width = 80
            height = 80
            background = "#3366aa"
            translate = 10, -4
            skew = 10, 0
        end
    end
end
Result