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

jquery - jQuery UI对话框的样式和大小问题-LMLPHP

CSS除了字体外没有设置任何其他内容。如果我添加max-height: 1.5em;,那么它们都将像下面一样相互堆叠。

jquery - jQuery UI对话框的样式和大小问题-LMLPHP

我不知道该怎么做,但下面是我的代码。我觉得这是由于页面上其他内容迫使元素移动所致。



    #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>

最佳答案

我只是将您的问题复制到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>





jquery - jQuery UI对话框的样式和大小问题-LMLPHP

10-05 20:39