Bootstrap 4.1.1 form-check form-check-inline 单选按钮

2024-05-03

我正在尝试将单选按钮显示为内联选项。 在 Bootstrap 4.1.1 文档中,示例代码是:

<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
  <label class="form-check-label" for="inlineRadio1">1</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">
  <label class="form-check-label" for="inlineRadio2">2</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" disabled>
  <label class="form-check-label" for="inlineRadio3">3 (disabled)</label>
</div>

尽管我将其克隆到我的 html 中,但它不起作用并且单选按钮显示正常。

My Html代码是:

{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'surveys/style.css' %}" />
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TFM Survey</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="{{ STATIC_URL }}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="{{ STATIC_URL }}/static/bootstrap/js/bootstrap.js" rel="stylesheet" media="screen">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
     <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="../../assets/js/html5shiv.js"></script>
      <script src="../../assets/js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="container">
    <form action="{% url 'surveys:vote' %}" method="post">
        {% csrf_token %}

        {% if questions %}
        <ul class="list-group">

        {% for question in questions %}
            <li class="list-group-item list-group-item-dark">{{ question.question_text}}</li>
            {% if question.choice_set.all %}
                {% for choice in question.choice_set.all %}
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="{{ question.id }}" id="choice{{ forloop.counter }}" value="{{ choice.choice_text }}">
                        <label class="form-check-label" for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label>
                    </div>
                {% endfor %}
            {% else %}
                <input type="text" class="form-control" placeholder="Type some answer..." name="{{ question.id }}"/>
            {% endif %}
        {% endfor %}
        </ul>
        {% else %}
            <p>No questions are available.</p>
        {% endif %}
        <input type="submit" class="btn btn-primary" value="Vote" />
    </form>
</div>
</body>
</html>

我也尝试使用class="checkbox-inline"但它也不起作用。 我已经看到div倾向于使用所有宽度,所以我还指定:

#radio-div{
 width:auto
}

但两者都不起作用(我在无线电输入中使用了 id 语句)。 有人知道这个实现中是否存在明显的错误吗?


在这里,你的<ul> <li>元素无效。 这意味着a内部只能有多个<li>元素。<ul>应该只包含li元素。

您的代码示例:在这里,您将单选按钮元素放在<li>元素。

<ul class="list-group">
  <li class="list-group-item list-group-item-dark">YOUR TEXT CONTENT</li>
  <div class="form-check form-check-inline">
    <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
    <label class="form-check-label" for="inlineRadio1">1</label>
  </div>
  <div class="form-check form-check-inline">
    <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
    <label class="form-check-label" for="inlineRadio1">1</label>
  </div>
</ul>

更正的代码示例:您需要将单选按钮元素代码放入其中<li>元素。

<ul class="list-group">
  <li class="list-group-item list-group-item-dark">YOUR TEXT CONTENT
    <div class="form-check form-check-inline">
      <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
      <label class="form-check-label" for="inlineRadio1">1</label>
    </div>
    <div class="form-check form-check-inline">
      <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
      <label class="form-check-label" for="inlineRadio1">1</label>
    </div>
  </li>
</ul>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bootstrap 4.1.1 form-check form-check-inline 单选按钮 的相关文章

随机推荐

  • 自定义 UIAlertView?

    鉴于蓝色与我的 UI 界面不相配 我只是想知道是否有办法更改 uialertview 的颜色 或者使用图像代替 所有按钮 关闭 等仍然存在 Thanks CodeCropper 的优秀人员刚刚推出了一个开源控件 可让您创建自定义警报视图 这
  • Big O 用于有限、固定大小的可能值集

    这个问题 https stackoverflow com questions 12305028 java what is the best way to find first duplicate character in a string引
  • 在画布中的鼠标位置放大/缩小

    我正在尝试使用 p5 js 实现缩放功能 当前缩放级别以及 x 和 y 位置存储在controls view目的 默认位置或 0 0 位置位于左上角 问题是调整放大 缩小时的 x 和 y 位置值 以便无论视图的当前位置是什么 它都会停留在缩
  • 调试 python Web 服务

    我正在使用找到的说明here http www diveintopython net http web services user agent html 尝试检查发送到我的网络服务器的 HTTP 命令 但是 我没有看到按照教程中的建议在控制
  • cuda中有模板化的数学函数吗? [复制]

    这个问题在这里已经有答案了 我一直在寻找 cuda 中的模板化数学函数 但似乎找不到 在普通的 C 中 如果我调用std sqrt它是模板化的 并且将根据参数是浮点数还是双精度数执行不同的版本 我想要这样的 CUDA 设备代码 我的内核将真
  • registerForActivityResult TakePicture 未触发

    我尝试使用新的 registerForActivityResult 来拍照 我可以打开相机意图 但拍照后 未触发回调 并且我在 logcat 上看不到任何有关 Activity Result 或错误的信息 我也尝试了RequestPermi
  • 如何在android中格式化长整型以始终显示两位数

    我有一个倒计时器 显示从 60 到 0 的秒数 1 分钟倒计时器 当它达到 1 位数字 例如 9 8 7 时 它显示 9 而不是 09 我尝试使用String format B 02d B x 我将 x 从 long 转换为字符串 它不起作
  • 角度材质选择不会检测嵌套组件生成的选项的更改

    我正在尝试提取过滤和显示我的逻辑mat option是我的mat selects 到他们自己的组件中 然而 由于某种原因 会显示选项 但单击它们不会触发事件 我正在编写的网络应用程序有很多mat select每个都可能有很多mat opti
  • 实体框架..自引用表..获取深度=x的记录?

    我成功地在实体框架中使用自引用表 但我不知道如何获得所需深度的记录 这应该是什么逻辑 Model public class FamilyLabel public FamilyLabel this Children new Collectio
  • fread 的填充选项

    假设我有这个 txt 文件 AA 3 3 3 3 CC ad 2 2 2 2 2 ZZ 2 AA 3 3 3 3 CC ad 2 2 2 2 2 With read csv I can gt read csv linktofile txt
  • 验证仅适用于数组的第一项

    给定这个模型代码 Required Display Name Name public string Name get set 以下查看代码有效 Html LabelFor model gt model Name Html TextBoxFo
  • 如何在 .NET 6.0 中使用最小 Api 配置 Newtonsoft Json

    I have net6 0具有最少 api 的项目 我想使用NetwtonsoftJson而不是内置的System Text Json用于序列化和反序列化的库 目前我有这个配置JsonOptions并且按预期工作 builder Servi
  • Laravel项目部署到Cpanel时出现404错误如何解决?

    我正在尝试将我的 laravel Laravel Framework 7 28 3 部署到 Cpanel 但出现 404 错误 我将项目上传到 public html 修改了 index php 文件以指向正确的文件 如下所示 我认为ind
  • React Native 中 SVG 中的定位图标

    背景 我正在尝试按照本教程将工具提示添加到react native svg图表中 教程链接 Link https levelup gitconnected com adding tooltip to react native charts
  • 二叉树实现C++

    二叉树插入 include stdafx h include
  • 从 Dataflow 中的 BigQuery 读取时设置 MaximumBillingTier

    当我从 BigQuery 读取数据作为查询结果时 我正在运行 GCP Dataflow 作业 我正在使用 google cloud dataflow java sdk all 版本 1 9 0 设置管道的代码片段如下所示 PCollecti
  • Spring中的server.error.include-binding-errors=on-param有什么作用?

    下面的设置是什么意思application properties在 Spring 应用程序中做什么 server error include binding errors on param 我在文档中找不到它 The always and
  • FireFox 中的默认表单按钮

    我正在构建一个服务器控件 它将搜索我们的数据库并返回结果 服务器控件包含一个 ASP Panel 我已将面板上的默认按钮设置为等于我的按钮 id 并将表单默认按钮设置为等于我的按钮 id 在面板上 MyPanel DefaultButton
  • captureWarnings 设置为 True 不会捕获警告

    我想记录所有警告 我以为这样的设定captureWarnings to True应该可以解决问题 但事实并非如此 代码 import logging import warnings from logging handlers import
  • Bootstrap 4.1.1 form-check form-check-inline 单选按钮

    我正在尝试将单选按钮显示为内联选项 在 Bootstrap 4 1 1 文档中 示例代码是 div class form check form check inline div