gpt4 book ai didi

html - 引导导航栏问题

转载 作者:行者123 更新时间:2023-11-28 16:32:36 27 4
gpt4 key购买 nike

所以,在 Flask 工作了一年之后,我将回到 Django。从那时起,我就习惯了使用 Bootstrap 3,我想把它带到 Django 上。不幸的是,我从一开始就遇到了一些严重的问题。具体来说,我很难让导航栏正常工作。

在 Firefox 中,我设法使导航栏看起来不错,并使下拉菜单正常工作。唯一的问题是,在下面的图片中很难看到,文本位于栏的下方。一些 css 魔法应该可以解决这个问题,但我使用 Bootstrap 的主要动机是尽可能多地处理 CSS。

A well behaved toolbar...mostly...

另一方面,在 Chrome 中,一切都是错误的。大错特错。发生了一些根本不涉及工具栏的事情...

Wrong. Wrong. Also, Wrong.

我在 ol' SE 上四处寻找此类问题,四处搜索,引用了 Bootstrap 的浏览器屏蔽墙,但我找不到任何东西,而且我对 CSS 和浏览器的了解不够,无法识别任何事物。谁能指出我正确的方向?我在 Ubuntu 14.04 上运行它(还没有在其他地方检查过)。

Bellow 是文件的代码,有 home extending base,并包含 nav 中的代码。

home.html:

{% extends "base.html" %}

{% block title %}
OASIS - Home
{% endblock %}

{% block content %}
<h1>NONE</h1>
{% endblock %}

base.html:

{% load compress %}
{% load staticfiles %}
<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>{% block title %}{% endblock title %}</title>
<meta name="description" content="">
<meta name="author" content="">


<link rel="shortcut icon" href="{{ STATIC_URL }}favicon.ico">

{% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}stylesheets/normalize.css">
<link rel="stylesheet" href="{{ STATIC_URL }}stylesheets/main.css">
<link rel="stylesheet" href="{{ STATIC_URL }}stylesheets/reset.css">
<link rel="stylesheet" href="{{ STATIC_URL }}stylesheets/bootstrap.min.css">
{% endcompress %}

{% compress js %}
<script src="{{ STATIC_URL}}javascripts/libs/jquery-1.11.3.js"></script>
<script src="{{ STATIC_URL}}javascripts/libs/bootstrap.min.js"></script>
<!--<script src="{{ STATIC_URL}}javascripts/libs/modernizr-2.0.6.js"></script>-->
{% endcompress %}

</head>
<body>
{% include "nav.html" %}
{% block content %}{% endblock content %}

{% compress js %}
{% endcompress %}

<script>
var _gaq=[['_setAccount','UA-6516194-8'],['_trackPageview']]; // Change UA-XXXXX-X to be your site's ID
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>

导航.html:

<nav class="navbar navbar-inverse navbar-fixed-top navbar-header" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img alt="logo" src="{{ STATIC_URL }}img/oasis_logo_tiny.png"></a>
<a class="navbar-brand" href="#">OASIS ON</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Admin<span class="sr-only">(current)</span></a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Library<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Collected Works</a></li>
<li><a href="#">Member Works</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">OASIS Canon</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <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>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

<!doctype html>
<html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>
OASIS - Home
</title>
<meta name="description" content="">
<meta name="author" content="">


<link rel="shortcut icon" href="/static/favicon.ico">


<link rel="stylesheet" href="/static/stylesheets/normalize.css">
<link rel="stylesheet" href="/static/stylesheets/main.css">
<link rel="stylesheet" href="/static/stylesheets/reset.css">
<link rel="stylesheet" href="/static/stylesheets/bootstrap.min.css">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<!--<script src="/static/javascripts/libs/modernizr-2.0.6.js"></script>-->


</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top navbar-header" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img alt="logo" src="/static/img/oasis_logo_tiny.png"></a>
<a class="navbar-brand" href="#">OASIS ON</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Admin<span class="sr-only">(current)</span></a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Library<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Collected Works</a></li>
<li><a href="#">Member Works</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">OASIS Canon</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <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>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>


<h1>NONE</h1>





<script>
var _gaq=[['_setAccount','UA-6516194-8'],['_trackPageview']]; // Change UA-XXXXX-X to be your site's ID
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>

P.S.:我没有看到任何浏览器的开发者工具弹出任何错误,尽管我很有可能没有正确使用它们。我可以做些什么来更好地调试这些东西吗?

最佳答案

问题是您使用的是 navbar-fixed-top .如果您阅读 Bootstrap 文档,它会明确指出:

Body padding required

The fixed navbar will overlay your other content, unless you add padding to the top of the <body> Try out your own values or use our snippet below. Tip: By default, the navbar is 50px high.

因此,要解决此问题,请将其添加到您的 css :

body { 
padding-top: 70px;
}

注意:Bootstrap 推荐 70px,但我通常坚持 15px 的边距,所以 65px 是一个不错的数字。

body{
padding-top: 65px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!doctype html>
<html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>
OASIS - Home
</title>
<meta name="description" content="">
<meta name="author" content="">


<link rel="shortcut icon" href="/static/favicon.ico">


<link rel="stylesheet" href="/static/stylesheets/normalize.css">
<link rel="stylesheet" href="/static/stylesheets/main.css">
<link rel="stylesheet" href="/static/stylesheets/reset.css">
<link rel="stylesheet" href="/static/stylesheets/bootstrap.min.css">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<!--<script src="/static/javascripts/libs/modernizr-2.0.6.js"></script>-->


</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top navbar-header" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img alt="logo" src="/static/img/oasis_logo_tiny.png"></a>
<a class="navbar-brand" href="#">OASIS ON</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Admin<span class="sr-only">(current)</span></a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Library<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Collected Works</a></li>
<li><a href="#">Member Works</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">OASIS Canon</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <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>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>


<h1>NONE</h1>





<script>
var _gaq=[['_setAccount','UA-6516194-8'],['_trackPageview']]; // Change UA-XXXXX-X to be your site's ID
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>

有关详细信息,请参阅 The Documentation

关于html - 引导导航栏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34027010/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com