html - 防止在 CSS 中重叠 div

标签 html css overlap

我正在尝试使用 CSS 制作一个页面,其中来自 div 的内容不会相互重叠。当内容从ma​​in div(白色区域)溢出时,出现滚动条,你可以滚动侧边栏和标题的内容(忽略红线文本......这只是我的调试信息).

我没有将 CSS 与 HTML 分开,所以对于困惑的布局我深表歉意。 div 中的样式标签是我用来在页面上定位内容的。

可以在 https://jsbin.com/gesuser/edit?html 找到相关代码以及这篇文章的底部。

如何防止主 div 在页眉和边栏上滚动?我可以使用框架来做到这一点,但我不想使用那种旧技术。 :)

应该是这样的:enter image description here 而不是这样:enter image description here

如有任何帮助,我们将不胜感激。

    <div class="container">
        <div class="header" style="position: fixed; width: 100%; height: 50px; background-color: #133068;">
            <div id="appname" style="float: left;">
                <a href="index.php"><label style="position: relative; top: 12px; left: 5px; font: bold 20pt/22pt 'Syncopate', Arial, sans-serif; color: white;">Bluebook</label></a>
            </div>

            <div id="searchbar" style="position: fixed; float: right; top: 12px; right: 20px;">
                <form id="" name="form_Search_All" action="search.php" method="post">
                    <input type="text" id="text_Search" style="width: 350px;" name="text_Search" placeholder=" search all departments" />
                    <input type="submit" name="btnSearch_All" value="+" />

                    <input type="radio" id="radio_Search_BB" name="radio_Search" value="BB" checked /><label style="color: white;">BB</label>
                    <input type="radio" id="radio_Search_RC" name="radio_Search" value="RC" /><label style="color: white;">RC</label>
                </form>
            </div>
        </div>

        <div class="sidebar grad" style="position: fixed; top: 50px; width: 200px; height: 100%; background-color: #4e6799; z-index: -1;">
            <div class="btn-group" style="position: relative; top: 20px;">
                <?php if ($site->IsAdmin ()) : ?>
                    <a href="logout.php"><button class="button">ADMIN LOGOUT</button></a>

                <?php else : ?>
                    <a href="login.php"><button class="button">ADMIN LOGIN</button></a>

                <?php endif; ?>

                <a href="index.php"><button class="button">SEARCH PAGE</button></a>
            </div>

            <div id="version" style="position: absolute; bottom: 50px; margin: 5px; font: bold 9pt/11pt Arial; color: #9a9797;">
                <label>Version 2.0.0</label>
            </div>
        </div>

        <div class="main" style="position: absolute; top: 60px; left: 210px;">
            <?php $tpl->Component (); // this outputs tables of data ?>
        </div> <!-- main -->

    </div> <!-- container -->

最佳答案

不要对主 div 使用绝对位置。使用亲戚并为其添加边距:

<div class="main" style="position: relative; margin-top: 60px; margin-left: 210px;">
    <?php $tpl->Component (); // this outputs tables of data ?>
</div> 

关于html - 防止在 CSS 中重叠 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43458775/

相关文章:

android - 如何在android中添加重叠按钮

javascript - 是否可以使用 javascript 更改我的 css sprite 显示的子图像?

css - float :left div's 的垂直对齐

html - 如何使用 foreach 在 1 行中显示正确的 4 个缩略图

javascript - 绝对定位的jQuery animate?

r - 在多列中查找重叠段

html - Bootstrap 4 下拉菜单位于下方的 div 之上

javascript - 从 CSS 调用 javascript 函数

javascript - 自动更改可点击幻灯片顶部的 div 的文本颜色

Python:在迭代范围时将范围添加到范围列表中