gpt4 book ai didi

css - Bootstrap 4 - H3 inside 下 zipper 接

转载 作者:行者123 更新时间:2023-11-28 00:34:48 32 4
gpt4 key购买 nike

我对导航栏中的下拉菜单有疑问。对于普通的导航链接(无下拉菜单),我将菜单文本放在 H3 中,但是当我尝试对下 zipper 接执行相同操作时,箭头不在标题旁边,而是在标题下方。我决定用 span 替换 h3 并提供与 h3 相同的 CSS,这次箭头在正确的位置,但没有考虑所有其他样式。

第三个例子更接近我想要的,但是字体大小不太一样。

没有下拉的原始代码

html {
font-size: 16px;
}

body {
font-family: Arial;
font-size: 1rem;
}

#logo {
max-height: 2.5rem;
}

.nav_container {
margin-bottom: 10%;
}

h1,h2,h3,h4,h5,h6 {
margin-bottom: .25rem;
margin-top: .25rem;
}

h3 {
font-size: 1.25rem;
}
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Original</title>
<!-- Bootstrap 3.0-->
<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.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- Bootstrap 4.0-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<!-- FontAwesome5 Icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">

<!-- CSS -->
<link rel="stylesheet" type="text/css" href="css/main.css">
<!-- Fin liens CSS et Script -->
</head>

<body>
<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="/image/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>

</ul>
</nav>
</div>
</body>

</html>

我的尝试

html {
font-size: 16px;
}

body {
font-family: Arial;
font-size: 1rem;
}

#logo {
max-height: 2.5rem;
}

.nav_container {
margin-bottom: 10%;
}

#navbardrop {
font-size: 1.25rem;
}

#navbardrop2 {
font-size: 1.25rem;
}

#navbardrop3 {
font-size: 1.25rem;
margin-bottom: .25rem;
margin-top: .25rem;
}

#admin_menu {
font-weight: 700!important;
margin-bottom: .25rem;
margin-top: .25rem;
}

h1, h2, h3, h4, h5, h6 {
margin-bottom: .25rem;
margin-top: .25rem;
}

h3 {
font-size: 1.25rem;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Example</title>
<!-- Bootstrap 3.0-->
<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.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- Bootstrap 4.0-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<!-- FontAwesome5 Icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">

<!-- CSS-->
<link rel="stylesheet" type="text/css" href="css/main.css">
<!-- Fin liens CSS et Script -->
</head>

<body>
<h2>Try 1</h2>
<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="/image/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link 1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>

<!-- Admin -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
<h3 id="admin_menu">Admin</h3>
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">
<h4>Admin1</h4>
</a>
<a class="dropdown-item" href="#">
<h4>Admin2</h4>
</a>
</div>
</li>
</ul>
</nav>
</div>

<h2>Try 2</h2>

<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="/image/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link 1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>

<!-- Admin -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop2" data-toggle="dropdown"><span id="admin_menu">Admin</span></a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">
<h4>Admin1</h4>
</a>
<a class="dropdown-item" href="#">
<h4>Admin2</h4>
</a>
</div>
</li>
</ul>
</nav>
</div>

<h2>Try 3</h2>

<div class="nav_container">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="d-flex align-items-center">
<a class="navbar-brand" href="#"><img id="logo" src="/image/440u9.png"></a>
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-uppercase" href="index.php">
<h3 class="font-weight-bold">Home</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link 1</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link2</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link3</h3>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<h3 class="font-weight-bold">Link4</h3>
</a>
</li>

<!-- Admin -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle font-weight-bold" href="#" id="navbardrop3" data-toggle="dropdown">Admin</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">
<h4>Admin1</h4>
</a>
<a class="dropdown-item" href="#">
<h4>Admin2</h4>
</a>
</div>
</li>
</ul>
</nav>
</div>
</body>

</html>

最佳答案

position:relative 赋给 h3,将 position:absolute 赋给 :after 并进行相应调整。谢谢

关于css - Bootstrap 4 - H3 inside 下 zipper 接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54233512/

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