首页 > 解决方案 > jQuery UI 对话框样式和大小问题

问题描述

我正在制作一个 jQuery UI 对话框。它看起来非常好,而且我的样式很有效,但是对话框中的第一段元素很大。

大段截图

CSS没有设置字体以外的任何东西。如果我添加max-height: 1.5em;,那么它们都会像下面那样堆叠在一起。

元素

我不知道这是做什么的,但我的代码如下。我有一种感觉,这是由于页面上其他地方的内容迫使元素移动。

    #cadEditor {
      display: none;
      z-index: 999999 !important;
      background: #222;
    }

    .ui-dialog {
      background: #222;
    }

    .ui-dialog .ui-dialog-titlebar {
      background: #333;
      height: 40px;
      top: 0;
      text-align: center;
      line-height: 40px;
    }

    .ui-dialog .ui-dialog-title {
      position: absolute;
      top: 0;
      display: block;
      width: 100%;
      height: fit-content;
      text-align: center;
    }

    #cadEditor p {
      max-height: 1.5em;
    }

    .ui-dialog .ui-dialog-titlebar-close {
      display: none;
    }

    .ui-dialog .ui-button {
      color: #fff;
      background: #222;
      padding: 0.3em 0.5em;
      border: #000000 1px solid;
      border-radius: 5px;
      margin: 1em;
      cursor: pointer;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<div id="cadEditor">
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
    <p>Test Dialog</p>
</div>
<script>
    function showCadEditor(button) {
        $('#cadEditor').dialog({
            dialogClass: "cadEditorDialog",
            autoOpen: true,
            title: "Editing Cad " + $(button).attr("forcad"),
            modal: true,
            resizable: false,
            width: 600,
             buttons: {
                "Save": function () {
                    $(this).dialog("close");
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        return false;
    }

    showCadEditor();
</script>

标签: jqueryhtmlcssjquery-ui

解决方案


我刚刚将您的问题复制到了html。对我来说看起来不错。你能更详细地解释你的问题吗?可能是站点的样式覆盖了弹出窗口的样式。

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Title Goes Here</title> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<style>
    #cadEditor {
      display: none;
      z-index: 999999 !important;
      background: #222;
    }

    .ui-dialog {
      background: #222;
    }

    .ui-dialog .ui-dialog-titlebar {
      background: #333;
      height: 40px;
      top: 0;
      text-align: center;
      line-height: 40px;
    }

    .ui-dialog .ui-dialog-title {
      position: absolute;
      top: 0;
      display: block;
      width: 100%;
      height: fit-content;
      text-align: center;
    }

    #cadEditor p {
      max-height: 1.5em;
    }

    .ui-dialog .ui-dialog-titlebar-close {
      display: none;
    }
    
    body{color: white}
</style>
</head>
    <body> <p>This is my web page</p>
    <div id="cadEditor">
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
        <p>Test Dialog</p>
    </div>
    <script>
        function showCadEditor(button) {
            $('#cadEditor').dialog({
                dialogClass: "cadEditorDialog",
                autoOpen: true,
                title: "Editing Cad " + $(button).attr("forcad"),
                modal: true,
                resizable: false,
                width: 600,
                 buttons: {
                    "Save": function () {
                        $(this).dialog("close");
                    },
                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });

            return false;
        }

        showCadEditor();
    </script>    
</body>
</html>

在此处输入图像描述


推荐阅读