gpt4 book ai didi

html - 如何在 collection_check_boxes 上将宽度设置为百分比?

转载 作者:太空宇宙 更新时间:2023-11-04 10:12:25 28 4
gpt4 key购买 nike

如何在 collection_check_boxes 上将宽度设置为百分比?由于有 7 个复选框,我希望每个复选框都占 18%。

现在的问题是,如果我将其设置为 18%,背景颜色将变为自身的 18%,而不是相对于较大容器的位置。

ruby

<div class="challenge-do-on">
<%= f.collection_check_boxes :committed, Date::ABBR_DAYNAMES, :downcase, :to_s %>
</div>

HTML 输出

<div class="challenge-do-on">

<span><label for="challenge_committed_sun"><input type="checkbox" value="sun" checked="checked" name="challenge[committed][]" id="challenge_committed_sun"><label class="collection_check_boxes"for="challenge_committed_sun">Sun</label></label></span>

<span><label for="challenge_committed_mon"><input type="checkbox" value="mon" checked="checked" name="challenge[committed][]" id="challenge_committed_mon"><label class="collection_check_boxes" for="challenge_committed_mon">Mon</label></label></span>

<span><label for="challenge_committed_tue"><input type="checkbox" value="tue" checked="checked" name="challenge[committed][]" id="challenge_committed_tue"><label class="collection_check_boxes" for="challenge_committed_tue">Tue</label></label></span>

<span><label for="challenge_committed_wed"><input type="checkbox" value="wed" checked="checked" name="challenge[committed][]" id="challenge_committed_wed"><label class="collection_check_boxes" for="challenge_committed_wed">Wed</label></label></span>

<span><label for="challenge_committed_thu"><input type="checkbox" value="thu" checked="checked" name="challenge[committed][]" id="challenge_committed_thu"><label class="collection_check_boxes" for="challenge_committed_thu">Thu</label></label></span>

<span><label for="challenge_committed_fri"><input type="checkbox" value="fri" checked="checked" name="challenge[committed][]" id="challenge_committed_fri"><label class="collection_check_boxes" for="challenge_committed_fri">Fri</label></label></span>

<span><label for="challenge_committed_sat"><input type="checkbox" value="sat" checked="checked" name="challenge[committed][]" id="challenge_committed_sat"><label class="collection_check_boxes" for="challenge_committed_sat">Sat</label></label></span>

</div>

最佳答案

使用 width: calc(100%/7)display:inline-block,在这 7 个 input 之间进行均分


.collection_check_boxes {
width: calc(100% / 7);
display: inline-block;
background:red
}
<div class="challenge-do-on">

<span><label for="challenge_committed_sun"><input type="checkbox" value="sun" checked="checked" name="challenge[committed][]" id="challenge_committed_sun"><label class="collection_check_boxes"for="challenge_committed_sun">Sun</label></label></span>

<span><label for="challenge_committed_mon"><input type="checkbox" value="mon" checked="checked" name="challenge[committed][]" id="challenge_committed_mon"><label class="collection_check_boxes" for="challenge_committed_mon">Mon</label></label></span>

<span><label for="challenge_committed_tue"><input type="checkbox" value="tue" checked="checked" name="challenge[committed][]" id="challenge_committed_tue"><label class="collection_check_boxes" for="challenge_committed_tue">Tue</label></label></span>

<span><label for="challenge_committed_wed"><input type="checkbox" value="wed" checked="checked" name="challenge[committed][]" id="challenge_committed_wed"><label class="collection_check_boxes" for="challenge_committed_wed">Wed</label></label></span>

<span><label for="challenge_committed_thu"><input type="checkbox" value="thu" checked="checked" name="challenge[committed][]" id="challenge_committed_thu"><label class="collection_check_boxes" for="challenge_committed_thu">Thu</label></label></span>

<span><label for="challenge_committed_fri"><input type="checkbox" value="fri" checked="checked" name="challenge[committed][]" id="challenge_committed_fri"><label class="collection_check_boxes" for="challenge_committed_fri">Fri</label></label></span>

<span><label for="challenge_committed_sat"><input type="checkbox" value="sat" checked="checked" name="challenge[committed][]" id="challenge_committed_sat"><label class="collection_check_boxes" for="challenge_committed_sat">Sat</label></label></span>

</div>

如果您想保留 18%,这里有一个片段


.collection_check_boxes {
width: 18%;
display: inline-block;
background:red
}
<div class="challenge-do-on">

<span><label for="challenge_committed_sun"><input type="checkbox" value="sun" checked="checked" name="challenge[committed][]" id="challenge_committed_sun"><label class="collection_check_boxes"for="challenge_committed_sun">Sun</label></label></span>

<span><label for="challenge_committed_mon"><input type="checkbox" value="mon" checked="checked" name="challenge[committed][]" id="challenge_committed_mon"><label class="collection_check_boxes" for="challenge_committed_mon">Mon</label></label></span>

<span><label for="challenge_committed_tue"><input type="checkbox" value="tue" checked="checked" name="challenge[committed][]" id="challenge_committed_tue"><label class="collection_check_boxes" for="challenge_committed_tue">Tue</label></label></span>

<span><label for="challenge_committed_wed"><input type="checkbox" value="wed" checked="checked" name="challenge[committed][]" id="challenge_committed_wed"><label class="collection_check_boxes" for="challenge_committed_wed">Wed</label></label></span>

<span><label for="challenge_committed_thu"><input type="checkbox" value="thu" checked="checked" name="challenge[committed][]" id="challenge_committed_thu"><label class="collection_check_boxes" for="challenge_committed_thu">Thu</label></label></span>

<span><label for="challenge_committed_fri"><input type="checkbox" value="fri" checked="checked" name="challenge[committed][]" id="challenge_committed_fri"><label class="collection_check_boxes" for="challenge_committed_fri">Fri</label></label></span>

<span><label for="challenge_committed_sat"><input type="checkbox" value="sat" checked="checked" name="challenge[committed][]" id="challenge_committed_sat"><label class="collection_check_boxes" for="challenge_committed_sat">Sat</label></label></span>

</div>

关于html - 如何在 collection_check_boxes 上将宽度设置为百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37494387/

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