/
Codeboy1
/
lab6
Обзор
Документация
Войти
/
Codeboy1
/
lab6
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
5.html
272 строки
9 KB
Codeboy1
create: 1.html, 2.html, 3.html, 4.html, 5.html, 6.html, 7.html, 8.html, 9.html
01 апр 2026, 14:10
Верифицирован
01 апр 2026, 14:10
b887c38
Код
Авторство
О чём код?
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Таблица с выделением четных сумм</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; margin: 0; padding: 40px 20px; display: flex; justify-content: center; align-items: center; } .container { background: white; border-radius: 20px; padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); max-width: 90%; overflow-x: auto; } h1 { text-align: center; color: #333; margin-bottom: 10px; font-size: 1.8rem; } .info { text-align: center; color: #666; margin-bottom: 30px; font-size: 1.1rem; border-bottom: 2px solid #667eea; padding-bottom: 15px; } table { border-collapse: collapse; width: 100%; min-width: 300px; margin: 0 auto; box-shadow: 0 5px 15px rgba(0,0,0,0.1); } th { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 12px 15px; font-weight: bold; font-size: 1.1rem; border: 1px solid #5a67d8; } td { border: 1px solid #ddd; padding: 10px 15px; text-align: center; transition: all 0.3s ease; } tr:hover td { background-color: #f8f9ff; transform: scale(1.01); } /* Стиль для выделенных ячеек */ td.highlight { background-color: #ff4444 !important; color: white !important; font-weight: bold; box-shadow: inset 0 0 0 2px #cc0000; } tr:hover td.highlight { background-color: #ff6666 !important; } /* Чередование цветов строк */ tr:nth-child(even) { background-color: #f9f9f9; } tr:nth-child(odd) { background-color: #ffffff; } /* Стили для заголовков */ th:first-child { border-top-left-radius: 10px; } th:last-child { border-top-right-radius: 10px; } caption { margin-bottom: 15px; font-size: 1rem; color: #555; font-style: italic; } @media (max-width: 768px) { .container { padding: 15px; } td, th { padding: 8px 10px; font-size: 0.9rem; } h1 { font-size: 1.4rem; } } .cell-content { font-weight: 500; color: #333; } td.highlight .cell-content { color: white; } .legend { margin-top: 25px; padding: 15px; background: #f0f0f0; border-radius: 10px; text-align: center; font-size: 0.9rem; color: #555; } .legend span { display: inline-block; width: 20px; height: 20px; background-color: #ff4444; border-radius: 4px; margin: 0 5px -3px 10px; border: 1px solid #cc0000; } </style> </head> <body> <div class="container"> <h1>📊 Таблица: Имя × Фамилия</h1> <div class="info"> <strong>Имя:</strong> ИВАН (4 буквы) | <strong>Фамилия:</strong> ПЕТРОВ (6 букв)<br> <strong>Размер таблицы:</strong> 4 × 6<br> <strong>Формат ячеек:</strong> j:i (столбец:строка) </div> <table id="dataTable"> <caption>Таблица размером n × m, где n = 4 (строки), m = 6 (столбцы)</caption> <!-- Заголовки столбцов --> <thead> <tr> <th>Строка\Столбец</th> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> <th>6</th> </tr> </thead> <tbody> <!-- Строка 1 --> <tr> <th>1</th> <td>1:1</td> <td>2:1</td> <td>3:1</td> <td>4:1</td> <td>5:1</td> <td>6:1</td> </tr> <!-- Строка 2 --> <tr> <th>2</th> <td>1:2</td> <td>2:2</td> <td>3:2</td> <td>4:2</td> <td>5:2</td> <td>6:2</td> </tr> <!-- Строка 3 --> <tr> <th>3</th> <td>1:3</td> <td>2:3</td> <td>3:3</td> <td>4:3</td> <td>5:3</td> <td>6:3</td> </tr> <!-- Строка 4 --> <tr> <th>4</th> <td>1:4</td> <td>2:4</td> <td>3:4</td> <td>4:4</td> <td>5:4</td> <td>6:4</td> </tr> </tbody> </table> <div class="legend"> <strong>📌 Легенда:</strong> Ячейки с четной суммой индексов (j + i) <span></span> выделены красным цветом </div> <div style="margin-top: 15px; padding: 10px; background: #e8f4f8; border-radius: 8px; text-align: center; font-size: 0.85rem; color: #2c5282;"> 💡 <strong>Пояснение:</strong> Четная сумма означает, что (номер столбца + номер строки) делится на 2 без остатка.<br> Например: ячейка (строка 1, столбец 1): 1+1=2 (четная) → выделена красным<br> Ячейка (строка 1, столбец 2): 1+2=3 (нечетная) → не выделена </div> </div> <script> // Функция для выделения ячеек с четной суммой индексов function highlightEvenSumCells() { const table = document.getElementById('dataTable'); const rows = table.getElementsByTagName('tr'); // Проходим по всем строкам, начиная со второй (первая строка - заголовок) for (let i = 1; i < rows.length; i++) { const cells = rows[i].getElementsByTagName('td'); // Проходим по всем ячейкам строки for (let j = 0; j < cells.length; j++) { // i - номер строки (индексация с 1, так как первая строка заголовок) // j - номер столбца (индексация с 0, но в таблице столбцы с 1) const rowNumber = i; // номер строки (1-индексация) const colNumber = j + 1; // номер столбца (1-индексация) // Проверяем, является ли сумма четной if ((rowNumber + colNumber) % 2 === 0) { cells[j].classList.add('highlight'); } } } } // Вызываем функцию после полной загрузки страницы window.addEventListener('DOMContentLoaded', highlightEvenSumCells); // Альтернативный вариант: можно также добавить динамическое обновление // если потребуется перерисовка, но для статической таблицы достаточно вышеуказанного </script> </body> </html>