蓝色天空.知识 · 实践 · 创造
我的收藏
jQuery UI 教程目录 43章
jQuery UI / LEARN BY DOING

jQuery UI CSS 框架 API

系统核对 jQuery UI CSS 框架在 ui.core.css 与 ui.theme.css 中的全部核心类:布局助手、小部件容器、交互状态、交互提示、上下文图标及圆角/覆盖/阴影视觉类。

学完这一章,你能够

  • 系统核对 jQuery UI CSS 框架在 ui.core.css 与 ui.theme.css 中的全部核心类:布局助手、小部件容器、交互状态、交互提示、上下文图标及圆角/覆盖/阴影视觉类。

CSS 框架职责分工与布局助手(ui.core.css)

jQuery UI CSS 框架面向自定义小部件和社区插件提供统一的语义标记约定,使整个应用呈现一致视觉且可被 ThemeRoller 集中换肤。全部框架类按职责分布在两个文件中:固定不变的结构与布局类定义于 `ui.core.css`,颜色、字体、背景等可主题化视觉类定义于 `ui.theme.css`。

布局助手类共 5 项:`.ui-helper-hidden` 应用 `display: none` 彻底隐藏元素;`.ui-helper-hidden-accessible` 借绝对定位与裁剪在视觉上隐藏元素同时保留辅助技术可读性;`.ui-helper-reset` 重置 `padding`、`margin`、`text-decoration`、`list-style` 等默认样式;`.ui-helper-clearfix` 让父容器自动包裹内部浮动子元素;`.ui-helper-zfix` 为 `<iframe>` 提供底层遮罩修复样式(应对早期浏览器原生控件穿透问题)。本站无头浏览器实测确认:`.ui-helper-hidden` 计算 `display: none`,`.ui-helper-hidden-accessible` 为 `position: absolute`、`1px × 1px`,`.ui-helper-reset` 归零边距与列表符号,`.ui-helper-clearfix` 包裹 40px 浮动块后高度精确为 `40px`,`.ui-helper-zfix` 为绝对定位且 `opacity: 0`。

小部件容器、交互状态与交互提示(Cues)

小部件容器类共 3 项:`.ui-widget` 用于最外层容器,统一设定字体族与字号,并对内部表单控件强制设置相同字体与 `1em` 字号以修复 Windows 浏览器表单字体不继承问题;`.ui-widget-header` 定义标题栏及其内部文本、链接与图标样式;`.ui-widget-content` 定义主体内容区(可作为标题栏的父级或同级元素)。本站实测 `.ui-widget` 设 `16px` 时内嵌 `<input>` 计算字号同样为 `16px`,标题与内容背景分别为 `rgb(204, 204, 204)` 与 `rgb(255, 255, 255)`。

交互状态类共 4 项,覆盖可点击控件的完整交互周期:默认可点击态 `.ui-state-default`、鼠标悬停态 `.ui-state-hover`、键盘聚焦态 `.ui-state-focus`(与悬停共用视觉高亮)以及鼠标按下/选中激活态 `.ui-state-active`。本站实测默认背景 `rgb(230, 230, 230)`,悬停与聚焦背景完全一致(`rgb(218, 218, 218)`),激活态为 `rgb(255, 255, 255)`。

交互提示(Cues)类共 6 项:`.ui-state-highlight` 标示高亮或选中区,`.ui-state-error` 标示错误消息容器,`.ui-state-error-text` 仅着色错误文本和子图标而不加背景(适用于表单标签),`.ui-state-disabled` 对已样式化控件叠加暗淡不透明度,`.ui-priority-primary` 以粗体强调主操作按钮,`.ui-priority-secondary` 以常规字重加轻微透明弱化次要按钮。本站实测高亮背景 `rgb(251, 249, 238)`、错误容器背景 `rgb(254, 241, 236)`、纯错误文本透明底配 `rgb(205, 10, 10)`、禁用态不透明度 `0.35`、主按钮字重 `700`、次按钮字重 `400` 且不透明度 `0.7`。

图标系统、圆角半径助手与覆盖阴影

图标基类 `.ui-icon` 将元素设为 `16px × 16px` 方块、通过负缩进隐藏内部文本并加载精灵背景图;且 `.ui-icon` 会依据祖先容器(如内容区、标题栏、`ui-state-default` 或错误容器)自动选用对应色调的精灵图。具体图形通过附加类 `.ui-icon-{icon type}-{icon sub description}-{direction}` 指定,例如向右三角形写作 `.ui-icon-triangle-1-e`;完整图标类名可在 ThemeRoller 预览栏悬停查阅。本站实测 `.ui-icon` 尺寸 `16px × 16px`、`text-indent: -99999px`、`.ui-icon-triangle-1-e` 精灵偏移 `-32px -16px`,且 4 种父容器均正确匹配各自色调背景图。

圆角半径助手提供 9 个精确控制方向的类:四角单控为 `.ui-corner-tl`(左上)、`.ui-corner-tr`(右上)、`.ui-corner-bl`(左下)、`.ui-corner-br`(右下);按边双控为 `.ui-corner-top`(上边两角)、`.ui-corner-bottom`(下边两角)、`.ui-corner-right`(右边两角)、`.ui-corner-left`(左边两角);全圆角为 `.ui-corner-all`。本站逐一实测 9 个类的四个计算圆角值,均精确在目标角输出 `4px`、其余角保持 `0px`。

覆盖与阴影提供 2 个视觉类:`.ui-widget-overlay` 以 `100%` 宽高与指定不透明度铺满视口形成模态遮罩;`.ui-widget-shadow` 叠加于浮层下方,通过四边 `padding` 定义阴影“厚度”,并通过可正可负的 `margin-top`/`margin-left` 控制阴影偏移量。本站 800×600 视口实测 `.ui-widget-overlay` 尺寸精确覆盖 `[800, 600]`(不透明度 `0.3`),`.ui-widget-shadow` 实测 `padding: 8px`、上/左偏移 `-8px` 且不透明度 `0.3`。

运行全套 jQuery UI CSS 框架类(布局助手、容器、状态/提示、图标、9 向圆角与遮罩阴影)离线实测

含完整源码 · 273 行
展开查看收起
python
"""Offline Playwright Chromium lab for jQuery UI Ch 09 (theme-api)."""
import json
from playwright.sync_api import sync_playwright


def launch_browser(p):
    try:
        return p.chromium.launch(headless=True)
    except Exception:
        return p.chromium.launch(headless=True, channel="chrome")


FRAMEWORK_CSS = """
/* ui.core.css - structural layout helpers */
.ui-helper-hidden { display: none; }
.ui-helper-hidden-accessible { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; }
.ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; }
.ui-helper-clearfix::before, .ui-helper-clearfix::after { content: ""; display: table; border-collapse: collapse; }
.ui-helper-clearfix::after { clear: both; }
.ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; }
.ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; width: 16px; height: 16px; }

/* ui.theme.css - themeable visual styles */
.ui-widget { font-family: Verdana, Arial, sans-serif; font-size: 16px; }
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Verdana, Arial, sans-serif; font-size: 1em; }
.ui-widget-content { border: 1px solid rgb(170, 170, 170); background: rgb(255, 255, 255); color: rgb(34, 34, 34); }
.ui-widget-content a { color: rgb(34, 34, 34); }
.ui-widget-header { border: 1px solid rgb(170, 170, 170); background: rgb(204, 204, 204); color: rgb(34, 34, 34); font-weight: bold; }
.ui-widget-header a { color: rgb(34, 34, 34); }

.ui-state-default { border: 1px solid rgb(211, 211, 211); background: rgb(230, 230, 230); color: rgb(85, 85, 85); }
.ui-state-hover, .ui-state-focus { border: 1px solid rgb(153, 153, 153); background: rgb(218, 218, 218); color: rgb(33, 33, 33); }
.ui-state-active { border: 1px solid rgb(170, 170, 170); background: rgb(255, 255, 255); color: rgb(33, 33, 33); }

.ui-state-highlight { border: 1px solid rgb(252, 239, 161); background: rgb(251, 249, 238); color: rgb(54, 54, 54); }
.ui-state-error { border: 1px solid rgb(205, 10, 10); background: rgb(254, 241, 236); color: rgb(205, 10, 10); }
.ui-state-error-text { color: rgb(205, 10, 10); background: transparent; }
.ui-state-disabled { opacity: 0.35; }
.ui-priority-primary { font-weight: 700; }
.ui-priority-secondary { opacity: 0.7; font-weight: 400; }

/* Contextual icon sprite sheets */
.ui-widget-content .ui-icon { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' data-tone='content'/>"); }
.ui-widget-header .ui-icon { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' data-tone='header'/>"); }
.ui-state-default .ui-icon { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' data-tone='default'/>"); }
.ui-state-error .ui-icon, .ui-state-error-text .ui-icon { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' data-tone='error'/>"); }
.ui-icon-triangle-1-e { background-position: -32px -16px; }

/* Corner radius helpers */
.ui-corner-tl { border-top-left-radius: 4px; }
.ui-corner-tr { border-top-right-radius: 4px; }
.ui-corner-bl { border-bottom-left-radius: 4px; }
.ui-corner-br { border-bottom-right-radius: 4px; }
.ui-corner-top { border-top-left-radius: 4px; border-top-right-radius: 4px; }
.ui-corner-bottom { border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; }
.ui-corner-right { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.ui-corner-left { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.ui-corner-all { border-radius: 4px; }

/* Overlay & Shadow */
.ui-widget-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgb(170, 170, 170); opacity: 0.3; }
.ui-widget-shadow { margin: -8px 0 0 -8px; padding: 8px; background: rgb(170, 170, 170); opacity: 0.3; border-radius: 8px; }
"""


def main():
    cases = []
    with sync_playwright() as p:
        browser = launch_browser(p)
        page = browser.new_page(viewport={"width": 800, "height": 600})
        page.set_content(f"""<!DOCTYPE html><html><head><style>{FRAMEWORK_CSS}</style></head><body>
<div id="h-hidden" class="ui-helper-hidden">Hidden</div>
<div id="h-acc" class="ui-helper-hidden-accessible">SR Only</div>
<ul id="h-reset" class="ui-helper-reset"><li>Item</li></ul>
<div id="h-clearfix" class="ui-helper-clearfix"><div style="float:left;height:40px;width:40px;">F</div></div>
<iframe id="h-zfix" class="ui-helper-zfix"></iframe>

<div id="w-root" class="ui-widget">
  <div id="w-hdr" class="ui-widget-header"><a id="w-hdr-a" href="#">H</a><span id="ic-hdr" class="ui-icon"></span></div>
  <div id="w-cnt" class="ui-widget-content">
    <input id="w-inp" type="text" />
    <span id="ic-cnt" class="ui-icon ui-icon-triangle-1-e">next</span>
  </div>
</div>

<button id="st-def" class="ui-state-default"><span id="ic-def" class="ui-icon"></span>D</button>
<button id="st-hov" class="ui-state-hover">H</button>
<button id="st-foc" class="ui-state-focus">F</button>
<button id="st-act" class="ui-state-active">A</button>
<div id="cue-hi" class="ui-state-highlight">Hi</div>
<div id="cue-err" class="ui-state-error"><span id="ic-err" class="ui-icon"></span>Err</div>
<span id="cue-err-txt" class="ui-state-error-text">ErrTxt</span>
<button id="cue-dis" class="ui-state-default ui-state-disabled">Dis</button>
<button id="pri-1" class="ui-priority-primary">P1</button>
<button id="pri-2" class="ui-priority-secondary">P2</button>

<div id="c-tl" class="ui-corner-tl"></div>
<div id="c-tr" class="ui-corner-tr"></div>
<div id="c-bl" class="ui-corner-bl"></div>
<div id="c-br" class="ui-corner-br"></div>
<div id="c-top" class="ui-corner-top"></div>
<div id="c-bot" class="ui-corner-bottom"></div>
<div id="c-right" class="ui-corner-right"></div>
<div id="c-left" class="ui-corner-left"></div>
<div id="c-all" class="ui-corner-all"></div>

<div id="ov" class="ui-widget-overlay"></div>
<div id="sh" class="ui-widget-shadow"></div>
</body></html>""")

        # Case 1: Layout helpers (ui.core.css)
        act1 = page.evaluate("""() => ({
          hidden_display: getComputedStyle(document.getElementById('h-hidden')).display,
          acc_pos_wh: [
            getComputedStyle(document.getElementById('h-acc')).position,
            getComputedStyle(document.getElementById('h-acc')).width,
            getComputedStyle(document.getElementById('h-acc')).height
          ],
          reset_props: [
            getComputedStyle(document.getElementById('h-reset')).marginTop,
            getComputedStyle(document.getElementById('h-reset')).paddingLeft,
            getComputedStyle(document.getElementById('h-reset')).listStyleType
          ],
          clearfix_height: document.getElementById('h-clearfix').offsetHeight,
          zfix_pos_opacity: [
            getComputedStyle(document.getElementById('h-zfix')).position,
            getComputedStyle(document.getElementById('h-zfix')).opacity
          ]
        })""")
        exp1 = {
            "hidden_display": "none",
            "acc_pos_wh": ["absolute", "1px", "1px"],
            "reset_props": ["0px", "0px", "none"],
            "clearfix_height": 40,
            "zfix_pos_opacity": ["absolute", "0"],
        }
        cases.append({
            "name": "layout_helpers_core_css",
            "expected": exp1,
            "actual": act1,
            "passed": act1 == exp1,
        })

        # Case 2: Widget containers & form control 1em inheritance
        act2 = page.evaluate("""() => ({
          widget_font_size: getComputedStyle(document.getElementById('w-root')).fontSize,
          input_font_size: getComputedStyle(document.getElementById('w-inp')).fontSize,
          header_bg: getComputedStyle(document.getElementById('w-hdr')).backgroundColor,
          header_link_color: getComputedStyle(document.getElementById('w-hdr-a')).color,
          content_bg: getComputedStyle(document.getElementById('w-cnt')).backgroundColor
        })""")
        exp2 = {
            "widget_font_size": "16px",
            "input_font_size": "16px",
            "header_bg": "rgb(204, 204, 204)",
            "header_link_color": "rgb(34, 34, 34)",
            "content_bg": "rgb(255, 255, 255)",
        }
        cases.append({
            "name": "widget_containers_and_form_inheritance",
            "expected": exp2,
            "actual": act2,
            "passed": act2 == exp2,
        })

        # Case 3: Interaction states (4) & cues (6)
        act3 = page.evaluate("""() => ({
          default_bg: getComputedStyle(document.getElementById('st-def')).backgroundColor,
          hover_equals_focus: getComputedStyle(document.getElementById('st-hov')).backgroundColor === getComputedStyle(document.getElementById('st-foc')).backgroundColor,
          active_bg: getComputedStyle(document.getElementById('st-act')).backgroundColor,
          highlight_bg: getComputedStyle(document.getElementById('cue-hi')).backgroundColor,
          error_bg: getComputedStyle(document.getElementById('cue-err')).backgroundColor,
          error_text_bg: getComputedStyle(document.getElementById('cue-err-txt')).backgroundColor,
          error_text_color: getComputedStyle(document.getElementById('cue-err-txt')).color,
          disabled_opacity: getComputedStyle(document.getElementById('cue-dis')).opacity,
          primary_weight: getComputedStyle(document.getElementById('pri-1')).fontWeight,
          secondary_weight_opacity: [
            getComputedStyle(document.getElementById('pri-2')).fontWeight,
            getComputedStyle(document.getElementById('pri-2')).opacity
          ]
        })""")
        exp3 = {
            "default_bg": "rgb(230, 230, 230)",
            "hover_equals_focus": True,
            "active_bg": "rgb(255, 255, 255)",
            "highlight_bg": "rgb(251, 249, 238)",
            "error_bg": "rgb(254, 241, 236)",
            "error_text_bg": "rgba(0, 0, 0, 0)",
            "error_text_color": "rgb(205, 10, 10)",
            "disabled_opacity": "0.35",
            "primary_weight": "700",
            "secondary_weight_opacity": ["400", "0.7"],
        }
        cases.append({
            "name": "interaction_states_and_cues",
            "expected": exp3,
            "actual": act3,
            "passed": act3 == exp3,
        })

        # Case 4: Icons - 16px box, text hiding, contextual sprite, directional naming
        act4 = page.evaluate("""() => {
          const ic = getComputedStyle(document.getElementById('ic-cnt'));
          return {
            size: [ic.width, ic.height],
            text_indent: ic.textIndent,
            triangle_1_e_pos: ic.backgroundPosition,
            tone_content: getComputedStyle(document.getElementById('ic-cnt')).backgroundImage.includes('content'),
            tone_header: getComputedStyle(document.getElementById('ic-hdr')).backgroundImage.includes('header'),
            tone_default: getComputedStyle(document.getElementById('ic-def')).backgroundImage.includes('default'),
            tone_error: getComputedStyle(document.getElementById('ic-err')).backgroundImage.includes('error')
          };
        }""")
        exp4 = {
            "size": ["16px", "16px"],
            "text_indent": "-99999px",
            "triangle_1_e_pos": "-32px -16px",
            "tone_content": True,
            "tone_header": True,
            "tone_default": True,
            "tone_error": True,
        }
        cases.append({
            "name": "icon_sizing_context_and_naming",
            "expected": exp4,
            "actual": act4,
            "passed": act4 == exp4,
        })

        # Case 5: All 9 corner radius helpers + overlay & shadow
        act5 = page.evaluate("""() => {
          const corners = (id) => {
            const s = getComputedStyle(document.getElementById(id));
            return [s.borderTopLeftRadius, s.borderTopRightRadius, s.borderBottomRightRadius, s.borderBottomLeftRadius];
          };
          const ov = document.getElementById('ov');
          const sh = getComputedStyle(document.getElementById('sh'));
          return {
            tl: corners('c-tl'), tr: corners('c-tr'), bl: corners('c-bl'), br: corners('c-br'),
            top: corners('c-top'), bottom: corners('c-bot'), right: corners('c-right'), left: corners('c-left'),
            all: corners('c-all'),
            overlay_rect: [ov.offsetWidth, ov.offsetHeight, getComputedStyle(ov).opacity],
            shadow_metrics: [sh.paddingTop, sh.marginTop, sh.marginLeft, sh.opacity]
          };
        }""")
        exp5 = {
            "tl": ["4px", "0px", "0px", "0px"],
            "tr": ["0px", "4px", "0px", "0px"],
            "bl": ["0px", "0px", "0px", "4px"],
            "br": ["0px", "0px", "4px", "0px"],
            "top": ["4px", "4px", "0px", "0px"],
            "bottom": ["0px", "0px", "4px", "4px"],
            "right": ["0px", "4px", "4px", "0px"],
            "left": ["4px", "0px", "0px", "4px"],
            "all": ["4px", "4px", "4px", "4px"],
            "overlay_rect": [800, 600, "0.3"],
            "shadow_metrics": ["8px", "-8px", "-8px", "0.3"],
        }
        cases.append({
            "name": "corner_radius_overlay_and_shadow",
            "expected": exp5,
            "actual": act5,
            "passed": act5 == exp5,
        })

        browser.close()

    print(json.dumps({"cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
核对 5 项布局助手、3 项容器与表单 1em 继承、4 态 6 提示、16px 上下文图标、9 项圆角角点及 800×600 遮罩与阴影偏移。

查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载本章实验包 (mbskycom202612a916.zip) ↓ 查看运行说明 ↗

本章附件与实例包

下载课程关联工程包:jQuery UI

课程关联工程包(登记关联43章) · 含当前章节或实例 · mbskycom202612a916.zip

下载课程关联工程包:jQuery UI

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a948.zip

常见错误与边界检查

  • 实际端口、文档资源与应用配置都应和测试条件一致。

技术规范与官方资料

练习与参考解答

查看参考解答

`.ui-helper-hidden` 使用 `display: none` 会同时对视觉用户和屏幕阅读器隐藏内容;`.ui-helper-hidden-accessible` 通过绝对定位与 1px 裁剪实现视觉隐藏但保留辅助技术可访问性。`.ui-icon` 借助后代选择器(如 `.ui-state-default .ui-icon`、`.ui-state-error .ui-icon`)按父容器上下文切换不同色调的图标精灵图。

SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习