如何将Bootstrap的下拉框应用到Flask的下拉框?

huangapple go评论135阅读模式
英文:

How to apply a Bootstrap combobox to a Flask combobox?

问题

我想在Flask combobox上使用Bootstrap combobox。目前Flask combobox对我来说运行正常。如何将Bootstrap按钮样式应用于它?

Bootstrap Combobox

<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  Small button
</button>

Flask 代码

<form name="Item_1" action="/combobox" method="POST">
    <select name="colours">
      {% for colour in colours %}
        {% if colour == chosen %}
         <option value="{{ colour }}" SELECTED>{{ colour }}</option>
        {% else %}
         <option value="{{ colour }}">{{ colour }}</option>
        {% endif %}     
      {% endfor %}     
   </select>
   <input type="submit">
</form>
英文:

I would like to use a Bootstrap combobox with the Flask combobox. Currently the Flask combobox works fine for me. How can I apply the Bootstrap button graphic to it?

Bootstrap Combobox

  &lt;button class=&quot;btn btn-secondary btn-sm dropdown-toggle&quot; type=&quot;button&quot; data-toggle=&quot;dropdown&quot; aria-haspopup=&quot;true&quot; aria-expanded=&quot;false&quot;&gt;
    Small button
  &lt;/button&gt;

Flask Code

&lt;form name=&quot;Item_1&quot; action=&quot;/combobox&quot; method=&quot;POST&quot;&gt;
    &lt;select name=&quot;colours&quot;&gt;
      {% for colour in colours %}
        {% if colour == chosen %}
         &lt;option value=&quot;{{ colour }}&quot; SELECTED&gt;{{ colour }}&lt;/option&gt;
        {% else %}
         &lt;option value=&quot;{{ colour }}&quot;&gt;{{ colour }}&lt;/option&gt;
        {% endif %}     
      {% endfor %}     
   &lt;/select&gt;
   &lt;input type=&quot;submit&quot;&gt;
&lt;/form&gt;

答案1

得分: 0

你可以按照以下方法更改你的Flask代码,为你的Flask组合框添加Bootstrap按钮样式:

<form name="Item_1" action="/combobox" method="POST">
  <div class="btn-group">
    <button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      选择颜色
    </button>
    <select class="btn btn-secondary btn-sm" name="colours">
      {% for colour in colours %}
        {% if colour == chosen %}
          <option value="{{ colour }}" SELECTED>{{ colour }}</option>
        {% else %}
          <option value="{{ colour }}">{{ colour }}</option>
        {% endif %}     
      {% endfor %}     
    </select>
  </div>
  <input type="submit" class="btn btn-primary btn-sm" value="提交">
</form>

这段代码将按钮和选择组件包装在一个btn-group div中。选择元素具有类btn btn-secondary btn-sm,这使它具有Bootstrap样式,按钮具有类btn btn-secondary btn-sm dropdown-toggle,使其看起来像Bootstrap按钮。

最后但同样重要的是,为了给它应用Bootstrap的主要按钮样式,提交按钮的输入元素具有类btn btn-primary btn-sm。

英文:

You can change your Flask code in the following method to give your Flask combobox the Bootstrap button styling:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;form name=&quot;Item_1&quot; action=&quot;/combobox&quot; method=&quot;POST&quot;&gt;
  &lt;div class=&quot;btn-group&quot;&gt;
    &lt;button class=&quot;btn btn-secondary btn-sm dropdown-toggle&quot; type=&quot;button&quot; data-toggle=&quot;dropdown&quot; aria-haspopup=&quot;true&quot; aria-expanded=&quot;false&quot;&gt;
      Select Color
    &lt;/button&gt;
    &lt;select class=&quot;btn btn-secondary btn-sm&quot; name=&quot;colours&quot;&gt;
      {% for colour in colours %}
        {% if colour == chosen %}
          &lt;option value=&quot;{{ colour }}&quot; SELECTED&gt;{{ colour }}&lt;/option&gt;
        {% else %}
          &lt;option value=&quot;{{ colour }}&quot;&gt;{{ colour }}&lt;/option&gt;
        {% endif %}     
      {% endfor %}     
    &lt;/select&gt;
  &lt;/div&gt;
  &lt;input type=&quot;submit&quot; class=&quot;btn btn-primary btn-sm&quot; value=&quot;Submit&quot;&gt;
&lt;/form&gt;

<!-- end snippet -->

This code covers the button and select components in a btn-group div. The select element has the class btn btn-secondary btn-sm, which gives it the Bootstrap styling, and the button has the classes btn btn-secondary btn-sm dropdown-toggle, which makes it resemble the Bootstrap button.

Last but not least, to give it the Bootstrap primary button style, the input element for the submit button has the class btn btn-primary btn-sm.

huangapple
  • 本文由 发表于 2023年6月16日 10:05:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定