{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `ui.html`\n", "\n", "## HTML 元素\n", "\n", "将任意 HTML 渲染到页面上,包装在指定的标签内。可以使用 Tailwind 进行样式设计。您还可以使用 `ui.add_head_html` 将 `html` 代码添加到文档的 `head` 中,以及使用 `ui.add_body_html` 将其添加到 `body` 中。\n", "\n", "- `content`:要显示的 HTML 代码\n", "- `tag`:包裹内容的 HTML 标签(默认:`\"div\"`)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "ui.html('This is HTML.')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 生成内联元素\n", "\n", "使用 `tag` 参数来生成除了 `div` 之外的其他元素。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "ui.html('This is emphasized.', tag='em')\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 }