# AW-Flex: RTL-Aware Flexbox Grid for W3.CSS

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![W3.CSS Compatible](https://img.shields.io/badge/W3.CSS-Compatible-green.svg)](https://www.w3schools.com/w3css/)

**AW-Flex** is a lightweight CSS add-on that brings proper RTL (Right-to-Left) support to [W3.CSS](https://www.w3schools.com/w3css/). It replaces W3.CSS's float-based grid with a modern flexbox grid that automatically responds to the `dir` attribute, making it perfect for multilingual websites supporting Hebrew, Arabic, Persian, and other RTL languages.

## 🌟 Features

- **True RTL Support**: Columns automatically mirror based on `dir="rtl"` or `dir="ltr"`
- **Drop-in Replacement**: Same naming convention as W3.CSS (`aw-half` instead of `w3-half`)
- **Fully Responsive**: Mobile-first with breakpoints for small, medium, and large screens
- **12-Column Grid**: Flexible grid system with `aw-l1` through `aw-l12` classes
- **Lightweight**: Only ~3KB minified
- **No JavaScript Required**: Pure CSS solution
- **Works WITH W3.CSS**: Keep using W3.CSS for colors, buttons, cards - just use AW-Flex for layouts

## 📦 Installation

### Option 1: CDN (Coming Soon)
```html
<link rel="stylesheet" href="https://cdn.example.com/aw/css/aw-rtl.css">
<link rel="stylesheet" href="https://cdn.example.com/aw/css/aw-flex.css">
```

### Option 2: Download
Download `aw-rtl.css` and `aw-flex.css` and add them to your project.

### Option 3: Copy to your CSS folder
Place the files in your CSS directory structure:
```
your-project/
├── css/
│   ├── w3css-v5.css      (W3.CSS base)
│   ├── aw-rtl.css        (RTL fixes)
│   ├── aw-flex.css       (Flexbox grid)
│   └── w3-theme.css      (Optional: W3.CSS theme)
```

## 🚀 Quick Start

### 1. Include the CSS files (after W3.CSS)

```html
<head>
    <!-- W3.CSS Base -->
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    
    <!-- AW Add-ons -->
    <link rel="stylesheet" href="./css/aw-rtl.css">
    <link rel="stylesheet" href="./css/aw-flex.css">
</head>
```

### 2. Create an RTL-aware layout

```html
<!-- English (LTR) -->
<div class="aw-row" dir="ltr">
    <div class="aw-half w3-padding">First (Left)</div>
    <div class="aw-half w3-padding">Second (Right)</div>
</div>

<!-- Hebrew/Arabic (RTL) -->
<div class="aw-row" dir="rtl">
    <div class="aw-half w3-padding">ראשון (ימין)</div>
    <div class="aw-half w3-padding">שני (שמאל)</div>
</div>
```

### 3. Dynamic language switching (with templating)

```html
<!-- Fat-Free Framework example -->
<div class="aw-row" dir="{{@LNG.dir}}">
    <div class="aw-third">{{@LNG.column_one}}</div>
    <div class="aw-third">{{@LNG.column_two}}</div>
    <div class="aw-third">{{@LNG.column_three}}</div>
</div>

<!-- PHP example -->
<div class="aw-row" dir="<?= $lang === 'he' ? 'rtl' : 'ltr' ?>">
    <div class="aw-third">Column 1</div>
    <div class="aw-third">Column 2</div>
    <div class="aw-third">Column 3</div>
</div>
```

## 📐 Class Reference

### Row Container

| Class | Description |
|-------|-------------|
| `aw-row` | Flex container for columns. Add `dir="rtl"` or `dir="ltr"` for direction |

### Fixed-Width Columns

| Class | Width | W3.CSS Equivalent |
|-------|-------|-------------------|
| `aw-half` | 50% | `w3-half` |
| `aw-third` | 33.33% | `w3-third` |
| `aw-twothird` | 66.66% | `w3-twothird` |
| `aw-quarter` | 25% | `w3-quarter` |
| `aw-threequarter` | 75% | `w3-threequarter` |
| `aw-fifth` | 20% | - |
| `aw-twofifth` | 40% | - |
| `aw-threefifth` | 60% | - |
| `aw-fourfifth` | 80% | - |

### Responsive 12-Column Grid

#### Large screens (>992px)
| Class | Width |
|-------|-------|
| `aw-l1` | 8.33% |
| `aw-l2` | 16.66% |
| `aw-l3` | 25% |
| `aw-l4` | 33.33% |
| `aw-l5` | 41.66% |
| `aw-l6` | 50% |
| `aw-l7` | 58.33% |
| `aw-l8` | 66.66% |
| `aw-l9` | 75% |
| `aw-l10` | 83.33% |
| `aw-l11` | 91.66% |
| `aw-l12` | 100% |

#### Medium screens (601px - 992px)
Use `aw-m1` through `aw-m12`

#### Small screens (<600px)
Use `aw-s1` through `aw-s12`

### Utility Classes

| Class | Description |
|-------|-------------|
| `aw-center` | Center columns horizontally |
| `aw-space-between` | Space columns evenly with space between |
| `aw-space-around` | Space columns evenly with space around |
| `aw-align-top` | Align columns to top |
| `aw-align-center` | Align columns to center vertically |
| `aw-align-bottom` | Align columns to bottom |
| `aw-stretch` | Stretch columns to equal height |
| `aw-gap` | 16px gap between columns |
| `aw-gap-small` | 8px gap between columns |
| `aw-gap-large` | 32px gap between columns |
| `aw-no-stack` | Prevent stacking on mobile |
| `aw-stack` | Force stacking on all screens |

## 💡 Examples

### Example 1: Basic Three-Column Layout

```html
<div class="aw-row" dir="ltr">
    <div class="aw-third w3-padding w3-card">
        <h3>Column 1</h3>
        <p>Content goes here</p>
    </div>
    <div class="aw-third w3-padding w3-card">
        <h3>Column 2</h3>
        <p>Content goes here</p>
    </div>
    <div class="aw-third w3-padding w3-card">
        <h3>Column 3</h3>
        <p>Content goes here</p>
    </div>
</div>
```

### Example 2: Responsive Layout

```html
<!-- 3 columns on desktop, 2 on tablet, 1 on mobile -->
<div class="aw-row" dir="ltr">
    <div class="aw-l4 aw-m6 aw-s12 w3-padding">
        <div class="w3-card w3-padding">Item 1</div>
    </div>
    <div class="aw-l4 aw-m6 aw-s12 w3-padding">
        <div class="w3-card w3-padding">Item 2</div>
    </div>
    <div class="aw-l4 aw-m12 aw-s12 w3-padding">
        <div class="w3-card w3-padding">Item 3</div>
    </div>
</div>
```

### Example 3: Sidebar Layout (RTL-Aware)

```html
<div class="aw-row" dir="rtl">
    <!-- Main content: appears on RIGHT in RTL, LEFT in LTR -->
    <div class="aw-threequarter w3-padding">
        <h2>תוכן ראשי</h2>
        <p>זהו התוכן הראשי של העמוד...</p>
    </div>
    
    <!-- Sidebar: appears on LEFT in RTL, RIGHT in LTR -->
    <div class="aw-quarter w3-padding w3-light-grey">
        <h3>תפריט צד</h3>
        <ul class="w3-ul">
            <li>קישור 1</li>
            <li>קישור 2</li>
            <li>קישור 3</li>
        </ul>
    </div>
</div>
```

### Example 4: Bilingual Page with Dynamic Direction

```html
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link rel="stylesheet" href="./css/aw-rtl.css">
    <link rel="stylesheet" href="./css/aw-flex.css">
</head>
<body>
    <!-- Language Switcher -->
    <div class="w3-bar w3-theme">
        <a href="?lang=en" class="w3-bar-item w3-button">English</a>
        <a href="?lang=he" class="w3-bar-item w3-button">עברית</a>
    </div>

    <?php
    $lang = $_GET['lang'] ?? 'en';
    $dir = ($lang === 'he') ? 'rtl' : 'ltr';
    ?>

    <body dir="<?= $dir ?>">
    
    <div class="aw-row w3-content" dir="<?= $dir ?>" style="max-width:1200px">
        <!-- Logo Section -->
        <div class="aw-half w3-center w3-padding">
            <img src="logo.png" alt="Logo" style="max-width:300px">
            <h1><?= $lang === 'he' ? 'ברוכים הבאים' : 'Welcome' ?></h1>
        </div>
        
        <!-- Info Section -->
        <div class="aw-quarter w3-padding">
            <h2><?= $lang === 'he' ? 'אודות' : 'About' ?></h2>
            <p><?= $lang === 'he' ? 'תיאור באתר...' : 'Site description...' ?></p>
        </div>
        
        <!-- Stats Section -->
        <div class="aw-quarter w3-padding">
            <h2><?= $lang === 'he' ? 'סטטיסטיקה' : 'Statistics' ?></h2>
            <p>1,234 <?= $lang === 'he' ? 'משתמשים' : 'Users' ?></p>
        </div>
    </div>
    
    </body>
</html>
```

### Example 5: Card Grid with Equal Heights

```html
<div class="aw-row aw-stretch aw-gap" dir="ltr">
    <div class="aw-third">
        <div class="w3-card w3-padding" style="height:100%">
            <h3>Card 1</h3>
            <p>Short content</p>
        </div>
    </div>
    <div class="aw-third">
        <div class="w3-card w3-padding" style="height:100%">
            <h3>Card 2</h3>
            <p>This card has much more content than the others, 
               but they will all be the same height thanks to aw-stretch.</p>
        </div>
    </div>
    <div class="aw-third">
        <div class="w3-card w3-padding" style="height:100%">
            <h3>Card 3</h3>
            <p>Medium content here</p>
        </div>
    </div>
</div>
```

### Example 6: Centered Content

```html
<div class="aw-row aw-center" dir="ltr">
    <div class="aw-half w3-padding">
        <div class="w3-card w3-center w3-padding">
            <h2>Centered Column</h2>
            <p>This column is centered on the page</p>
        </div>
    </div>
</div>
```

### Example 7: Form Layout

```html
<form class="w3-container">
    <div class="aw-row aw-gap" dir="ltr">
        <div class="aw-half">
            <label>First Name</label>
            <input class="w3-input w3-border" type="text" name="fname">
        </div>
        <div class="aw-half">
            <label>Last Name</label>
            <input class="w3-input w3-border" type="text" name="lname">
        </div>
    </div>
    <div class="aw-row aw-gap" dir="ltr">
        <div class="aw-l8 aw-m6 aw-s12">
            <label>Email</label>
            <input class="w3-input w3-border" type="email" name="email">
        </div>
        <div class="aw-l4 aw-m6 aw-s12">
            <label>Phone</label>
            <input class="w3-input w3-border" type="tel" name="phone">
        </div>
    </div>
    <button class="w3-button w3-green w3-margin-top">Submit</button>
</form>
```

## 🔄 Migrating from W3.CSS Grid

If you have existing W3.CSS layouts, migration is straightforward:

| W3.CSS | AW-Flex |
|--------|---------|
| `<div class="w3-row">` | `<div class="aw-row" dir="ltr">` |
| `<div class="w3-half">` | `<div class="aw-half">` |
| `<div class="w3-third">` | `<div class="aw-third">` |
| `<div class="w3-quarter">` | `<div class="aw-quarter">` |
| `<div class="w3-col l6 m12">` | `<div class="aw-l6 aw-m12">` |

**Important**: Always add `dir="ltr"` or `dir="rtl"` to your `aw-row` containers!

### Before (W3.CSS)
```html
<div class="w3-row">
    <div class="w3-half w3-padding">Left</div>
    <div class="w3-half w3-padding">Right</div>
</div>
```

### After (AW-Flex)
```html
<div class="aw-row" dir="ltr">
    <div class="aw-half w3-padding">Left</div>
    <div class="aw-half w3-padding">Right</div>
</div>
```

## ⚠️ Important Notes

1. **Always specify `dir` attribute**: The `aw-row` container needs `dir="rtl"` or `dir="ltr"` to work correctly.

2. **Don't mix with W3.CSS grid classes**: Avoid using `w3-half`, `w3-third`, etc. inside `aw-row`. Use only `aw-*` classes for columns.

3. **Keep using W3.CSS for everything else**: Colors (`w3-blue`), buttons (`w3-button`), cards (`w3-card`), padding (`w3-padding`), etc. all work perfectly with AW-Flex.

4. **Mobile-first stacking**: By default, all columns stack vertically on screens smaller than 600px. Use `aw-s*` classes or `aw-no-stack` to override.

5. **Clean up w3-rtl.css**: If you were using w3-rtl.css, switch to aw-rtl.css which removes the conflicting float-based rules.

## 🌐 Browser Support

AW-Flex uses CSS Flexbox, which is supported in all modern browsers:

- Chrome 29+
- Firefox 28+
- Safari 9+
- Edge 12+
- Opera 17+
- iOS Safari 9+
- Android Browser 4.4+

## 📁 File Structure

```
aw/
├── css/
│   ├── aw-rtl.css      (1KB)  - RTL fixes for W3.CSS
│   └── aw-flex.css     (3KB)  - Flexbox grid system
├── js/
│   └── (future utilities)
└── README.md
```

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## 📄 License

MIT License - feel free to use in personal and commercial projects.

## 🙏 Credits

- **AW-Flex** was developed with the assistance of [Claude.ai](https://claude.ai) (Anthropic's AI assistant) in collaboration with **Eli Argon** of [Mifgash Hafakot](https://mifgash.com).

- **W3.CSS** is developed and maintained by [W3Schools](https://www.w3schools.com/w3css/).

- **Original w3css-rtl** by [Hamid Samak](https://github.com/hamidsamak/w3css-rtl) - portions adapted for aw-rtl.css.

---

## 📞 Support

For questions, issues, or suggestions:
- Open an issue on GitHub
- Contact: [Your contact info]

---

Made with ❤️ for the multilingual web community
