CSS और SCSS दिशानिर्देश
XOOPS SCSS प्रीप्रोसेसिंग के साथ आधुनिक CSS मानकों का पालन करता है, रखरखाव और प्रदर्शन पर ध्यान केंद्रित करता है।
अवलोकन
Section titled “अवलोकन”XOOPS CSS मानक इस पर जोर देते हैं:
- SCSS संगठन के लिए प्रीप्रोसेसिंग
- नामकरण के लिए बीईएम पद्धति
- मोबाइल-प्रथम प्रतिक्रियाशील डिज़ाइन
- पहुंच-योग्यता और अर्थ HTML
- प्रदर्शन अनुकूलन
फ़ाइल संरचना
Section titled “फ़ाइल संरचना”SCSS संगठन
Section titled “SCSS संगठन”styles/├── abstracts/ # Variables, mixins, functions│ ├── _variables.scss│ ├── _mixins.scss│ └── _functions.scss├── base/ # Reset, typography, defaults│ ├── _reset.scss│ ├── _typography.scss│ └── _base.scss├── components/ # Reusable components│ ├── _button.scss│ ├── _form.scss│ ├── _card.scss│ └── _navigation.scss├── layout/ # Page layout│ ├── _header.scss│ ├── _footer.scss│ ├── _sidebar.scss│ └── _container.scss├── pages/ # Page-specific styles│ ├── _home.scss│ ├── _dashboard.scss│ └── _admin.scss└── main.scss # Import all filesफ़ाइल नामकरण
Section titled “फ़ाइल नामकरण”// Use lowercase with hyphens_button.scss // Component_modal-dialog.scss // Multi-word component_colors.scss // Variablesनामकरण परंपराएँ
Section titled “नामकरण परंपराएँ”बीईएम पद्धति
Section titled “बीईएम पद्धति”बीईएम = ब्लॉक एलिमेंट संशोधक
// Block: Standalone component.button { }
// Block__Element: Child of block.button__text { }.button__icon { }
// Block--Modifier: Variation of block.button--primary { }.button--disabled { }.button--small { }
// Complex example.card { }.card__header { }.card__body { }.card__footer { }.card--highlighted { }.card--loading { }सर्वोत्तम प्रथाओं का नामकरण
Section titled “सर्वोत्तम प्रथाओं का नामकरण”// ✅ Descriptive BEM naming.form-field { }.form-field__label { }.form-field__input { }.form-field--disabled { }.form-field--error { }
// ❌ Avoid.form-f { } // Too abbreviated.form_field { } // Use hyphens, not underscores.formField { } // Don't use camelCase.form-field-2 { } // Don't use numbers for variants.form-field.active { } // Use modifiers, not classesफ़ॉर्मेटिंग
Section titled “फ़ॉर्मेटिंग”बुनियादी संरचना
Section titled “बुनियादी संरचना”.component { // 1. Positioning and layout display: flex; position: relative; top: 0; left: 0;
// 2. Box model width: 100%; height: auto; padding: 1rem; margin: 0.5rem; border: 1px solid;
// 3. Typography font-size: 1rem; line-height: 1.5; color: #333;
// 4. Visual effects background: #fff; border-radius: 4px; box-shadow: none;
// 5. Animations transition: all 0.3s ease;}रिक्ति और इंडेंटेशन
Section titled “रिक्ति और इंडेंटेशन”// Use 2 spaces for indentation.component { padding: 1rem;
&__child { margin: 0.5rem; }}
// Properties on separate lines.component { display: flex; // ✅ color: red; font-size: 1rem;}
// ❌ Don't compact.component { display: flex; color: red; }चयनकर्ता
Section titled “चयनकर्ता”// One selector per line.button,.button-group,.button-list { // ...}
// Don't skip lines between selectors// ✅.component {}
.component__element {}
// ❌.component {}
.component__element {}परिवर्तनीय नामकरण
Section titled “परिवर्तनीय नामकरण”// Use descriptive names$color-primary: #0066cc;$color-secondary: #666666;$color-danger: #dc3545;
$font-base: 16px;$font-size-small: 0.875rem;$font-size-large: 1.25rem;
$spacing-unit: 0.5rem;$spacing-small: 0.5rem;$spacing-medium: 1rem;$spacing-large: 2rem;
$border-radius-small: 2px;$border-radius-medium: 4px;$border-radius-large: 8px;
$transition-duration: 0.3s;$transition-timing: ease-in-out;परिवर्तनशील संगठन
Section titled “परिवर्तनशील संगठन”// Colors$color-primary: #0066cc;$color-secondary: #666666;
// Typography$font-family-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;$font-size-base: 1rem;$line-height-base: 1.5;
// Spacing$spacing-unit: 0.5rem;$spacing-xs: $spacing-unit;$spacing-sm: $spacing-unit * 2;$spacing-md: $spacing-unit * 4;$spacing-lg: $spacing-unit * 8;
// Breakpoints$breakpoint-sm: 576px;$breakpoint-md: 768px;$breakpoint-lg: 992px;$breakpoint-xl: 1200px;रंग प्रणाली
Section titled “रंग प्रणाली”// Primary palette$color-primary: #0066cc;$color-primary-dark: #004499;$color-primary-light: #3399ff;
// Secondary palette$color-secondary: #666666;$color-secondary-dark: #333333;$color-secondary-light: #999999;
// Semantic colors$color-success: #28a745;$color-warning: #ffc107;$color-danger: #dc3545;$color-info: #17a2b8;
// Neutral colors$color-white: #ffffff;$color-black: #000000;$color-gray-100: #f8f9fa;$color-gray-200: #e9ecef;$color-gray-300: #dee2e6;$color-gray-400: #ced4da;$color-gray-500: #adb5bd;$color-gray-600: #6c757d;$color-gray-700: #495057;$color-gray-800: #343a40;$color-gray-900: #212529;
// Usage.button { background-color: $color-primary; color: $color-white;
&:hover { background-color: $color-primary-dark; }
&--danger { background-color: $color-danger; }}टाइपोग्राफी
Section titled “टाइपोग्राफी”फ़ॉन्ट घोषणाएँ
Section titled “फ़ॉन्ट घोषणाएँ”// Define typography variables$font-family-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;$font-family-monospace: 'Courier New', monospace;
// Font sizes$font-size-base: 1rem; // 16px$font-size-small: 0.875rem; // 14px$font-size-large: 1.25rem; // 20px
$line-height-base: 1.5;$line-height-tight: 1.25;$line-height-loose: 1.75;
// Font weights$font-weight-light: 300;$font-weight-normal: 400;$font-weight-semibold: 600;$font-weight-bold: 700;शीर्षक पदानुक्रम
Section titled “शीर्षक पदानुक्रम”h1, .h1 { font-size: 2rem; line-height: 1.2; font-weight: $font-weight-bold; margin-bottom: $spacing-lg;}
h2, .h2 { font-size: 1.5rem; line-height: 1.3; font-weight: $font-weight-bold; margin-bottom: $spacing-md;}
h3, .h3 { font-size: 1.25rem; line-height: 1.4; font-weight: $font-weight-semibold; margin-bottom: $spacing-md;}
p { font-size: $font-size-base; line-height: $line-height-base; margin-bottom: $spacing-md;}
small { font-size: $font-size-small;}मिश्रण
Section titled “मिश्रण”सामान्य मिश्रण
Section titled “सामान्य मिश्रण”// Responsive breakpoint mixin@mixin respond-to($breakpoint) { @if $breakpoint == 'sm' { @media (min-width: $breakpoint-sm) { @content; } } @else if $breakpoint == 'md' { @media (min-width: $breakpoint-md) { @content; } } @else if $breakpoint == 'lg' { @media (min-width: $breakpoint-lg) { @content; } } @else if $breakpoint == 'xl' { @media (min-width: $breakpoint-xl) { @content; } }}
// Usage.component { font-size: 0.875rem;
@include respond-to('md') { font-size: 1rem; }
@include respond-to('lg') { font-size: 1.125rem; }}
// Flexbox mixin@mixin flex-center { display: flex; align-items: center; justify-content: center;}
// Usage.modal__overlay { @include flex-center; height: 100vh;}
// Truncate text mixin@mixin truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}
// Usage.breadcrumb__item { @include truncate; max-width: 200px;}
// Clearfix mixin (legacy)@mixin clearfix { &::after { content: ''; display: table; clear: both; }}उत्तरदायी डिजाइन
Section titled “उत्तरदायी डिजाइन”मोबाइल-प्रथम दृष्टिकोण
Section titled “मोबाइल-प्रथम दृष्टिकोण”// Base styles (mobile).component { font-size: 0.875rem; padding: $spacing-sm;}
// Tablets and up@include respond-to('md') { .component { font-size: 1rem; padding: $spacing-md; }}
// Desktops and up@include respond-to('lg') { .component { font-size: 1.125rem; padding: $spacing-lg; }}ब्रेकप्वाइंट सिस्टम
Section titled “ब्रेकप्वाइंट सिस्टम”// Define breakpoints$breakpoints: ( 'xs': 0, 'sm': 576px, 'md': 768px, 'lg': 992px, 'xl': 1200px, 'xxl': 1400px,);
// Flexible mixin for any breakpoint@mixin media($breakpoint) { $min-width: map-get($breakpoints, $breakpoint); @media (min-width: $min-width) { @content; }}
// Usage.component { width: 100%;
@include media('md') { width: 50%; }
@include media('lg') { width: 33.333%; }}बटन घटक
Section titled “बटन घटक”.button { display: inline-flex; align-items: center; justify-content: center; padding: $spacing-sm $spacing-md; border: 1px solid transparent; border-radius: $border-radius-medium; font-size: $font-size-base; font-weight: $font-weight-semibold; text-decoration: none; cursor: pointer; transition: all $transition-duration $transition-timing;
&:hover { opacity: 0.9; }
&:focus { outline: none; box-shadow: 0 0 0 3px rgba($color-primary, 0.25); }
&:disabled { opacity: 0.5; cursor: not-allowed; }
// Variants &--primary { background-color: $color-primary; color: $color-white;
&:hover { background-color: $color-primary-dark; } }
&--secondary { background-color: $color-secondary; color: $color-white; }
&--danger { background-color: $color-danger; color: $color-white; }
&--small { padding: $spacing-xs $spacing-sm; font-size: $font-size-small; }
&--large { padding: $spacing-md $spacing-lg; font-size: $font-size-large; }
// Icons &__icon { margin-right: 0.5em;
&:last-child { margin-right: 0; margin-left: 0.5em; } }}प्रपत्र घटक
Section titled “प्रपत्र घटक”.form-group { margin-bottom: $spacing-lg;}
.form-field { display: flex; flex-direction: column;
&__label { font-weight: $font-weight-semibold; margin-bottom: 0.5rem; color: $color-secondary-dark; }
&__input, &__select, &__textarea { padding: $spacing-sm; border: 1px solid #ddd; border-radius: $border-radius-medium; font-size: $font-size-base; font-family: inherit; transition: border-color $transition-duration;
&:focus { outline: none; border-color: $color-primary; box-shadow: 0 0 0 3px rgba($color-primary, 0.1); }
&:disabled { background-color: #f5f5f5; cursor: not-allowed; } }
&__help { font-size: $font-size-small; color: $color-gray-600; margin-top: 0.25rem; }
&--error { .form-field__input, .form-field__select { border-color: $color-danger;
&:focus { box-shadow: 0 0 0 3px rgba($color-danger, 0.1); } }
.form-field__error { color: $color-danger; font-size: $font-size-small; margin-top: 0.25rem; } }
&--disabled { opacity: 0.6; cursor: not-allowed; }}सर्वोत्तम प्रथाएँ
Section titled “सर्वोत्तम प्रथाएँ”- रंग, रिक्ति, फ़ॉन्ट के लिए SCSS वेरिएबल का उपयोग करें
- बीईएम नामकरण परंपरा का पालन करें
- मोबाइल-प्रथम प्रतिक्रियाशील डिज़ाइन
- उद्देश्य के अनुसार फ़ाइलें व्यवस्थित करें
- पुन: प्रयोज्य मिश्रण लिखें
- चयनकर्ताओं को सरल रखें (अधिकतम 3 स्तर गहरा)
- सिमेंटिक HTML का प्रयोग करें
- विशिष्टता कम करें
- जटिल अनुभागों पर टिप्पणी करें
मत करो
Section titled “मत करो”- इनलाइन शैलियों का प्रयोग करें
- उपयोग करें !महत्वपूर्ण (लगभग कभी नहीं)
- अत्यधिक विशिष्ट चयनकर्ता बनाएं
- स्टाइलिंग के लिए आईडी चयनकर्ताओं का उपयोग करें
- बहुत गहराई तक घोंसला बनाएं (अधिकतम 3-4 स्तर)
- फ़ॉन्ट आकार के लिए px का उपयोग करें (rem का उपयोग करें)
- जादुई संख्याएँ बनाएँ (चर का उपयोग करें)
- अप्रयुक्त CSS छोड़ें
- पहुंच को भूल जाओ
अभिगम्यता
Section titled “अभिगम्यता”रंग कंट्रास्ट
Section titled “रंग कंट्रास्ट”// Ensure sufficient contrast// Level AA: 4.5:1 for normal text// Level AAA: 7:1 for normal text
.button--primary { background-color: $color-primary; // #0066cc color: $color-white; // #ffffff // Contrast ratio: 8.6:1 ✅}
.button--secondary { background-color: $color-gray-300; // #dee2e6 color: $color-black; // #000000 // Contrast ratio: 9.3:1 ✅}फोकस राज्य
Section titled “फोकस राज्य”// Always provide focus styles.button:focus,.form-field__input:focus { outline: 3px solid $color-primary; outline-offset: 2px;}सिमेंटिक HTML CSS के साथ
Section titled “सिमेंटिक HTML CSS के साथ”// Use proper semantic structuremain { padding: $spacing-lg;}
article { margin-bottom: $spacing-xl; border-bottom: 1px solid #eee; padding-bottom: $spacing-xl;}
header { background-color: #f5f5f5; padding: $spacing-md;}
nav { display: flex; gap: $spacing-md;}प्रदर्शन
Section titled “प्रदर्शन”चयनकर्ताओं को अनुकूलित करें
Section titled “चयनकर्ताओं को अनुकूलित करें”// ✅ Efficient.button { // ...}
.button--primary { // ...}
// ❌ Inefficient (too specific, deep nesting)div.container section.content article .button { // ...}दोबारा रंग-रोगन कम से कम करें
Section titled “दोबारा रंग-रोगन कम से कम करें”// Group animations.component { // Change multiple properties at once transition: background-color 0.3s, color 0.3s, border-color 0.3s;}
// Or use shorthand.component { transition: all 0.3s ease;}स्टाइललिंट कॉन्फ़िगरेशन
Section titled “स्टाइललिंट कॉन्फ़िगरेशन”{ "extends": "stylelint-config-standard-scss", "rules": { "indentation": 2, "string-quotes": "single", "color-hex-length": "short", "selector-pseudo-class-no-unknown": null, "scss/dollar-variable-pattern": "^[a-z]" }}संबंधित दस्तावेज़ीकरण
Section titled “संबंधित दस्तावेज़ीकरण”- JavaScript मानक -आचार संहिता
- योगदान कार्यप्रवाह
- PHP मानक
#xoops #css #scss #स्टाइलिंग #कोडिंग-मानक #सर्वोत्तम अभ्यास