英文:
Align button in a navbar with bootstrap5 and vue
问题
这是我的应用程序中视图的模板,我尝试创建一个简单的导航栏,但正如您所看到的,注册按钮与其他文本不对齐。我正在使用Bootstrap 5和Vue 3。
<template>
<nav class="navbar navbar-expand-md navbar-light bg-light">
<a class="navbar-brand" href="/">
<img src="../assets/logo.png" width="60" height="60" alt=".">
<strong>Foodmate</strong>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto text-center">
<li class="nav-item active">
<a class="nav-link" href="/about">Chi siamo</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/login">Accedi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/signup">
<button type="button" class="btn btn-outline-success" id="registerButton">Registrati</button>
</a>
</li>
</ul>
</div>
</nav>
</template>
<style>
#registerButton{
border-radius: 20px;
}
</style>
我尝试阅读文档,但无法找到解决方案。
英文:
this is the template of a view in my app,i am trying to do a simple navbar but as you can see the sign up button is non aligned with the rest of the text.What can i do?
I am using bootstrap5 and vue3.
<template>
<nav class="navbar navbar-expand-md navbar-light bg-light">
<a class="navbar-brand" href="/">
<img src="../assets/logo.png" width="60" height="60" alt=".">
<strong>Foodmate</strong>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto text-center">
<li class="nav-item active">
<a class="nav-link" href="/about">Chi siamo</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/login">Accedi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/signup">
<button type="button" class="btn btn-outline-success" id="registerButton">Registrati</button>
</a>
</li>
</ul>
</div>
</nav>
</template>
<style>
#registerButton{
border-radius: 20px;
}
</style>
I've tried to read the documentation but i cannot find a solution.
答案1
得分: 0
只删除锚点标签内的按钮。你可以只使用 a
,btn
类也适用于它:
<a class="nav-link btn btn-outline-success" href="/signup" id="registerButton">
Registrati
</a>
这是代码片段中的部分。
<!-- begin snippet: js hide: true console: true babel: false -->
<!-- language: lang-css -->
#registerButton{
border-radius: 20px;
}
<!-- language: lang-html -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<nav class="navbar navbar-expand navbar-light bg-light">
<a class="navbar-brand" href="/">
<strong>Foodmate</strong>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto text-center">
<li class="nav-item active">
<a class="nav-link" href="/about">Chi siamo</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/login">Accedi</a>
</li>
<li class="nav-item">
Registrati
</li>
</ul>
</div>
</nav>
<!-- end snippet -->
英文:
Just remove the button from inside the anchor tag. You can just use the a
, the btn
class works with it too:
<a class="nav-link btn btn-outline-success" href="/signup" id="registerButton">
Registrati
</a>
Here it is in the snippet.
<!-- begin snippet: js hide: true console: true babel: false -->
<!-- language: lang-css -->
#registerButton{
border-radius: 20px;
}
<!-- language: lang-html -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<nav class="navbar navbar-expand navbar-light bg-light">
<a class="navbar-brand" href="/">
<strong>Foodmate</strong>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto text-center">
<li class="nav-item active">
<a class="nav-link" href="/about">Chi siamo</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/login">Accedi</a>
</li>
<li class="nav-item">
<a class="nav-link btn btn-outline-success" href="/signup" id="registerButton">
Registrati
</a>
</li>
</ul>
</div>
</nav>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论