【问题标题】:BootStrap Grid Not Working Correctly?BootStrap 网格无法正常工作?
【发布时间】:2017-03-27 07:41:18
【问题描述】:

我正在制作这个网页,到目前为止,我大部分时间都在完善动画,所以还没有任何内容,只有几个 div。正如您在图片中看到的那样,我遇到的问题是“行” div 包含短语 Hello World!不知何故落在包含灰色和橙色空白 div 的“行”的顶部。对于我的生活,我无法弄清楚为什么。我唯一能想到的可能是引导程序等的链接有问题?所有代码和屏幕截图如下。提前感谢您的帮助。

作为一个附带问题,目前并不重要,谁能告诉我为什么导航栏上方有一个小的白色间隙?

Link to screenshot of top 1/3rd of page and browser

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Timothy Sutterby">
<!-- <meta HTTP-EQUIV="refresh" CONTENT="10"> -->
<!-- The above 3 meta tags *must* come first in the head; any other head 
     content must come *after* these tags -->

<title>T G Sutterby</title>

<link rel="stylesheet"            href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://use.fontawesome.com/880f652677.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="CSS/TGSstyles.css">

</head>

<body>

<!-- Modals -->



<!-- End Modals -->

<!-- Nav Bar -->

<nav class="navbar navbar-inverse">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
</button>
    </div>
    <a class="navbar-brand" id="navbar-brand" href="#"><span id="brand-    span">Brand</span></a>
    <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-left">
            <li><a href="#">Left</a></li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">L Down <span class="caret"></span></a>
                <ul class="dropdown-menu">
                    <li><a href="#">Action</a></li>
                    <li><a href="#">Another action</a></li>
                    <li><a href="#">Something else here</a></li>
                    <li role="separator" class="divider"></li>
                    <li><a href="#">Separated link</a></li>
                    <li role="separator" class="divider"></li>
                    <li><a href="#">One more separated link</a></li>
                </ul>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"    role="button" aria-haspopup="true" aria-expanded="false">D Right <span    class="caret"></span></a>
                <ul class="dropdown-menu">
                    <li><a href="#">Action</a></li>
                    <li><a href="#">Another action</a></li>
                    <li><a href="#">Something else here</a></li>
                    <li role="separator" class="divider"></li>
                    <li><a href="#">Separated link</a></li>
                    <li role="separator" class="divider"></li>
                    <li><a href="#">One more separated link</a></li>
                </ul>
            </li>
            <li><a href="#contact">Right</a></li>
        </ul>
    </div>
</nav>

<!-- End Nav Bar -->

<!-- Body Elements -->

<div class="container-fluid">

    <!-- Animated/Expanding Div -->

    <div class="row outeranimDiv-TGS" id="outeranimDiv">
        <div class="leftanimDiv col-lg-5" id="animDiv2"></div>
        <div class="animDiv-TGS col-lg-2" id="animDiv1"></div>
        <div class="rightanimDiv col-lg-5" id="animDiv3"></div>
    </div>

    <!-- End Animated/Expanding Div -->

    <!-- Actual Body -->

    <div class="row bodyTGS">
        Hello World!
    </div>

    <!-- End Actual Body -->

</div>

<!-- End Body Elements -->

<!-- Scripts -->
<script>
    $(document).ready(function() {
        $("#animDiv1").animate({
            height: "400px"
        }, 500);
        $("#animDiv2, #animDiv3").delay(501).animate({
            backgroundColor: "gray"
        }, 500);
    });

</script>
<!-- End Scripts -->


</body>

还有 CSS:

body {
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
color: #333;
font-size: 12px;
background-color: black;
height: 100vh;
width: 100vw;
padding: 0;
}

.bodyTGS {
}

.outeranimDiv-TGS {
z-index: -1;
position: absolute;
top: 0px;
width: 100%;
text-align: center;
height: 400px;
}

.animDiv-TGS {
position: relative;
margin: 0 auto;
height: 2px;
width: 20%;
background-color: #ff9900;
}

.leftanimDiv {
position: relative;
margin: 0 auto;
background-color: black;
width: 40%;
height: 400px;
z-index: -1;
}

.rightanimDiv {
position: relative;
margin: 0 auto;
background-color: black;
width: 40%;
height: 400px;
z-index: -1;
}

.navbar-brand {
position: absolute;
font-size: 35px;
width: 100%;
left: 0;
text-align: center;
margin: 0 auto;
}

.navbar-toggle {
z-index: 3;
}

.navbar-right {
margin-right: 2px;
}

【问题讨论】:

    标签: html css twitter-bootstrap grid


    【解决方案1】:

    outeranimDiv-TGS 类有一个绝对位置

    要么将绝对位置改为浮动,然后清除浮动 或尝试此处建议的解决方案以在绝对位置后显示静态元素 Static elements after position:absolute

    不清楚你想要实现什么,你能发一张图片显示你希望 Hello World 出现在哪里吗?

    【讨论】:

    • 我使用了 position: absolute 因为我还使用了 z-index: -1 来移动导航栏后面的两个灰色 div 和橙色 div。我这样做是因为橙色 div 有一个动画,可以在页面加载时将其高度更改为 400px。它在导航栏后面开始像 20px 高。据我了解,您必须使用绝对、固定或相对位置来使用 z-index?我想要包含 Hello World 的 div!低于橙色和灰色的 div。
    • 好吧,将位置更改为相对工作。仍然不确定为什么这很重要,但如果它有效,它就有效。谢谢@SirNarsh。
    猜你喜欢
    • 2015-08-31
    • 2016-04-30
    • 1970-01-01
    • 2015-08-24
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    相关资源
    最近更新 更多