| name | safe-css-append |
| description | Safely append CSS styles from one file to another by identifying missing rules, adapting CSS variables, and verifying changes |
Safe CSS Append Workflow
This skill provides a systematic approach for safely appending CSS styles from a source file to a destination file. The workflow ensures no content is overwritten, CSS variables are properly adapted, and all changes are verified.
When to Use This Skill
- Migrating styles between projects
- Copying component styles while preserving existing rules
- Adding new CSS rules without duplicating or conflicting with existing styles
- Adapting styles to use a different set of CSS variables
Workflow Steps
1. Read and Analyze Source CSS
First, examine the source CSS file to identify the selectors and rules you want to transfer:
cat /path/to/source/styles.css
grep "selector-pattern" /path/to/source/styles.css
Document:
- Target selectors (e.g.,
.panel-tab, .header-nav)
- CSS variables used (e.g.,
--primary-color, --spacing-unit)
- Complete rule sets for each selector
2. Read and Check Destination CSS
Examine the destination file to understand existing rules and avoid duplication:
cat /path/to/destination/styles.css
grep "selector-name" /path/to/destination/styles.css
grep "^[[:space:]]*--" /path/to/destination/styles.css | head -20
Identify:
- Existing selectors that might conflict
- CSS variable naming conventions in the destination
- Any existing rules for the target selectors
3. Identify Missing Styles and Required Adaptations
Compare source and destination to determine:
- Which selectors are completely missing
- Which properties are missing from existing selectors
- How CSS variables need to be mapped (source → destination)
Example variable mapping:
Source: --panel-bg → Destination: --background-secondary
Source: --text-primary → Destination: --color-text-primary
Source: --border-radius → Keep as-is (if already defined in destination)
4. Prepare Adapted CSS Content
Create the CSS content to append, adapting variables as needed:
.new-selector {
background-color: var(--background-secondary);
color: var(--color-text-primary);
border-radius: var(--border-radius);
padding: 8px 16px;
}
.existing-selector {
new-property: value;
}
5. Safely Append to Destination
Use append operations (never overwrite) to add the new styles:
cat >> /path/to/destination/styles.css << 'EOF'
/* Added styles from source project */
.selector-name {
property: value;
variable-property: var(--adapted-variable);
}
EOF
Best practices:
- Add a comment indicating the source or purpose
- Include a blank line before the new content for readability
- Use
>> (append) never > (overwrite)
6. Verify the Changes
Confirm that the styles were added correctly:
tail -n 20 /path/to/destination/styles.css
grep "new-selector-name" /path/to/destination/styles.css
cat /path/to/destination/styles.css | tail -n 50
Complete Example
Here's a full example workflow:
cat project-a/components.css | grep -A 10 ".button-primary"
grep ".button-primary" project-b/main.css
grep "^[[:space:]]*--btn-" project-b/main.css
cat >> project-b/main.css << 'EOF'
/* Button styles from project-a */
.button-primary {
background-color: var(--primary-color);
padding: 10px 20px;
border-radius: 4px;
font-weight: 600;
}
EOF
tail -n 10 project-b/main.css
grep ".button-primary" project-b/main.css
Safety Checklist
Common Pitfalls
- Overwriting instead of appending: Always use
>>, never >
- Variable mismatch: Ensure all CSS variables exist in the destination or are properly defined
- Duplicate selectors: Check for existing rules before adding complete selector blocks
- Missing verification: Always verify changes after appending
Tips
- Use
wc -l before and after to confirm lines were added
- Keep a mapping document for complex variable transformations
- Consider using a temporary file to preview changes before appending
- Group related selectors together when appending multiple rules