简体   繁体   English

具有浮动div边框的重叠页面容器边框

[英]Overlap page container border with a floating div border

I'm trying to make a tab float vertically in a page with dynamic generated content and overlap the right border the page content container with the left border of the floating div. 我正在尝试使选项卡在具有动态生成内容的页面中垂直浮动,并使页面内容容器的右边界与浮动div的左边界重叠。

Here is a representation of what I'm trying to achieve : 这是我要实现的目标的表示

In the following fiddle there's a basic skeleton of my page and an example of what is happening. 在下面的小提琴中,有我页面的基本框架和正在发生的事的示例。

jsFiddle here jsFiddle在这里

If I add position: absolute to this class the floating tab is correctly positioned but the page will not grow correctly as the content is appended nor will the footer be correctly positioned. 如果我向此类添加位置:绝对,则浮动标签页的位置正确,但是随着内容的添加,页面也不会正确增长,页脚也不会正确定位。 On the other hand, if I remove the position absolute then the tab is not correctly positioned. 另一方面,如果我删除绝对位置,则选项卡位置不正确。

#page-content
{
    border: 1px solid lightblue;
    display: inline-block;
    width: 180px;
    padding: 10px;
    min-height: 100px;
    /*position: absolute;*/
}

How can I place the floating tab correctly overlapping the container border? 如何将浮动标签正确地与容器边框重叠放置?

Notes: I cannot change much of the page structure (wrapping div and footer) but if needs be, the floating div can be appended after the #inner div. 注意:我无法更改页面的大部分结构(包装div和页脚),但是如果需要,可以在#inner div之后附加浮动div。

Try this FIDDLE 试试这个FIDDLE

Just add this rules to your .floating-tab : 只需将以下规则添加到您的.floating-tab

margin-left: -1px;
z-index: 999;
float: left;

and float: left to your selector #page-content float: left选择器#page-content

Something like this: 像这样:

#inner
{
    text-align: left;
    margin-right: auto;
    margin-left: auto;
    display: inline-block;
    width: 200px;
    position: relative; /* positoning context */
}

.floating-tab
{
    position: absolute;    
    border-left: 1px solid #fff;
    border-top: 1px solid lightblue;
    border-right: 1px solid lightblue;
    border-bottom: 1px solid lightblue;
    width: 32px;
    text-align: center;
    top: 10px;
    left:100%; /* fully left */
    margin-left: 1px; /* width of border */
    z-index:2;

}

 $(function($) { var element = $(".floating-tab"), originalY = element.offset().top, topMargin = 10; $(window).on("scroll", function(event) { var scrollTop = $(this).scrollTop(); element.stop(false, false).animate({ top: scrollTop < originalY ? topMargin : scrollTop - originalY + topMargin }, 300); }); $("#B1").on("click", function() { $("#innercontent").append("<p>text 1</p><p>text 2</p><p>text 3</p><p>text 4</p><p>text 5</p><p>text 6</p><p>text 7</p><p>text 8</p><p>text 9</p><p>text 10</p>"); }); }); 
 .floating-tab { position: absolute; border-left: 1px solid #fff; border-top: 1px solid lightblue; border-right: 1px solid lightblue; border-bottom: 1px solid lightblue; width: 32px; text-align: center; top: 10px; left:100%; margin-left: 1px; z-index:2; } .floating-tab span { width: 24px; height: 24px; margin: 2px; } #page-content { border: 1px solid lightblue; display: inline-block; width: 180px; padding: 10px; min-height: 100px; } #inner { text-align: left; margin-right: auto; margin-left: auto; display: inline-block; width: 200px; position: relative; } #outer { width: 100%; padding-top: 10px; display: block; text-align: center; } #footer { margin-top: 17px; background-color: lightblue; border-top: 1px solid gray; height: 48px; } #pagewrapper { min-height: 100%; margin-bottom: -66px; } html, body, form { height:100%; } html { overflow: initial !important; } *, *::after, *::before { padding: 0px; margin: 0px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="pagewrapper"> <div id="outer"> <div id="inner"> <div id="page-content"> <input type="button" value="add content" id="B1" /> <div id="innercontent"></div> </div> <div class="floating-tab"> <span>A</span> <span>B</span> <span>C</span> <div> </div> </div> </div> <div id="footer">FOOTER</div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM