Align a checkbox input and a <p> tag in the same line

大兔子大兔子 提交于 2019-12-11 19:12:17

问题


I've seen most of the other solutions to this problem using a label. Unfortunately, I can't use label on this particular case, because that will mess things up. What I have is the following:

<div className="terms-checkbox">
  <input type="checkbox" required />
  <p>I accept the Terms and Conditions</p>
</div>

And I'm setting display to be inline-block for terms-checkbox like so:

    .terms-checkbox {
      display: inline-block;
    }

However, this does not align the items horizontally/in the same line. Without wrapping the input tag with label, how can I make the checkbox and p tag align horizontally?

Here's the fiddle link: https://jsfiddle.net/eu5rso2a/1/

edit: fixed indentation.


回答1:


You must set the terms-checkbox class to input or p tag. Not their parent. Means your input and p tag must be inline-block




回答2:


<p><input type="checkbox" required/>I accept the Terms and Conditions</p>


来源:https://stackoverflow.com/questions/51922044/align-a-checkbox-input-and-a-p-tag-in-the-same-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!