Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在某些动态元素需要绝对定位时避免内容重叠_Html_Css_Responsive Design - Fatal编程技术网

Html 在某些动态元素需要绝对定位时避免内容重叠

Html 在某些动态元素需要绝对定位时避免内容重叠,html,css,responsive-design,Html,Css,Responsive Design,codepen上有一个整洁的响应性组织结构图布局:它使用绝对定位来模仿老式组织结构图的效果。但是,它非常依赖绝对定位元素,以便使框显示在正确的位置 当您尝试将其放入自己的文档流时,会出现问题,与下面的内容重叠。显然,由于它是为响应而设计的,所以您无法预测内容的高度,而我希望采用的实现方式是,框的内容无论如何都是动态的-因此添加固定高度的div wrap似乎不是一个选项 我添加了一把小提琴来演示这个问题: *{ -webkit框大小:边框框; -moz框大小:边框框; 框大小:边框框; 位置:相

codepen上有一个整洁的响应性组织结构图布局:它使用绝对定位来模仿老式组织结构图的效果。但是,它非常依赖绝对定位元素,以便使框显示在正确的位置

当您尝试将其放入自己的文档流时,会出现问题,与下面的内容重叠。显然,由于它是为响应而设计的,所以您无法预测内容的高度,而我希望采用的实现方式是,框的内容无论如何都是动态的-因此添加固定高度的div wrap似乎不是一个选项

我添加了一把小提琴来演示这个问题:


*{
-webkit框大小:边框框;
-moz框大小:边框框;
框大小:边框框;
位置:相对位置;
}
.cf:之前,
.cf:之后{
内容:;/*1*/
显示:表格;/*2*/
}
.cf:之后{
明确:两者皆有;
}
/**
*仅适用于IE 6/7
*包含此规则以触发hasLayout并包含浮动。
*/
.cf{
*缩放:1;
}
/*通用样式*/
身体{
背景#F5EEC9;
}
.内容{
宽度:100%;
最大宽度:1142px;
保证金:0自动;
填充:0 20px;
}
a:焦点{
轮廓:2个虚线#F7F7;
}
@介质和全部(最大宽度:767px){
.内容{
填充:0 20px;
}   
}
保险商实验室{
填充:0;
保证金:0;
列表样式:无;
}
ul a{
显示:块;
背景:#ccc;
边框:4px实心#fff;
文本对齐:居中;
溢出:隐藏;
字体大小:.7em;
文字装饰:无;
字体大小:粗体;
颜色:#333;
高度:70像素;
边缘底部:-26px;
盒影:4px4px9px-4pxRGBA(0,0,0,0.4);
-webkit转换:全线性。1s;
-moz跃迁:全线性。1s;
过渡:全部线性。1s;
}
@介质和全部(最大宽度:767px){
ul a{
字号:1em;
}
}
跨距{
最高:50%;
边缘顶部:-0.7em;
显示:块;
}
/*
*/
.administration>li>a{
边缘底部:25px;
}
.director>li>a{
宽度:50%;
保证金:0自动0px自动;
}
.子目录:之后{
内容:“;
显示:块;
宽度:0;
高度:130像素;
背景:红色;
左边框:4px实心#fff;
左:45.45%;
位置:相对位置;
}
.子目录,
.部门{
位置:绝对位置;
宽度:100%;
}
.subdirector>li:第一个子目录,
.departments>li:第一个孩子{
宽度:18.59894921190893%;
高度:64px;
保证金:0自动92px自动;
填充顶部:25px;
边框底部:4倍纯白;
z指数:1;
}
.subdirector>li:第一个子目录{
浮动:对;
右:27.2%;
左边框:4倍纯白;
}
.departments>li:第一个孩子{
浮动:左;
左:27.2%;
右边框:4倍纯白;
}
.subdirector>li:第一个子目录a,
李:第一个孩子{
宽度:100%;
}
.subdirector>li:第一个子目录a{
左:25px;
}
@介质和全部(最大宽度:767px){
.subdirector>li:第一个子目录,
李:第一个孩子{
宽度:40%;
}
.subdirector>li:第一个子目录{
右:10%;
右边距:2px;
}
.子目录:之后{
左:49.8%;
}
李:第一个孩子{
左:10%;
左边距:2倍;
}
}
李:第一个孩子{
右:25px;
}
.部门:第一个孩子,
.李系:第n个孩子(2){
左边距:0;
清除:左;
}
.部门:之后{
内容:“;
显示:块;
位置:绝对位置;
宽度:81.1%;
高度:22px;
边框顶部:4px实心#fff;
右边框:4px实心#fff;
左边框:4px实心#fff;
保证金:0自动;
顶部:130像素;
左:9.1%
}
@介质和全部(最大宽度:767px){
.部门:之后{
边界权:无;
左:0;
宽度:49.8%;
}
}
.部门:以前{
内容:“;
显示:块;
位置:绝对位置;
宽度:0;
高度:22px;
左边框:4倍纯白;
z指数:1;
顶部:-22px;
左:50%;
左边距:-4px;
}
部门:第一个孩子:之前,
.部门:最后一个孩子:之前{
边界:无;
}
.部门{
左边框:4px实心#fff;
宽度:18.59894921190893%;
浮动:左;
左缘:1.751313485113835%;
边缘底部:60px;
}
.lt-ie8.部门{
宽度:18.25%;
}
@介质和全部(最大宽度:767px){
.部门{
浮动:无;
宽度:100%;
左边距:0;
}
.部门:以前{
内容:“;
显示:块;
位置:绝对位置;
宽度:0;
高度:60px;
左边框:4倍纯白;
z指数:1;
顶部:-60px;
左:0%;
左边距:-4px;
}
.部门:第n个孩子(2):之前{
显示:无;
}
}
.部门>a{
利润率:0.0-26px-4px;
z指数:1;
}
.department>a:悬停{
高度:80px;
}
.部门>ul{
边际上限:0px;
边缘底部:0px;
}
李{
左侧填充:25px;
边框底部:4px实心#fff;
高度:80px;
}
李a系{
背景:#fff;
顶部:48px;
位置:绝对位置;
z指数:1;
宽度:90%;
高度:60px;
垂直对齐:中间对齐;
右:-1px;
背景图像:-莫兹线性梯度(-45度,rgba(0,0,0,0.25)0%,rgba(0,0,0,0)100%)!重要;
背景图像:-webkit渐变(线性、左上、右下、颜色停止(0%,rgba(0,0,0,0.25))、颜色停止(100%,rgba(0,0,0,0))!重要;
背景图像:-webkit线性梯度(-45度,rgba(0,0,0,0.25)0%,rgba(0,0,0,0)100%)!重要;
背景图像:-o-线性梯度(-45度,rgba(0,0,0,0.25)0%,rgba(0,0,0,0)100%)!重要;
背景图像:-ms线性梯度(-45度,rgba(0,0,0,0.25)0%,rgba(0,0,0,0)100%)!重要;
背景图像:线性梯度(135度,rgba(0,0,0,0.25)0%,rgba(0,0,0,0)100%)!重要
<style>
*{
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    position: relative;
}

.cf:before,
.cf:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}

.cf:after {
    clear: both;
}

/**
 * For IE 6/7 only
 * Include this rule to trigger hasLayout and contain floats.
 */
.cf {
    *zoom: 1;
}

/* Generic styling */

body{
    background: #F5EEC9;    
}

.content{
    width: 100%;
    max-width: 1142px;
    margin: 0 auto;
    padding: 0 20px;
}

a:focus{
    outline: 2px dashed #f7f7f7;
}

@media all and (max-width: 767px){
    .content{
        padding: 0 20px;
    }   
}

ul{
    padding: 0;
    margin: 0;
    list-style: none;       
}

ul a{
    display: block;
    background: #ccc;
    border: 4px solid #fff;
    text-align: center;
    overflow: hidden;
    font-size: .7em;
    text-decoration: none;
    font-weight: bold;
    color: #333;
    height: 70px;
    margin-bottom: -26px;
    box-shadow: 4px 4px 9px -4px rgba(0,0,0,0.4);
    -webkit-transition: all linear .1s;
    -moz-transition: all linear .1s;
    transition: all linear .1s;
}


@media all and (max-width: 767px){
    ul a{
        font-size: 1em;
    }
}


ul a span{
    top: 50%;
    margin-top: -0.7em;
    display: block;
}

/*

 */

.administration > li > a{
    margin-bottom: 25px;
}

.director > li > a{
    width: 50%;
    margin: 0 auto 0px auto;
}

.subdirector:after{
    content: "";
    display: block;
    width: 0;
    height: 130px;
    background: red;
    border-left: 4px solid #fff;
    left: 45.45%;
    position: relative;
}

.subdirector,
.departments{
    position: absolute;
    width: 100%;
}

.subdirector > li:first-child,
.departments > li:first-child{  
    width: 18.59894921190893%;
    height: 64px;
    margin: 0 auto 92px auto;       
    padding-top: 25px;
    border-bottom: 4px solid white;
    z-index: 1; 
}

.subdirector > li:first-child{
    float: right;
    right: 27.2%;
    border-left: 4px solid white;
}

.departments > li:first-child{  
    float: left;
    left: 27.2%;
    border-right: 4px solid white;  
}

.subdirector > li:first-child a,
.departments > li:first-child a{
    width: 100%;
}

.subdirector > li:first-child a{    
    left: 25px;
}

@media all and (max-width: 767px){
    .subdirector > li:first-child,
    .departments > li:first-child{
        width: 40%; 
    }

    .subdirector > li:first-child{
        right: 10%;
        margin-right: 2px;
    }

    .subdirector:after{
        left: 49.8%;
    }

    .departments > li:first-child{
        left: 10%;
        margin-left: 2px;
    }
}


.departments > li:first-child a{
    right: 25px;
}

.department:first-child,
.departments li:nth-child(2){
    margin-left: 0;
    clear: left;    
}

.departments:after{
    content: "";
    display: block;
    position: absolute;
    width: 81.1%;
    height: 22px;   
    border-top: 4px solid #fff;
    border-right: 4px solid #fff;
    border-left: 4px solid #fff;
    margin: 0 auto;
    top: 130px;
    left: 9.1%
}

@media all and (max-width: 767px){
    .departments:after{
        border-right: none;
        left: 0;
        width: 49.8%;
    }
}

.department:before{
    content: "";
    display: block;
    position: absolute;
    width: 0;
    height: 22px;
    border-left: 4px solid white;
    z-index: 1;
    top: -22px;
    left: 50%;
    margin-left: -4px;
}

.department:first-child:before,
.department:last-child:before{
    border:none;
}

.department{
    border-left: 4px solid #fff;
    width: 18.59894921190893%;
    float: left;
    margin-left: 1.751313485113835%;
    margin-bottom: 60px;
}

.lt-ie8 .department{
    width: 18.25%;
}

@media all and (max-width: 767px){
    .department{
        float: none;
        width: 100%;
        margin-left: 0;
    }

    .department:before{
        content: "";
        display: block;
        position: absolute;
        width: 0;
        height: 60px;
        border-left: 4px solid white;
        z-index: 1;
        top: -60px;
        left: 0%;
        margin-left: -4px;
    }

    .department:nth-child(2):before{
        display: none;
    }
}

.department > a{
    margin: 0 0 -26px -4px;
    z-index: 1;
}

.department > a:hover{  
    height: 80px;
}

.department > ul{
    margin-top: 0px;
    margin-bottom: 0px;
}

.department li{ 
    padding-left: 25px;
    border-bottom: 4px solid #fff;
    height: 80px;   
}

.department li a{
    background: #fff;
    top: 48px;  
    position: absolute;
    z-index: 1;
    width: 90%;
    height: 60px;
    vertical-align: middle;
    right: -1px;
    background-image: -moz-linear-gradient(-45deg,  rgba(0,0,0,0.25) 0%, rgba(0,0,0,0) 100%) !important;
    background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%,rgba(0,0,0,0.25)), color-stop(100%,rgba(0,0,0,0)))!important;
    background-image: -webkit-linear-gradient(-45deg,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
    background-image: -o-linear-gradient(-45deg,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
    background-image: -ms-linear-gradient(-45deg,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
    background-image: linear-gradient(135deg,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#40000000', endColorstr='#00000000',GradientType=1 );
}

.department li a:hover{
    box-shadow: 8px 8px 9px -4px rgba(0,0,0,0.1);
    height: 80px;
    width: 95%;
    top: 39px;
    background-image: none!important;
}

/* Department/ section colors */
.department.dep-a a{ background: #FFD600; }
.department.dep-b a{ background: #AAD4E7; }
.department.dep-c a{ background: #FDB0FD; }
.department.dep-d a{ background: #A3A2A2; }
.department.dep-e a{ background: #f0f0f0; }
</style>

<h3>Some Content Above</h3>
<div class="content">
  <h1>Responsive Organization Chart</h1>
  <figure class="org-chart cf">
    <ul class="administration">
      <li>                  
        <ul class="director">
          <li>
            <a href="#"><span>Director</span></a>
            <ul class="subdirector">
              <li><a href="#"><span>Assistante Director</span></a></li>
            </ul>
            <ul class="departments cf">                             
              <li><a href="#"><span>Administration</span></a></li>

              <li class="department dep-a">
                <a href="#"><span>Department A</span></a>
                <ul class="sections">
                  <li class="section"><a href="#"><span>Section A1</span></a></li>
                  <li class="section"><a href="#"><span>Section A2</span></a></li>
                  <li class="section"><a href="#"><span>Section A3</span></a></li>
                  <li class="section"><a href="#"><span>Section A4</span></a></li>
                  <li class="section"><a href="#"><span>Section A5</span></a></li>
                </ul>
              </li>
              <li class="department dep-b">
                <a href="#"><span>Department B</span></a>
                <ul class="sections">
                  <li class="section"><a href="#"><span>Section B1</span></a></li>
                  <li class="section"><a href="#"><span>Section B2</span></a></li>
                  <li class="section"><a href="#"><span>Section B3</span></a></li>
                  <li class="section"><a href="#"><span>Section B4</span></a></li>
                </ul>
              </li>
              <li class="department dep-c">
                <a href="#"><span>Department C</span></a>
                <ul class="sections">
                  <li class="section"><a href="#"><span>Section C1</span></a></li>
                  <li class="section"><a href="#"><span>Section C2</span></a></li>
                  <li class="section"><a href="#"><span>Section C3</span></a></li>
                  <li class="section"><a href="#"><span>Section C4</span></a></li>
                </ul>
              </li>
              <li class="department dep-d">
                <a href="#"><span>Department D</span></a>
                <ul class="sections">
                  <li class="section"><a href="#"><span>Section D1</span></a></li>
                  <li class="section"><a href="#"><span>Section D2</span></a></li>
                  <li class="section"><a href="#"><span>Section D3</span></a></li>
                  <li class="section"><a href="#"><span>Section D4</span></a></li>
                  <li class="section"><a href="#"><span>Section D5</span></a></li>
                  <li class="section"><a href="#"><span>Section D6</span></a></li>
                </ul>
              </li>
              <li class="department dep-e">
                <a href="#"><span>Department E</span></a>
                <ul class="sections">
                  <li class="section"><a href="#"><span>Section E1</span></a></li>
                  <li class="section"><a href="#"><span>Section E2</span></a></li>
                  <li class="section"><a href="#"><span>Section E3</span></a></li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>   
      </li>
    </ul>           
  </figure>
</div>
<h3>Some Content Below</h3>
.departments{
    height:0;
    width: 100%;
}


@media all and (max-width: 767px){
    .department{
        float: left;
        width: 100%;
        margin-left: 0;
    }
}
<div class="top-content"></div>
<div class="middle-content">
  // org chart here
</div>
<div class="footer-content"></div>
.middle-content{
  position:relative;
  height:2500px;
}