Skip to content

Using CSS V2

When building or customizing a website, placing your CSS in the correct location ensures clean, maintainable, and efficient code. Here’s a concise, updated guide to modern CSS placement using Beaver Builder and WordPress.

Coding Standards

Create Code That Is Meaningful, Consistent, and Readable 

1. Keep Your Code Organized

Structure: Follow this hierarchy: Global > Page-Specific > Module-Specific > Mobile-Specific. Organizing CSS this way makes it easier for updates and debugging.

Indentation: Use consistent indentation (e.g., 2 spaces) to enhance readability. 

Spacing: Add blank lines between major sections or blocks. 

Readable Selectors: Write each selector on its own line, ending with a comma or opening curly brace. 

DON'T DO THIS:
.selector-1, .selector-2 {color: #000; margin: 0;}
DO THIS:
.selector-1, .selector-2 { color: #000; margin: 0; }

2. Comment Liberally

Explain the purpose of your CSS code. 

Avoid !important unless absolutely necessary. If used, explain why. 

EXAMPLE:
/* This selector adjusts the header's z-index to avoid overlap with dropdown menus */ .header { z-index: 10; }

3. Use Meaningful Names for Classes and IDs

Avoid generic names like .box or .red-text.

Use descriptive and reusable names, e.g., .primary-button or .card-container.

4. Avoid Inline Styles

Use CSS files or <style> tags for maintainability. 

Inline styles make debugging and updates harder. 

5. Avoid Targeting Auto-Generated Classes

Do not target classes like .fl-module generated by page builders. Instead, create custom classes and target those. 

CSS Guidelines

1. Use Shorthand Properties

Whenever possible, use shorthand for CSS properties. 

DON'T DO THIS:
.selector { margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; }
DO THIS:
.selector { margin: 10px; }

2. Avoid Zero Units for px, em, rem

DON'T DO THIS:
.selector { margin-top: 0px; }
DO THIS:
.selector { margin-top: 0; }

3. Use Variables for Consistency

CSS variables work similarly to classes, allowing you to define reusable values that can be applied consistently across your styles. For example, you can create a variable for a specific color and then reuse it throughout your project.

 

Why Use CSS Variables?

A practical use case is when customizing WooCommerce elements. Instead of manually applying the same color to every button, border, or other design element, you can define a single variable, such as --primary-color, and use it wherever needed.

EXAMPLE:
:root { --primary-color: #3498db; --secondary-color: #2ecc71; --font-family: "Arial, sans-serif"; } h1 { color: var(--primary-color); font-family: var(--font-family); }

CSS Guidelines

Place the following structure in your CSS file or in the “Additional CSS” section of your CMS. 

EXAMPLE:
/* Typography */ body { font-family: "Arial, sans-serif"; color: #333; } /* Layout */ .container { max-width: 1200px; margin: 0 auto; padding: 0 20px; } /* Components */ .button { background-color: var(--primary-color); color: #fff; padding: 10px 20px; border-radius: 5px; text-decoration: none; } .button:hover { background-color: var(--secondary-color); }

Styling Workflow

Follow this order of operations:

1. First, Use the CMS Customizer

Define global styles for headings, buttons, and links directly in the customizer. 

2. Second, Use Module-Specific Classes

Apply classes to modules when the customizer doesn’t meet your needs. 

3. Finally, Write Custom CSS

Add specific styles for edge cases not covered by the above methods. 

Common Mistakes to Avoid

Overusing !important: Makes debugging and maintenance difficult. 

Writing overly specific selectors: Keep selectors simple and reusable. 

Mixing CSS for layout and content: Use CSS Grid or Flexbox for layout; avoid hardcoding margins for alignment. 

By following these updated best practices, you’ll ensure your CSS is clean, scalable, and easy to maintain. 

Modern Guide to Using CSS in Web Design

This guide explains how to use CSS effectively, focusing on modern practices for adding class names or IDs to modules and ensuring best practices in CSS styling. 

Adding CSS IDs or Class Names to Elements 

You can assign unique identifiers (IDs) or reusable class names to HTML elements (such as rows, columns, or modules) for targeted CSS styling. 

Steps to Assign CSS IDs or Classes 

Access the Element Settings:

  • Open the row, column, or module settings in your page builder. 
  • Navigate to the Advanced Tab.

Assign a Name: 

  • For IDs: Enter a unique identifier (e.g., hero-section). 
  • For Classes: Enter reusable names (e.g., highlight-text). 
  • Note: Do not include the # (for IDs) or . (for classes) in the name during assignment. 

ID Selectors: Rules and Best Practices

An ID Selector is used to uniquely target one specific element. 

1. When to Use IDs:

For one-off elements requiring unique styling. 

For linking to specific sections (e.g., anchor links). 

2. Rules for IDs:

Must start with a letter. 

No spaces allowed (use - or _ instead). 

Use once per page to avoid conflicts. 

Example CSS for ID Selector:
#hero-section { background-color: #f4f4f4; text-align: center; }

3.Improper Use of IDs

One of the most common mistakes we observe when reviewing code and websites is the overuse or misuse of IDs. This can lead to serious issues in the structure and functionality of a webpage. Here are the key points to keep in mind:

  • Do not use the same ID more than once on the same page

IDs are meant to be unique identifiers. Each ID on a page must be unique. Reusing the same ID multiple times can cause unexpected conflicts in JavaScript functionality and styling.

  • Avoid random and illogical IDs

Creating IDs like #h1 or #h1-title is a bad practice. These IDs provide no meaningful context or clarity. Use descriptive names that reflect the element's purpose, such as #main-header or #article-title.

Class Selectors: Rules and Best Practices

A Class Selector allows you to style multiple elements with shared properties. 

1. When to Use Classes:

For recurring styles across multiple elements.

To keep styles reusable and maintainable. 

2. Rules for Classes:

Must start with a letter. 

Can be applied to multiple elements on the same page. 

Example CSS for Class Selector:
.highlight-text { color: #3498db; font-weight: bold; }

Writing Efficient CSS Selectors

Follow these steps to write concise and effective CSS: 

1. Use the Least Specific Selector Needed:

Target elements efficiently to minimize conflicts. 

Avoid excessive specificity. 

2. Organize Your Code:

Group related selectors. 

Use comments to describe sections. 

3. Use Modern Techniques:

Leverage flexbox or grid for layouts.

Use variables (--primary-color) for consistency. 

Example: Styling Nested Elements:
.card .card-title { font-size: 1.5rem; margin-bottom: 10px; }

Task: Target all <h4> headings inside a specific module and make them blue. 

Steps: 

  1. Assign a class name to the module: green-heading. 
  2. Use the following CSS: 
Example: Applying Styles to Modules:
.green-heading h4 { color: #3498db; }

Note: Avoid using !important unless absolutely necessary, as it complicates debugging. 

CSS Placement Best Practices

1. Restrict CSS to a Single Page Using Beaver Builder

If you want your CSS to apply only to specific pages or sections, this method is ideal. It keeps styles organized and prevents unnecessary global impact. 

Steps: 

  • Open Beaver Builder editor. 
  • Select Layout CSS & JavaScript. 
  • Enter your custom CSS code in the CSS tab. 
  • Click Save. 

When to Use: 

  • For CSS targeting specific rows, columns, or modules. 
  • For CSS unique to a single page template (e.g., forms, custom landing pages). 

Avoid Using This For: 

  • Styles affecting global elements like header, footer, or sidebar. 

 

Note: If you do apply CSS here, leave a comment in the WordPress Customizer (Appearance > Customize > Additional CSS) to inform future developers. 

2. Apply CSS Site-Wide Using Beaver Builder Global Settings

For CSS that should apply across your entire website, Beaver Builder’s Global Settings is an option. However, using the WordPress Customizer is generally preferred for modern standards. 

Steps: 

  1. Open Beaver Builder editor. 
  1. Click the Tools menu (top-left corner). 
  1. Select Global Settings. 
  1. Enter your custom CSS code in the CSS tab. 
  1. Click Save and preview your site. 

When to Use: 

  • If you want CSS applied to every page built using Beaver Builder. 

Recommendation: Use the WordPress Customizer for true site-wide CSS as it’s more standardized and reliable. 

3. Using the WordPress Customizer for Global CSS (Recommended)

The Customizer is the preferred method for adding global CSS in WordPress. It applies styles site-wide, whether or not Beaver Builder is in use. 

Steps: 

  1. Go to Appearance > Customize > Additional CSS. 
  1. Enter your custom CSS code in the text area. 
  1. Click Publish to save your changes. 

Advantages: 

  • CSS added here is stored in the WordPress database. 
  • Ideal for site-wide and theme-specific styles. 
  • Accessible for future developers. 

Best Practices: 

  • Add comments to explain your code. 
  • Use organized, modular CSS for better maintainability. 
Example:
/* Styles for large screens */ @media screen and (min-width: 768px) { .header-navigation { background-color: #333; color: #fff; } } /* Styles for smaller screens */ @media screen and (max-width: 767px) { .header-navigation { background-color: #fff; color: #333; } }

Summary of Recommendations

Method Use Case Recommendation
Beaver Builder Page CSSSingle-page or module-specific CSSUse only for isolated page styles.
Beaver Builder Global SettingsSite-wide CSS in Beaver BuilderUse with caution; prefer Customizer.
WordPress Customizer (Recommended)Global site-wide CSSBest for modern standards.

Key Takeaways

  • Always use the WordPress Customizer for global CSS. 
  • Use Beaver Builder’s local options for page-specific styling. 
  • Avoid redundancy by adding comments and organizing your CSS effectively. 

Pro Tip: Store backup copies of custom CSS separately for reference or future updates.

Table of Contents
    Scroll To Top