两个连续的HTML下拉菜单呈现问题

时间:2015-11-29 17:39:11

标签: html css dropdown

我有以下代码,我正在尝试创建两个下拉菜单;一个用于星期几,另一个用于该类别。

<!DOCTYPE html>
    <html>
    <body>
    <p>Category of the article: 
    <option value="lifestyle">Lifestyle</option>
    <option value="entertainment">Entertainment</option>
    <option value="business">Business</option>
    <option value="social media">Social Media</option>
    <option value="tech">Tech</option>
    <option value="world">World</option></p> <br>
    
    <p>Day of publishing the article: 
    <option value="monday">Monday</option>
    <option value="tuesday">Tuesday</option>
    <option value="wednesday">Wednesday</option>
    <option value="thursday">Thursday</option>
    <option value="friday">Friday</option>
    <option value="saturday">Saturday</option>
    <option value="sunday">Sunday</option></p> <br>
    
    </body>
    </html>

但该页面如下图所示。有人可以帮我确定为什么会这样吗?

Output

2 个答案:

答案 0 :(得分:1)

<强>错误:

  1. <p>内不能包含任何块标记或任何内容。
  2. 您错过了<select>代码。
  3. 更正后的代码:

    <!DOCTYPE html>
    <html>
      <body>
        <p>Category of the article:</p>
        <select>
          <option value="lifestyle">Lifestyle</option>
          <option value="entertainment">Entertainment</option>
          <option value="business">Business</option>
          <option value="social media">Social Media</option>
          <option value="tech">Tech</option>
          <option value="world">World</option>
        </select>
    
        <p>Day of publishing the article:</p>
        <select>
          <option value="monday">Monday</option>
          <option value="tuesday">Tuesday</option>
          <option value="wednesday">Wednesday</option>
          <option value="thursday">Thursday</option>
          <option value="friday">Friday</option>
          <option value="saturday">Saturday</option>
          <option value="sunday">Sunday</option>
        </select>
    
      </body>
    </html>
    

答案 1 :(得分:0)

您忘记了<select>代码。

<!DOCTYPE html>
    <html>
    <head>
       <title>Titre</title>
    </head>
    <body>
    <p>Category of the article: 
    <select>
      <option value="lifestyle">Lifestyle</option>
      <option value="entertainment">Entertainment</option>
      <option value="business">Business</option>
      <option value="social media">Social Media</option>
      <option value="tech">Tech</option>
      <option value="world">World</option>
    </select></p> <br>
    
    <p>Day of publishing the article: 
    <select>
      <option value="monday">Monday</option>
      <option value="tuesday">Tuesday</option>
      <option value="wednesday">Wednesday</option>
      <option value="thursday">Thursday</option>
      <option value="friday">Friday</option>
      <option value="saturday">Saturday</option>
      <option value="sunday">Sunday</option>
     </select></p> <br>
    
    </body>
    </html>

此代码位于验证器中,但我不确定您是否可以在<select>中添加<p>

请参阅HTML select tag