{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d1490459",
   "metadata": {},
   "source": [
    "# 22-02 · HTML и CSS вживую\n",
    "\n",
    "Практика к разделам [«Строительные блоки — HTML»](../../site/chapters/glava-22/22-02-html.html) и [«Делаем красивее — CSS»](../../site/chapters/glava-22/22-03-css.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a53134f",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Увидеть, как HTML-теги превращаются в структуру страницы, а CSS меняет её внешний вид — прямо внутри ноутбука."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "918e0d86",
   "metadata": {},
   "source": [
    "## Рабочий пример — HTML без стилей"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "172887f5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:59:44.702859Z",
     "iopub.status.busy": "2026-08-14T20:59:44.702757Z",
     "iopub.status.idle": "2026-08-14T20:59:44.734908Z",
     "shell.execute_reply": "2026-08-14T20:59:44.734423Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<h1>Привет, мир!</h1>\n",
       "<p>Это мой первый сайт на HTML.</p>\n",
       "<ul>\n",
       "  <li>Учу Python</li>\n",
       "  <li>Учу HTML</li>\n",
       "</ul>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Длина HTML-кода: 112 символов\n"
     ]
    }
   ],
   "source": [
    "from IPython.display import HTML, display\n",
    "\n",
    "html_bez_stilej = \"\"\"\n",
    "<h1>Привет, мир!</h1>\n",
    "<p>Это мой первый сайт на HTML.</p>\n",
    "<ul>\n",
    "  <li>Учу Python</li>\n",
    "  <li>Учу HTML</li>\n",
    "</ul>\n",
    "\"\"\"\n",
    "\n",
    "display(HTML(html_bez_stilej))\n",
    "print(\"Длина HTML-кода:\", len(html_bez_stilej), \"символов\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a56a7088",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3e6b6c37",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:59:44.735900Z",
     "iopub.status.busy": "2026-08-14T20:59:44.735783Z",
     "iopub.status.idle": "2026-08-14T20:59:44.738080Z",
     "shell.execute_reply": "2026-08-14T20:59:44.737638Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: страница содержит заголовок и оба пункта списка.\n"
     ]
    }
   ],
   "source": [
    "assert \"<h1>\" in html_bez_stilej\n",
    "assert \"<li>Учу Python</li>\" in html_bez_stilej\n",
    "print(\"Верно: страница содержит заголовок и оба пункта списка.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2cb9deb7",
   "metadata": {},
   "source": [
    "## Эксперимент — та же страница со стилями CSS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7f549b93",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:59:44.738998Z",
     "iopub.status.busy": "2026-08-14T20:59:44.738893Z",
     "iopub.status.idle": "2026-08-14T20:59:44.741500Z",
     "shell.execute_reply": "2026-08-14T20:59:44.741100Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  .demo-blok { font-family: sans-serif; background: #f7f7fb; padding: 12px; }\n",
       "  .demo-blok h1 { color: #4a2fbd; }\n",
       "  .demo-blok p { line-height: 1.6; }\n",
       "</style>\n",
       "<div class=\"demo-blok\">\n",
       "  <h1>Привет, мир!</h1>\n",
       "  <p>Теперь у страницы есть цвет, фон и аккуратные отступы.</p>\n",
       "</div>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "html_so_stilyami = \"\"\"\n",
    "<style>\n",
    "  .demo-blok { font-family: sans-serif; background: #f7f7fb; padding: 12px; }\n",
    "  .demo-blok h1 { color: #4a2fbd; }\n",
    "  .demo-blok p { line-height: 1.6; }\n",
    "</style>\n",
    "<div class=\"demo-blok\">\n",
    "  <h1>Привет, мир!</h1>\n",
    "  <p>Теперь у страницы есть цвет, фон и аккуратные отступы.</p>\n",
    "</div>\n",
    "\"\"\"\n",
    "\n",
    "display(HTML(html_so_stilyami))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da138d49",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Добавьте в CSS ещё одно правило — измените цвет текста внутри <li> на зелёный, — и убедитесь, что строка появилась в коде."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e311161e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:59:44.742503Z",
     "iopub.status.busy": "2026-08-14T20:59:44.742396Z",
     "iopub.status.idle": "2026-08-14T20:59:44.745351Z",
     "shell.execute_reply": "2026-08-14T20:59:44.744889Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<style>\n",
       "  .demo-blok2 li { color: green; }\n",
       "</style>\n",
       "<div class=\"demo-blok2\">\n",
       "  <ul><li>Зелёный пункт списка</li></ul>\n",
       "</div>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: правило для зелёного текста добавлено.\n"
     ]
    }
   ],
   "source": [
    "html_svoj_stil = \"\"\"\n",
    "<style>\n",
    "  .demo-blok2 li { color: green; }\n",
    "</style>\n",
    "<div class=\"demo-blok2\">\n",
    "  <ul><li>Зелёный пункт списка</li></ul>\n",
    "</div>\n",
    "\"\"\"\n",
    "\n",
    "display(HTML(html_svoj_stil))\n",
    "\n",
    "assert \"color: green\" in html_svoj_stil\n",
    "print(\"Верно: правило для зелёного текста добавлено.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
