【问题标题】:Bootstrap4 Form Example is Rendering IncorrectlyBootstrap4 表单示例呈现不正确
【发布时间】:2021-03-09 14:57:12
【问题描述】:

我正在尝试构建一个简单的电子邮件表单,例如 Bootstrap 4 docs,但由于某种原因格式错误。

示例如下所示:

但由于某种原因,这是它在我的项目中编译的内容:

很明显,我的代码库/环境中有一些东西弄乱了布局。为什么我的字段不像示例那样位于单独的行中?为什么元素之间没有间距?为什么提交按钮不是蓝色的?一团糟。我的 bootstrap 4 依赖安装不正确吗?

我正在使用示例中的确切 html。代码如下。

<template>
<form>
    <div class="form-group">
      <label for="exampleInputEmail1">Email address</label>
      <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
      <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
    </div>
    <div class="form-group">
      <label for="exampleInputPassword1">Password</label>
      <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
    </div>
    <div class="form-check">
      <input type="checkbox" class="form-check-input" id="exampleCheck1">
      <label class="form-check-label" for="exampleCheck1">Check me out</label>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</template>

main.ts

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// @ts-ignore
createApp(App).use(store).use(router).mount('#app')

【问题讨论】:

  • 您可能需要将 CSS 导入到您的项目中。你能展示你的 main.js 吗?如果您还没有使用它,请查看BoostrapVue
  • 用我的 main.ts 文件更新了我的帖子。我现在正在研究 BootstrapVue
  • 现在,添加到 main.jsimport 'bootstrap';import 'bootstrap/dist/css/bootstrap.min.css';
  • 有 2 个导入,请确保同时使用。如果您决定使用BootstrapVue,您还需要两者。
  • @Dan 很有趣,在项目中包含 Bootstrap4.5 的 main.ts 文件的典型导入代码确实不适用于 Vue3,您必须使用您专门共享的 2 个导入bootstrap-vue.org 文档指出的内容。显然,Bootstrap 团队的目标是在 2020 年底之前通过 Bootstrap5 支持 Vue3。github.com/bootstrap-vue/bootstrap-vue/issues/5196

标签: html css vue.js bootstrap-4 bootstrap-modal


【解决方案1】:

如果您正在为静态网站或基本内容寻找简单的解决方案 您需要做的就是将此cdn添加到您的html中


    <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

还有这个用于下拉菜单和导航栏的引导 javascript cdn

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

和 jQuery cdn

查看此链接以获取实时预览

https://stackblitz.com/edit/web-platform-ss4nvu?file=script.js

基本上这个

    <link rel="stylesheet" type="text/css"
        href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

在头部标签:)

但我看到你在标签中提到了 vue js 你正在寻找答案,所以我也建议你去抛出 vueJS bootstrap 的网站,如果你有任何问题我也可以在 gmail 中使用,这太棒了:)

dolev146@gmail.com

【讨论】:

【解决方案2】:

您忘记从引导程序链接 css 文件。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

复制粘贴到你的html头部

另请阅读入门文档:bootstrap get started doc

【讨论】:

    猜你喜欢
    • 2018-04-08
    • 2018-09-13
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    相关资源
    最近更新 更多