Styling form error message - bootstrap/rails

前端 未结 8 633
陌清茗
陌清茗 2021-02-01 18:38

The error messages for my rails form look terrible with bootstrap. Does anyone know a solution for better (nice looking) error messages? I use Rails and Bootstrap.

My fo

8条回答
  •  佛祖请我去吃肉
    2021-02-01 19:29

    Maybe a simpler one is search for ids and classes on the form itself. Works for any combo.

    By default, this are the lines included in scaffold to arrange the error messages. You can do with them whatever you want. Just have to extend them in your css.scss file:

    .field_with_errors {
      padding: 2px;
      background-color: red;
      display: table;
    }
    
    #error_explanation {
      width: 450px;
      border: 2px solid red;
      padding: 7px 7px 0;
      margin-bottom: 20px;
      background-color: #f0f0f0;
    }
    
    #error_explanation h2 {
      text-align: left;
      font-weight: bold;
      padding: 5px 5px 5px 15px;
      font-size: 12px;
      margin: -7px -7px 0;
      background-color: #c00;
      color: #fff;
    }
    
    #error_explanation ul li {
      font-size: 12px;
      list-style: square;
    }
    

    In case something is not working, check the navigator in developer mode. There you should be able to find all the html and css rails is creating...

提交回复
热议问题