CSS label text right below input element

后端 未结 4 1964
一个人的身影
一个人的身影 2021-02-05 10:08

I have input text\'s and label tags. I can\'t figure out the CSS to get the label text to align right below the input text. Here\'s a snippet of the HT

4条回答
  •  离开以前
    2021-02-05 10:44

    A quickly whipped up example that works:

    input {
      display: inline-block;
      width: 6em;
      position: relative;
      top: -3em;
    }
    
    label {
      display: inline-block;
      width: 6em;
      margin-right: .5em;
      padding-top: 1.5em;
    }

    Could be improved, but I find it cleaner than extraneous divs, and it degrades much nicer than the label-after-input-approach when CSS support is absent. Personally, I prefer to nest the inputs in the labels anyway.

提交回复
热议问题