【问题标题】:jQuery UI dialog styling and size issuesjQuery UI 对话框样式和大小问题
【发布时间】:2018-06-10 09:54:58
【问题描述】:

我正在制作一个 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>

【问题讨论】:

  • 删除代码片段示例中的最大高度时,它看起来仍然很好。你能验证一下并与你的原始代码进行比较吗?如果是,并且您的原件仍然存在问题,您能否提供原件的链接?
  • 令人讨厌的是,我无法提供链接,因为该网站受密码保护。该对话框独立工作,但在网站本身中不起作用,这就是我认为内容会影响它的原因。

标签: jquery html css jquery-ui


【解决方案1】:

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

【讨论】:

  • 我认为这与我网站的侧边栏(导航菜单)有关。当屏幕窄于 700 像素时,我的页面会隐藏它,当它被隐藏时,对话框看起来很好。
  • 不,这与酒吧的大小有关。有什么办法可以让 div 不受任何东西的影响?
【解决方案2】:

我通过position: absolute; 将问题修复到对话框内容 (#cadEditor)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 2010-10-16
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2011-05-24
    • 1970-01-01
    相关资源
    最近更新 更多