gpt4 book ai didi

css - 更改全高导航栏元素背景颜色

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:29 25 4
gpt4 key购买 nike

我正在使用 bootstrap 4。我想复制此页面的设计:

https://www.stickermule.com/custom-stickers

为了更清晰的想法,我使用红色背景来说明我需要什么。

我可以将导航栏元素的背景颜色更改为红色,但顶部和底部有一个间隙。

我该如何解决这个问题?

enter image description here

CSS 代码:

li.nav-item:hover {
background-color: red;
}

代码:

<nav class="navbar navbar-expand-md navbar-dark fixed-top navbar-bg">
<!--<a class="navbar-brand" href="#">Navbar</a>-->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault"
aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarsExampleDefault">

<div class="col-md-8">
<ul class="navbar-nav mr-auto">

<li class="nav-item active">
<a class="nav-link" href="#">Stickers <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Etiquetas</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Magnetos</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Pines</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Pines</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Empaques</a>
</li>
<!--<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>-->


</ul>
</div>
<div class="col-md-4">

<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="glyphicon glyphicon-globe"></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">LogIn</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Registro</a>
</li>
</ul>
</div>
<!--<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
-->
</div>
</nav>

更新 1:

解决方案仅在添加导航标签时有效:

nav.navbar {padding: 0 1rem;}

不仅仅是:

.navbar {padding: 0 1rem;}

为什么?

我这样调用我的 css 文件:

<link href="{% static 'gallito_app/style.css' %}" rel="stylesheet">

头部内容:

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">

<title>Jumbotron Template for Bootstrap</title>

<!-- Bootstrap core CSS -->
<link href="../../dist/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="jumbotron.css" rel="stylesheet">
<!-- Custom styles for this template -->

<link href="{% static 'gallito_app/style.css' %}" rel="stylesheet">

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js" rel="stylesheet">


</head>

最佳答案

这也会改变导航栏的高度

.navbar {padding: 0 1rem;}

如果你想保持相同的高度添加

.navbar .nav-item{padding:1rem 1rem}

关于css - 更改全高导航栏元素背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52574695/

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