How to display HTML <FORM> as inline element?

后端 未结 7 1940
死守一世寂寞
死守一世寂寞 2020-12-02 10:43

This is probably a basic html/css question...

I have a simple one-button form that I would like to display inline inside paragraph text.

Rea

相关标签:
7条回答
  • 2020-12-02 11:27

    According to HTML spec both <form> and <p> are block elements and you cannot nest them. Maybe replacing the <p> with <span> would work for you?

    EDIT: Sorry. I was to quick in my wording. The <p> element doesn't allow any block content within - as specified by HTML spec for paragraphs.

    0 讨论(0)
  • 2020-12-02 11:30

    You can try this code:

    <form action="#" method="get" id="login" style=" display:inline!important;">
    
      <label for='User'>User:</label> 
      <input type='text' name='User' id='User'>
    
      <label for='password'>Password:</label><input type='password' name='password' id='password'>
      <input type="submit" name="log" id="log" class="botton" value="Login" />
    
    </form> 
    

    The important thing to note is the css style property in the <form> tag.

    display:inline!important;

    0 讨论(0)
  • 2020-12-02 11:34

    Add a inline wrapper.

    <div style='display:flex'>
    <form>
     <p>Read this sentence</p>
     <input type='submit' value='or push this button' />
    </form>
    <div>
        <p>Message here</p>
    </div>
    
    0 讨论(0)
  • 2020-12-02 11:35

    <form> cannot go inside <p>, no. The browser is going to abruptly close your <p> element when it hits the opening <form> tag as it tries to handle what it thinks is an unclosed paragraph element:

    <p>Read this sentence 
     </p><form style='display:inline;'>
    
    0 讨论(0)
  • 2020-12-02 11:38

    You can accomplish what you want, I think, simply by including the submit button within the paragraph:

         <pre>
         <p>Read this sentence  <input  type='submit' value='or push this button'/></p>
         </pre>   
    
    0 讨论(0)
  • 2020-12-02 11:40

    Move your form tag just outside the paragraph and set margins / padding to zero:

    <form style="margin: 0; padding: 0;">
      <p>
        Read this sentence 
        <input style="display: inline;" type="submit" value="or push this button" />
      </p>
    </form>
    
    0 讨论(0)
提交回复
热议问题