This page shows you how to set up CSS for a newly created Styla domain. It also discusses the structure of such settings and gives you tipps on how to do this in an efficient way.
Styla CSS works in separation from the CSS of a parent website on which Styla content is embedded, Styla CSS classes are very specific in order for them not to be influenced by the external CSS. So any style rules needed for Styla content to match the appearance of the parent website need to be set up separately.
Styla sets up CSS for every new client during the onboarding phase, based on their CI guides and website front-end where Styla content will be embedded on. You will be able to do this for your clients using Styla account management tool - the Organization Manager.
Styla CSS can be applied on several levels depending on how specific a rule should be. Each of the levels inherits settings from its parent and can override them for its own scope.
Level: | When to apply rules here: |
---|---|
Application defaults | These can only be changed by Styla developers by deploying changes to the Layout Engine (Styla front-end) project. If you create a new domain and don't configure any Theme or Module settings, every module will use these defaults. By configuring settings you override these. If you configure something in a wrong way, the application will probably fall back to these defaults. |
Domain/account (Theme and Module settings) |
These are CSS and other settings influencing any piece of content you create for this domain. "Domain" is Styla lingo for an account = locale within an organization (client). You configure general typography and colour settings plus sizing and gutters in Theme settings, then customise these for every module type that has a different HTML structure in Module settings. In general, every new domain needs to have these configured and they will be applied automatically, unless overridden on a lower CSS level.
If you change one of them in the future, the changes will be applied retroactively to any existing content. This CSS is fetched from the top-level settings every time a Styla page is requested. |
Module preset |
If you want to use several variants of a module with different CSS, you can apply some changes with the Editor UI and then reuse the resulting preset for any module of the same type. Which means that by selecting a different preset from the dropdown in the "Settings" tab, a different set of CSS rules will be applied. You can also apply any CSS rule to any HTML node, even if there is no UI for it in the Editor.
CSS from such preset will be merged into any other CSS applied for the module and override any module settings from the higher levels. If you update a preset intself, you need to reapply it to all modules you need the changes to be reflected on. Creating presets only makes sense if they really will be reused on muliple modules. |
Module instance | You can apply CSS settings ona single module level as well - with the Editor UI or directly in the JSON editor. This makes sense if you only want the changes to be applied to one module and don't want to reuse them. |
One more thing important for you to understand on how CSS is applied to Styla content is that on any of the four levels above rules are applied to all view port widths and then can be overridden for mobile widths specifically.
Styla front-end only features one breakpoint applied with standard media queries. This breakpoint is set per default to 767px and can be modified in Theme settings. This means there is no intermediate breakpoints you'd normally use to apply a different CSS to tablets, laptop screens etc.
You can apply any CSS property (not just widths, margins or font-sizes) to any Styla HTML element separately. This is in line with the Editor UI which lets users override certain settings from desktop on mobile.
The Organization Manager tool in which you create new organizations, domains and users, is also where you configure CSS per domain. You do this in the THEME SETTINGS and MODULE SETTINGS tabs:
You configure CSS and other settings directly via JSON editor. We are aware that this is not the most efficient and user-friendly way but as Styla is developing their product at a very high pace, this approach lets us save some effort on a user interface that would need to be updated every time a new feature is released. Also, JSON data may contain thousands of fields and such a UI would be extremely detailed.
A proper user interface to configure CSS per domain will probably be released in the future.
This is where settings affecting any module are set. This includes typography, colours, sizes, gutters etc. They are inherited and can be modified on lower CSS levels.
Almost all sizes in this tab are defined in base unit which itself is defined in pixels. You define it by simply setting: "baseUnit": 10, on the highest JSON level. Setting it to 10 will make every other setting multiply its value by 10px. This way you can make every CSS property larger/smaller by changing this one setting. This will not be possible if you use px, rem, vw or any other CSS unit on a (lower) module level. These would keep their values in standard CSS units no matter what you change the base unit to.
Defaults: all: 8, smallScreen: 7
Styla can use external sources of font files to be loaded by Styla front-end and Editor preview. Setting them up is only needed for displaying text with a specific font outside of the parent website. Styla content embedded on a website will use font files loaded by this website, so the only thing you need to set up for such case is proper font-family rules.
However, you may need to load external font files to demo content and approve the CSS with your client - even before Styla content has been embedded on the website and is able to use the external font files.
Setting font-family without loading external fonts:
The only thing you need is to set up a list of font names that will populate the font-family CSS property in Styla front-end. They need to match font files loaded by the website or installed on user's machine, otherwise browser will fall back to whatever is defined in the fallback field.
{ "fonts": { "families": { "body": { "fallback": "sans-serif", "fontName": "GlacialIndifference-Regular" }, "cta": { "fallback": "Helvetica, sans-serif", "fontName": "Oswald" }, "headline": { "fallback": "Arial, sans-serif", "fontName": "GlacialIndifference-Bold" }, "serif": { "fallback": "serif", "fontName": "Butler" } } } }
Setting font-family and loading external font files:
Obviously, you need to host font files (best: .woff or .wof2) somewhere and use the same font family names as defined in your CSS. You can upload both the CSS file and fonts on your static files for this use specifically or just reference the files your website uses.
Styla has a loader mini app for Google Fonts and will load them via Google Fonts API as long as you set them up correctly (example below).
{ "fonts": { "custom": { "families": [ "ObiSans_ML_Bold", "ObiSans_ML_Regular" ], "urls": [ "https://fonts.styla.com/obi-redesign.css" ] }, "families": { "body": { "fallback": "sans-serif", "fontName": "Roboto" }, "headline": { "fallback": "ObiSans_ML_Bold, Arial, sans-serif", "fontName": "Obi-bold" }, "interaction": { "fallback": "sans-serif", "fontName": "Lato" }, "product": { "fallback": "Helvetica Neue, Helvetica, sans-serif", "fontName": "Arial" }, "subheadline": { "fallback": "ObiSans_ML_Regular, Arial, sans-serif", "fontName": "Obi-regular" } }, "google": { "families": [ "Roboto:400,400i,700,700i", "Lato:300,300i,700,700i:latin" ] }, "source": [ "custom", "google" ] }
Once your CSS has been approved, you can switch the avoid_font_loading feature flag on. This will prevent Styla content from loading external font files when embedded on the parent website while still load them in the Editor.
Instead of directly setting up font-size and line-height for each font format, Styla front-end needs them to be configured in leading and lineHeight fields, which will result in the above CSS properties in pixels. It's done this way to enable baseUnit changes influence any text size.
The leading field defines overall text line height, from the top to the bottom of every possible character. It is counted by multiplying the value you set by baseUnit. The lineHeight defines a fraction of font-size that the lineHeight will be. It's a bit hard to get the math done in your head, so we've created a spreadsheet for you to convert the standard CSS properties into the Styla properties and the other way round. Add it to your bookmarks if you are going to use it often.
Once you've set up your font-families, you use them to set up font formats. These are typography definitions which you can reuse on any number of modules and presets by adding a "fonts.formats" : "formatName" reference there. You can then update this format for all modules using it by changing its properties in Theme settings.
Font formats you define here can also be selected by users in the Editor in the "Advanced" tab for any module. Selecting them from the below dropdown list will make a specific field on your module load typography properties from the format assigned.
Font format examples:
The below JSON node shows how to set them up. Please don't use any non-typography CSS settings (paddings, colours, transitions) there. They won't work as they are applied on the module level.
As you can see, properties can be set just for mobile views in the smallScreen node.
{ "fonts": { "formats": { "body": { "fontFamily": "body", "leading": 2, "lineHeight": 1.5, "smallScreen": { "leading": 2.4, "lineHeight": 1.5 }, "styles": { "fontStyle": "normal", "fontWeight": 400 } }, "headline-1": { "fontFamily": "headline", "leading": 3.333333333, "lineHeight": 1.052631579, "smallScreen": { "leading": 2.5, "lineHeight": 1 }, "styles": { "fontWeight": 700, "letterSpacing": "1.5px", "textTransform": "uppercase" } }, "productModuleOldPrice": { "fontFamily": "serifMedium", "leading": 1.6, "lineHeight": 1.333333333, "smallScreen": { }, "styles": { "fontWeight": "bold", "textDecoration": "underline" } } } } }
The bodyCopy is the most important format and should always be defined. It is per default used for every module paragraph text and inherited by many other fields, for instance, price and product name fields in Product module.
The same way you create font formats to be reused in many different modules, you configure colours to be able to reference their name and change them in Theme settings for any module using it. You set them up by giving them a name and then assigning a CSS hex or RGB scheme value.
You can then reference these names as variables when setting up in any properties. For instance: "color": "{colors.black}" or "borderBottomColor": "{colors.secondary}". This does not work in shorthand definitions where you need to use a full hex number.
Colours you define here can also be selected by users in the Editor in the "Advanced" tab for any module. Selecting them from the below dropdown list updates will apply a CSS property with this colour to a given HTML element.
Colour examples:
The contrast is per default used for all background elements and in 90% of cases will be white. The bodyCopy will per default be applied to paragraph copy and in 90% of cases will be black or dark grey. Some other names like primary or link will also be automatically applied to some HTML elements in some modules unless you override them in module settings.
As you can see below, every CSS-compliant colour notation can be used, including colour hex and RGB numbers with opacity.
{ "colors":{ "bodyCopy":"#000", "contrast":"#fff", "headline":"#17332f", "link":"#1454fe", "neutralBackgroundDark":"#1e212a", "neutralBrownGrey":"#909090", "neutralWarmGrey":"#979797", "primary":"#ffdd00", "secondaryBurgundy":"#8b5f65", "secondaryDarkSlateBlue":"#224a63", "secondaryDustyOrange":"#f6912c", "secondaryFadedOrange":"#efa152", "utilityHighlight":"rgba(20, 84, 254, 0.3)", "whiteOpacity":"#fffc" } }
Theme settings feature a property for setting a max-width for any Styla content (which will be used for the row "Default Width" in Editor) and a separate one for the "Smaller" width. These are set in pixels. "Full Bleed" will always use 100% of browser width unless Styla content sits in an external HTML that has its own width or margins/paddings set.
It is good practice to set the pageMaxWidth to the same pixel value parent website uses. This will make content appear more or less the same in the Editor. In addition, you can set a pageMargin value in base units which will apply paddings on the left and right, visible once you resize the browser window below the pageMaxWidth.
Values from the gutters array populate the dropdown in the Editor where you can apply margin-top to layout rows, spaces between modules in a row and external paddings for a row background. They are defined in base units and can be set for desktop and mobile separately. This lets you space rows or modules differently on smaller screens.
Max widths, page margins, gutters examples:
{ "baseUnit": 10, "gutters": { "block": 4, "double": 2, "extraLarge": 8, "extraSmall": 0.5, "large": 4.5, "medium": 3, "none": 0, "single": 1, "small": 1.5, "textMaxWidth": 88 }, "pageMargin": 0, "pageMaxWidth": 1220, "smallerContentMaxWidth": 1000, "smallScreen": { "baseUnit": 10, "gutters": { "extraLarge": 3, "large": 3.5, "medium": 2, }, "pageMargin": 2, }, "smallScreenMaxWidth": 768, }
The smallScreenMaxWidth sets the only breakpoint for Styla content, usually separating mobile phone layouts from any wider ones. You can modify it in Theme settings by setting a different pixel value if you want smallScreen overrides to kick in on a lower or higher width. The default is 767px.
imgixParams - you can modify image compression across all pieces of content with it. The setting will be used by Styla's imgix account which provides image analysis and manipulation. Useful if your client tells you the load sizes/times for Styla content are too big. The default is 45.
templateModuleIds - this array holds references to preset modules that can be used by this domain. It is updated automatically every time you add a new preset in the presets management list in the Editor. You can add new IDs manually if you want a domain to use presets you've created for another one.
textMaxWidth - this field sets a max-width value (in base units) for the textWrapper HTML div in which content of Text module sits. The default is 88.
{ "gutters": { "textMaxWidth": 88 }, "imgixParams": { "q": 20 }, "templateModuleIds": [ 123565, 128574, 132558, 133099, 133372, 175534, 240261, 270166 ] }
Once Theme settings have been configured, you can start configuring Module settings. The best way to start with it is by creating a page with each of module types you or your client want to use in the future. This way you will see how each of them looks with only Theme settings applied (typography, colours and spacings).
The next step would be to start updating settings for each specific module. You do this by applying CSS and other settings in a JSON node named after the module.
Each module node contains a styles subnode, where CSS is applied and a settings subnode where non-CSS settings are applied. These include some switches/feature flags for which there is no UI in the Editor, some of them very client-specific features that Styla had been asked to develop for them.
CSS that you set for a module is delivered by Styla to your browser and will work as CSS on any other website. So any CSS property can be set and will be rendered, as long as your browser supports it. You can transform, animate objects, change their position, display and z-index properties - which of course can break module layouts.
In case lack of a specific HTML element in Styla DOM is limiting implementation of your design, try adding pseudoelements in Module settings. For every HTML element on every module you can set :hover or :after or :nth-of-type(n). This is the only way to add some custom elements into Styla DOM.
CSS properties are represented by JSON nodes named after them but written in camel cases. So, for instance, align-content becomes alignContent. Property values however, stay as in CSS, so flex-start does not change and if you want to set it, you write: "alignContent": "flex-start" in module styles JSON.
Most CSS properties should be set as strings, for instance:
"backgroundPosition": "93% center",
"boxShadow": "0 2px 6px 0 rgba(0, 0, 0, 0.12)",
"fontSize": "1.4em",
"width": "calc(100% - 60px)"
and you use strings to reference Styla variables too:
"backgroundColor": "{colors.primary}",
"fonts.formats": "price"
However, any size properties that you normally set in px or em can be set in base units if you simply use numbers (positive or negative) to set them:
"bottom": 0,
"marginTop": -1.2,
"paddingLeft": 0.5
Many non-CSS settings take Boolean values, some of them are numbers or strings:
"isExternalLink": false,
"priceMinFractions": 2,
"priceTemplate": "#{price} €".
Any JSON you enter into the Organization Manager or Editor will be validated before saving. If it's invalid the changes won't be saved and will be lost, so if you're planning to enter a big chunk of JSON into the editor, better validate it somewhere else beforehand or back it up. The best approach is small incremental changes.
This is where you set CSS properties that you want inherited on every other module. Examples would be: a background colour and some instructions for browsers on how to render fonts.
{ "App": { "styles": { "App": { "all": { "backgroundColor": "{colors.lightGrey}", "marginTop": 0, "paddingBottom": 4, "textRendering": "optimizelegibility", "-webkit-font-smoothing": "antialiased" } } } } }
This is one of the most complex and definitely the most often used module. It consists of a text and buttons (in textLayer container) and an image (in imageLayer container).
{ "BANNER": { "styles": { "ctaLink": { "all": { "border": "1px solid", "borderRadius": "25px", "fonts.formats": "button", "padding": "14px 25px" } } } } }
This is a generic module reused for carousel arrows left and right on Product slider and Product Details modules. If you change settings here, they will be updated for both of them.
{ "CarouselControls": { "styles": { "left": { "all": { "left": "-40px", "position": "absolute", "top": "55%" }, "smallScreen": { "left": "-34px" } } } } }
This is the module used for graphically separating some other modules (groups) while not being semantically a headline. When updating its appearance, you should pay attention to Section Title too, where default font format will come from and whose module settings will influence it too.
{ "DIVIDER": { "styles": { "DIVIDER": { "all": { "position": "relative" }, "smallScreen": { "display": "flex", "flexDirection": "column", "justifyContent": "center", "position": "static" } } } }, "SectionTitle": { "styles": { "SectionTitle": { "all": { "backgroundColor": "#fff", "boxShadow": "0px 0px 0px 30px #ffffff", "display": "inline-block", "left": "50%", "marginBottom": 0, "marginTop": 0, "position": "absolute", "top": "6px", "transform": "translateX(-50%)" }, "smallScreen": { "boxShadow": "0px 0px 0px 15px #ffffff", "top": "auto" } } } } }
This is a very complex module in terms of HTML and needs JavaScript to work as intended. It features overlays displaying on clicking pins that users place manually on a background image, so it's complex in terms of Editor UI too. Same as Product and Product Details modules, it uses product data provided via Styla Product API.
Settings:
{ "EDITORIALSHOPPING": { "settings": { "pinImageWidth": 200, "priceTemplate": "#{price} €", "productClassification": "brand", "showOldPrice": true }, "styles": { "PIN": { "all": { "backgroundColor": "{colors.primary}", "borderRadius": "2px", "fill": "{colors.bodyCopy}", "padding": "7px" } } } } }
This module is what the "Your Stories" from the modules list in the Editor. It displays a feed consisting of pages with the type: story and has multiple settings that are really hard to customise as the appearance of the feed depends on all of them and almost each of them influences the others. You might need Styla's help to make this module look exactly as you need it.
Settings:
In the layouter node:
"feedGrid": {
"all": {
"gridTemplateColumns": "repeat(4, 1fr)"
}
}
{ "FEED": { "settings": { "copyMinWords": 10, "imageSelectionVariant": "FIRST_COLLAGE", "layouter": { "infiniteScroll": false, "maxRelevance": 1, "storySizeScale": 0.98 }, "showByline": false, "showCTA": true, "smallScreen": { "layouter": { "maxRelevance": 1, "storySizeScale": 1 }, "storyMarginVertical": 9 }, "storyMarginHorizontal": 8, "storyMarginVertical": 8 }, "styles": { "CallToAction": { "all": { "backgroundColor": { "id": "bodyCopy", "type": "colors" }, "borderRadius": "27px", "boxShadow": "0px 3px 6px #00000029", "color": { "id": "contrast", "type": "colors" }, "fonts.formats": "button", "marginBottom": 1, "marginTop": 1, "padding": "13px 30px", "transition": "all .5s" } }, } } }
A simple module consisting of an image and caption text. Still, you can adjust typography or caption background for it.
{ "IMAGE": { "styles": { "picture": { "all": { "borderRadius": "3px", "boxShadow": "0 1px 4px 0 rgba(0, 0, 0, 0.08), 0 3px 6px 0 rgba(0, 0, 0, 0.06), 0 1px 11px 0 rgba(0, 0, 0, 0.14)", "overflow": "hidden" } } } } }
This module displays a list with relative or absolute links that you set in the Editor. As the Editor features a very advanced UI with which you can set colours, paddings, margins and flex box properties, make sure you only apply only settings you always want inherited here (example: a font format).
{ "NAV": { "styles": { "elem": { "all": { "borderBottom": "1px solid", "fonts.formats": "navigation", "margin": "0px!important", "marginRight": "70px!important", "transition": "all .2s" } } } } }
This module displays a list of products populated with product images and text field sourced via Styla Product API. Editor UI for its settings features several switches, the most important ones being three layout variants: slider, grid, spread, each of them resulting in a different HTML structure and CSS classes. Editor users can also change number of products per row easily. Therefore you don't need to set these in Module settings JSON.
There are some quite complex calculations done to count product container sizes depending on how many products displayed per row, so if you will need to change paddings around them or apply some borders/shadows to get a very specific look, you might need to hardcode them for 3, 4 or 5 products per row.
Settings:
{ "PRODUCT": { "settings": { "isExternalLink": false, "imageBoxRatio": 1.12446352, "priceMinFractions": 2, "showControls": true }, "styles": { "caption": { "all": { "color": { "id": "headline", "type": "colors" }, "fonts.formats": "productCaption", "marginTop": 1, "order": "1", "textAlign": "left", "transition": "all .2s" } } } } }
This actually is not a module but a set of row settings that lets you manage every new slider row created in the Editor. The most important is selecting between three types of navigation available and setting an animation delay.
Settings:
If you need to override these settings for a single slider instance, you need to do this in. page JSON directly. There is currently no Editor UI for doing this.
{ "STANDARD_SLIDER": { "settings": { "autoPlayDelay": 5000, "showDotNavigation": true, "showThumbnailNavigation": false }, "styles": { "dotNavigation": { "all": {}, "smallScreen": {} } } } }
This is a rarely used module consisting of a product slider, product text with multiple fields and a button. It also can display external product content fetched via APIs: BazaarVoice (product reviews) and Commerce Connector (links to external shops selling the specific SKU). Here's an example.
Settings:
{ "PRODUCTDETAILS": { "settings": { "showArrows": false }, "styles": { "container": { "all": { "marginLeft": "auto", "marginRight": "auto", "maxWidth": "1488px", "padding": "60px 0px" }, "smallScreen": { "padding": "20px 0px" } } } } }
A very straightforward module consisting of a text field for which background and paddings can be customised with the Editor UI. Its width is per default set to 88 base units which you can change in Theme settings.
{ "TEXT": { "styles": { "ordered-item:before": { "all": { "color": { "id": "emerald", "type": "colors" }, "marginRight": 1.75 } } } } }
This module a banner with an .mp4 video file in the background. Same as banner, it display a text container with CTA buttons that can be customised with the Editor UI.
{ "TEXTONVIDEO": { "styles": { "ctaLink": { "all": { "border": "2px solid", "fonts.formats": "button", "padding": "14px 22px", "transitionDelay": "0s, 0s", "transitionDuration": "0.25s, 0.25s", "transitionProperty": "background-color, color", "transitionTimingFunction": "ease-out, ease-out", "WebkitFontSmoothing": "antialiased" }, "smallScreen": { "textAlign": "center" } } } } }
Remember that you can override every general setting from all node in smallScreen just for mobile views. Even without any explicit settings in smallScreen most modules will look differently once you make you shrink your browser window below 767px as they inherit a set of CSS for this media query from default Layout Engine app settings. This is especially valid for Banner, Product and Editorial Shopping modules.
When inspecting Styla HTML with your browser developer tools, you will see CSS classes and properties applied to each of them on different levels. Classes will almost always include one of the modules' names and then a specific HTML element name, separated by a couple underline characters.
This information is enough for you to first test applying some CSS properties in your browser window and then apply these in module settings JSON.
Still, there are some HTML elements/CSS classes in Styla DOM for which you won't be able to apply custom CSS rules. You can recognize them by the initial part of their class names not matching any of the modules above. Here's an example:
While you can modify modules' appearance in many different ways, the only two ways to change layout rows that contain modules are a) the Editor UI for row b) direct manual changes in page JSON structure. The latter is a bit risky operation and settings from a modified page can only be reused by copying the whole page.
Please find some hints below on how to approach the whole process of setting up CSS for Styla domain. These are based on experience of the author of this guide and should help you save time and effort.
The below .zip pack contains Theme and Module settings for a couple clients set up by Styla team. You can copy&paste this JSON into your domain Theme and Module settings to see how various properties can influence module content.
If your client need several appearance variants of the same module and cannot achieve it with the default set of presets available for every client, you will need to create a set of custom presets for them.
As the Editor features a UI to create and manage such presets, clients themselves can create presets there. But the usual UI in the Editor does not enable them to apply any CSS property to any HTML element. Therefore, you will need to set up some more advanced things directly in module JSON data.
Once this is done, the CSS and other settings from the preset you've just created can be applied to any other module of the same type with the "Presets" dropdown in the "Settings" tab. They will be saved in the "presets" node of its JSON data and merged to any other CSS it already has set. In case the same CSS property is set differently on both of them, the original settings in the module will prevail, being on a lower-level.
The preset that you've created will be available in the "Preset Manager" until you remove it. You can modify its JSON data and the changes will be reflected on any module you apply the preset to. The changes won't be automatically reflected on the modules you'd applied the preset to before. You'll need to re-apply it.
Presets that you set in the way described above are added in the templateModuleIds JSON node in Theme settings, as in the example below:
"templateModuleIds": [
1363771,
1364397,
1364398
],
You can copy this into another domain to reuse the presets.
Also, make sure you update these settings if you're editing JSON in a local file. If you remove or don't include this node, the Editor won't display your presets for this specific domain.