代码之家  ›  专栏  ›  技术社区  ›  Evgeny

如何将HTML<FORM>显示为内联元素?

  •  92
  • Evgeny  · 技术社区  · 16 年前

    这可能是一个基本的html/css问题。..

    我有一个简单的一键表单,我想在段落文本中内联显示。

    <p>Read this sentence 
         <form style='display:inline;'>
         <input style='display:inline;' 
                type='submit' 
                value='or push this button'/>
         </form>.
    </p>
    

    即使窗体有style=display:inline属性,我在窗体之前也会得到一个换行符。有没有办法去掉它?

    <p> ?

    7 回复  |  直到 16 年前
        1
  •  72
  •   ChssPly76    11 年前

    <form style="margin: 0; padding: 0;">
      <p>
        Read this sentence 
        <input style="display: inline;" type="submit" value="or push this button" />
      </p>
    </form>
    
        2
  •  53
  •   John Kugelman Michael Hodel    16 年前

    <form> <p> <p>; <形式>

    <p>Read this sentence 
     </p><form style='display:inline;'>
    
        3
  •  19
  •   Lucky    11 年前

    <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> 
    

    需要注意的是css样式属性 <form>

    display:inline!important;

        4
  •  6
  •   Grzegorz Oledzki    16 年前

    根据 HTML spec <form> <p> 是块元素,不能嵌套它们。也许更换 <p>; <span> 会为你工作吗?

    编辑: <p>; 元素中不允许任何块内容,如所指定的 HTML spec for paragraphs .

        5
  •  0
  •   Tac    14 年前

    添加内联包装器。

    <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>
    
        6
  •  0
  •   MikkoP    13 年前

         <pre>
         <p>Read this sentence  <input  type='submit' value='or push this button'/></p>
         </pre>