LoginSignup
9
9

Bootstrap - checkboxとlabelを水平に一直線にするCSS

Last updated at Posted at 2015-07-29

Screenshot 2015-07-28 21.35.06.png

#やりたいこと

  • よく見ると微妙に揃っていないcheckboxとlabelを水平に一直線にしたい。
  • 簡単そうで簡単に出来なかったのでメモ。

#環境

  • Ruby 2.2.1
  • Rails 4.2.3
  • bootstrap

###Before
Screenshot 2015-07-28 20.38.44.png
labelの文字が少し上方向にズレている。
###After
Screenshot 2015-07-28 20.38.29.png

#Viewの成功例

.form-inline
  .checkbox
    %label
      = f.check_box :rooms, options, checked_value, unchecked_value
      = room_name
# Deviseのフォーム
- if devise_mapping.rememberable?
  .field.form-group
    .form-inline
      .checkbox
        = f.check_box :remember_me
        = f.label :remember_me

#問題解決CSS


@media (min-width: 768px) {
  .form-inline .radio input[type="radio"],
  .form-inline .checkbox input[type="checkbox"] {
    float: left;
    margin-right: 5px;
    label {
      font-weight: normal;
    }
  }
}

#参考文献

問題解決CSSは以下のStackOverflowから学びました。
Bootstrap 3 form checkbox label doesn't align with checkbox input in Chromium + Firefox

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9