{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `ui.column`\n", "\n", "## 列元素\n", "\n", "提供子元素按列排列的容器。\n", "\n", "`wrap`:是否换行内容(默认:`False`)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.column():\n", " ui.label('label 1')\n", " ui.label('label 2')\n", " ui.label('label 3')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Masonry 或 Pinterest 风格布局\n", "\n", "要创建 Masonry/Pinterest 风格布局,不能使用常规的 `ui.column`。但是可以通过几个 TailwindCSS 类来实现。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.element('div').classes('columns-3 w-full gap-2'):\n", " for i, height in enumerate([50, 50, 50, 150, 100, 50]):\n", " tailwind = f'mb-2 p-2 h-[{height}px] bg-blue-100 break-inside-avoid'\n", " with ui.card().classes(tailwind):\n", " ui.label(f'Card #{i+1}')\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "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.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }