【问题标题】:Get div and its content at the top on:hover without disturbing other content获取顶部的 div 及其内容:悬停而不干扰其他内容
【发布时间】:2014-12-01 22:32:24
【问题描述】:

我创建了一个包含多个框的弹出窗口。我想要做的是当用户将鼠标悬停在任何“.deviceboxes”上时,特定的盒子宽度应该扩大并且它应该在网页上的每个内容上都可见。为了实现这一点,我编写了“.deviceboxes:hover”,仅适用于行中的第一个框。但是当我将鼠标悬停在其他盒子上时,它会扰乱布局。我应该怎么做才能做到这一点?

以下是我的 HTML 内容

<div class="modal-body">
    <div id="leftsection">
      <div class="deviceboxes">
            <div id="boxlabel_NetworkDevice_97" class="title">NetworkDevice_97</div>
                <div id="NetworkDevice_97_1" class="cmds">Command 1</div>
                <div id="NetworkDevice_97_0" class="cmds">Command 2</div>
            </div>

      <div class="deviceboxes mrgnleft">
        <div id="boxlabel_NetworkDevice_9" class="title">NetworkDevice_9</div>
        <div id="NetworkDevice_9_1" class="cmds"Command_1</div>
        <div id="NetworkDevice_9_0" class="cmds">Command_2</div>
      </div>
    </div>
</div>

以下是一个 CSS :

.modal-body{ overflow: hidden; position: relative;} 
#fetch_commands{ left: 34% !important; width:1000px !important; height:500px; overflow: hidden;}
#leftsection{ float: left; width: 730px; height: 400px; overflow-y: scroll; overflow-x: hidden; min-height: 200px;}
#rightsection{position: relative; width: 200px; height: 400px; overflow-y: scroll; overflow-x: hidden; margin-left: 10px; padding-left: 20px; }
.netDevices { width:98%; padding: 5px 0px 5px 5px; cursor: pointer;}
.netDevices:hover {background: #406BA3; color: #FFF !important; -webkit-transition: all 1s; -moz-transition: all 1s; -o-transition: all 1s;}
.processing{ background: #006002; color: #FFF;}
.success{ background: none; color: #006002;}
.failed{ background: node; color: #FF0A16;}

.deviceboxes{ float: left; width: 215px; height: 200px; border: 1px solid #666; overflow-x: hidden;-webkit-transition: all 1s; -moz-transition: all 1s; -o-transition: all 1s;}
.deviceboxes:hover{ position:absolute !important; z-index:999999; width:500px !important; -webkit-transition: all 1s; -moz-transition: all 1s; -o-transition: all 1s;}
.title{ width: 100%; text-align: center; background: #000; color:#FFF; padding:10px; cursor: pointer;}
.cmds{ width: 195px; text-align: left; background: none; color:#000; padding:2px; margin-left: 5px; cursor: pointer; overflow-x: hidden; white-space: nowrap;}
.mrgnleft{ margin-left:10px; }
.mrgntop{ margin-top:10px; }
.navbar-inner { min-height: 65px!important; }

【问题讨论】:

  • 您将divs 向左浮动,然后在悬停时通过绝对定位它们将它们从流程中移除。
  • 我是程序员,实际上不是 UI 开发人员,对 CSS 不太擅长。你能详细解释一下吗??

标签: jquery html css


【解决方案1】:

您可以进行 2 项简单的更改。

  1. 为了补偿从 215 - 500px 增加的宽度,您可以设置负边距,以便将以下元素拉回其原始位置。在这种情况下,它需要是 215-500 = -285px

  2. 下一步,而不是使用position:absolute。您可以将position:relative 用于所有.deviceboxes(不仅仅是悬停),因此它仍然会对页面流产生一些影响。这也意味着 z-indexing 将按照您的意愿工作。

请注意,您只需将transition 设置应用于基本状态,而不是hover,如果它们相同的话。只是节省了几位。

.modal-body {
    overflow: hidden;
    position: relative;
}
#fetch_commands {
    left: 34% !important;
    width:1000px !important;
    height:500px;
    overflow: hidden;
}
#leftsection {
    float: left;
    width: 730px;
    height: 400px;
    overflow-y: scroll;
    overflow-x: hidden;
    min-height: 200px;
}
#rightsection {
    position: relative;
    width: 200px;
    height: 400px;
    overflow-y: scroll;
    overflow-x: hidden;
    margin-left: 10px;
    padding-left: 20px;
}
.netDevices {
    width:98%;
    padding: 5px 0px 5px 5px;
    cursor: pointer;
}
.netDevices:hover {
    background: #406BA3;
    color: #FFF !important;
    -webkit-transition: all 1s;
    -moz-transition: all 1s;
    -o-transition: all 1s;
}
.processing {
    background: #006002;
    color: #FFF;
}
.success {
    background: none;
    color: #006002;
}
.failed {
    background: node;
    color: #FF0A16;
}
.deviceboxes {
    float: left;
    position:relative;
    width: 215px;
    height: 200px;
    border: 1px solid #666;
    overflow-x: hidden;
    -webkit-transition: all 1s;
    -moz-transition: all 1s;
    -o-transition: all 1s;
}
.deviceboxes:hover {
    margin-right:-285px;
    z-index:999999;
    width:500px !important;
}
.title {
    width: 100%;
    text-align: center;
    background: #000;
    color:#FFF;
    padding:10px;
    cursor: pointer;
}
.cmds {
    width: 195px;
    text-align: left;
    background: none;
    color:#000;
    padding:2px;
    margin-left: 5px;
    cursor: pointer;
    overflow-x: hidden;
    white-space: nowrap;
}
.mrgnleft {
    margin-left:10px;
}
.mrgntop {
    margin-top:10px;
}
.navbar-inner {
    min-height: 65px!important;
}
<div class="modal-body">
    <div id="leftsection">
        <div class="deviceboxes">
            <div id="boxlabel_NetworkDevice_97" class="title">NetworkDevice_97</div>
            <div id="NetworkDevice_97_1" class="cmds">Command 1</div>
            <div id="NetworkDevice_97_0" class="cmds">Command 2</div>
        </div>
        <div class="deviceboxes mrgnleft">
            <div id="boxlabel_NetworkDevice_9" class="title">NetworkDevice_9</div>
            <div id="NetworkDevice_9_1" class="cmds">Command_1</div>
            <div id="NetworkDevice_9_0" class="cmds">Command_2</div>
        </div>
    </div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多