gpt4 book ai didi

css - 如何使用自定义 css 修复导航栏列表项

转载 作者:行者123 更新时间:2023-11-28 00:09:01 25 4
gpt4 key购买 nike

我正在为我的网站制作一个自定义导航栏,但列表项没有按我想要的方式显示。

这是我试过的 JSFiddle .在我的本地主机中,我得到 This Output .

感谢您的宝贵时间。

这是html代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="css/custom.css" rel="stylesheet">
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>

<body>
<div class="top-nav-shadow">
<nav class="navbar bg-nav">
<div class="navbar-brand">
Contact: <a href="#">+91 xxxxxxxxxx or xxxxxxxxx </a>
</div>
<div class="top-nav-logo">
<img src="images/IN.png">
<img class="img2" src="images/PV.png">
</div>
</nav>
</div>
<div>&nbsp;</div>
<div class="nav-shadow">
<nav class="navbar bg-nav-inverse">
<div class="container-fluid">
<div>
<img src="images/logo.png" class="navbar-logo">
</div>
<div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Courses</a></li>
</ul>
</div>
</div>
</nav>
</div>

</body>
</html>

这是CSS

@charset "utf-8";
/* CSS Document */
.bg-nav
{
background: #008080; /* Old browsers */
background: -moz-linear-gradient(-45deg, #008080 0%, #008080 80%, #ffffff 81%, #ffffff 81%, #ffffff 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(-45deg, #008080 0%,#008080 80%,#ffffff 81%,#ffffff 81%,#ffffff 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(135deg, #008080 0%,#008080 80%,#ffffff 81%,#ffffff 81%,#ffffff 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#008080', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
border-top:1px solid #008080;
max-height:30px;
}
.bg-nav-inverse
{
background: #ffffff; /* Old browsers */
background: -moz-linear-gradient(-45deg, #ffffff 0%, #ffffff 17%, #008080 18%, #008080 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(-45deg, #ffffff 0%,#ffffff 17%,#008080 18%,#008080 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(135deg, #ffffff 0%,#ffffff 17%,#008080 18%,#008080 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#008080',GradientType=1 );
color:black;
border-bottom:1px solid #008080;
max-height:50px;
}
.top-nav-shadow
{ margin-top:3px;
-webkit-box-shadow: 0px -4px 3px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 0px -4px 3px rgba(50, 50, 50, 0.75);
box-shadow: 0px -4px 3px rgba(50, 50, 50, 0.75);
}
.nav-shadow
{
-webkit-box-shadow: 0 8px 6px -6px black;
-moz-box-shadow: 0 8px 6px -6px black;
box-shadow: 0 8px 6px -6px black;
}
.navbar-logo
{
max-width:11%;;
margin-top:-45px;
margin-left:0px;
margin-bottom:-20px;
}
.top-nav-logo
{
margin-top:-18px;
}
.top-nav-logo img
{
max-height:60px;
margin-left:30px;

}
.top-nav-logo .img2
{
max-height:73px;
padding-left:10px;
}
.navbar-brand
{
font-family:Aharoni;
font-size:18px;
color:white;
padding:0px;
margin-top:-48px;
}

.navbar-brand a{
text-decoration:none;
color:white;
background-color:transparent;
font-size:20px;

}
.navbar-brand a: hover
{
text-decoration:none;
color:#CCC;
}
@media only screen and (max-width: 600px)
{
.bg-nav
{
background: #008080; /* Old browsers */
background: -moz-linear-gradient(-45deg, #008080 0%, #008080 63%, #ffffff 64%, #ffffff 64%, #ffffff 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(-45deg, #008080 0%,#008080 63%,#ffffff 64%,#ffffff 64%,#ffffff 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(135deg, #008080 0%,#008080 63%,#ffffff 64%,#ffffff 64%,#ffffff 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#008080', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
}
.bg-nav-inverse
{
background: #ffffff; /* Old browsers */
background: -moz-linear-gradient(-45deg, #ffffff 0%, #ffffff 37%, #008080 38%, #008080 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(-45deg, #ffffff 0%,#ffffff 37%,#008080 38%,#008080 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(135deg, #ffffff 0%,#ffffff 37%,#008080 38%,#008080 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#008080',GradientType=1 );
color:black;
}

}

我希望输出为 This Image

我已经把我做的都贴出来了,所以我希望你能告诉我我哪里做错了。

最佳答案

我有一些空闲时间并且对 Bootstrap 很好奇,所以我以我认为最好的方式集成了您想要的输出(第一次使用 Bootstrap 哈哈)。

代码片段:

@charset "utf-8";

.navbar {
border: 1px solid #008080;
border-width: 1px 0;
box-shadow: 0px -4px 3px rgba(50, 50, 50, 0.75), 0 8px 6px -6px black;
}

.navbar-contact,
.nav {
background: #008080;
overflow: hidden;
}

.navbar-contact {
max-height: 29px;
}

.bottom {
margin-top: -30px;
}

/* White Angles (Common) */

.nav:before,
.navbar-contact:after {
content: "";
background: #fff;
position: absolute;
width: 2em; height: 2.5em;
transform: skew(-30deg);
}

/* .navbar-contact angle position */

.navbar-contact:after {
right: -1em;
top: 0;
}

/* .nav angle position */

.nav:before {
left: -1em;
top: 0;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>

<html>
<body>
<nav class="navbar p-0">
<div class="top d-flex w-100">
<div class="px-2 navbar-contact text-white position-relative flex-grow-1">Contact: <a class="text-white" href="#">+91 xxxxxxxxxx or xxxxxxxxxx </a></div>
<div class="pt-1 pr-3 d-flex mt-auto bg-white position-relative">
<img class="position-relative ml-2 mr-1" src="http://computervision.in/images/IN.png" height="50">
<img class="position-relative mx-3" src="http://computervision.in/images/PV.png" height="55">
</div>
</div>
<div class="bottom d-flex w-100">
<a href="" class="navbar-brand mr-0">
<img src="http://computervision.in/images/logo.png" height="60">
</a>
<ul class="nav mt-auto flex-grow-1 pl-4 position-relative">
<li class="nav-item active"><a class="nav-link text-white active" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link text-white" href="#">Services</a></li>
<li class="nav-item"><a class="nav-link text-white" href="#">Courses</a></li>
</ul>
</div>
</nav>
</body>
</html>

JSFiddle:

https://jsfiddle.net/3L7tmbxk/

总结:

  • 我将您的渐变背景转换为伪元素 Angular 。它们相对于容器放置,以获得更好的响应能力,并利用 Bootstrap 4 flexbox 实现。
  • 我尽可能多地使用 Bootstrap 类,但我认为您可以进一步改进它。这是我第一次使用它,所以我不知道所有可能的配置和所有可用的类。
  • 我将您的图片的高度直接设置到它们的 img 标签中。

关于css - 如何使用自定义 css 修复导航栏列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55510471/

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