【问题标题】:Invalid location of tag <div> in JSPJSP 中标签 <div> 的位置无效
【发布时间】:2015-04-30 05:25:32
【问题描述】:

我在我的 jsp 页面中插入了一些代码 HTML:acceuil.jsp,但我的标签 &lt;div class="ca-content"&gt; 中出现错误。它告诉我这是一个无效的位置。 (ca-content 指的是我样式表中的一个类)。

我尝试禁用 HTML 验证器,但仍然遇到同样的错误。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/acceuil.css" />
    <title>Insert title here</title>
</head>
<body>
    <ul class="ca-menu">
        <li>
            <a href="#">
                <span class="ca-icon">A</span>

                <div class="ca-content">
                    <h2 class="ca-main">Exceptional Service</h2>
                    <h3 class="ca-sub">Personalized to your needs</h3>
                </div>
			
            </a>
        </li>

    </ul>
</body>
</html>

【问题讨论】:

    标签: html css jsp


    【解决方案1】:

    &lt;div&gt;&lt;a&gt; 中无效。

    HTML 4.1 specification 中,&lt;a&gt; 元素可能只包含inline elements,而&lt;div&gt;block element,因此它可能不会出现在&lt;a&gt; 中。

    所以,改为:

    <a href="#">
        <span class="ca-icon">A</span>
    
        <div class="ca-content">
            <h2 class="ca-main">Exceptional Service</h2>
            <h3 class="ca-sub">Personalized to your needs</h3>
        </div>
    
    </a>
    

    用途:

    <a href="#">
        <span class="ca-icon">A</span>
    </a>
    <div class="ca-content">
        <h2 class="ca-main">Exceptional Service</h2>
        <h3 class="ca-sub">Personalized to your needs</h3>
    </div>
    

    或其他代表您需要的东西,但总是在 &lt;div&gt; 之外 &lt;a&gt;

    看看 HTML 5 规范中的"The a element",可能会对你有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多