简体   繁体   English

在锚标签中使用div标签是否正确?

[英]Is it correct to use div tag inside anchor tag?

I have used the following piece of code where I have used div tag inside anchor tag. 我在锚标签内使用div标签的地方使用了以下代码。 The code is working fine but I am not sure if this is the correct format. 该代码工作正常,但我不确定这是否是正确的格式。 Is it correct to use div inside anchor tag ? 在锚标签内使用div是否正确?

<a class="discount-popup" href="#" id="WC_Link_ProductDiscount_1_<c:out value="${discountCounter.count}"/>">
    <div id="view_offer" style="display: block;">
        &nbsp;&nbsp;<u style="color: #000000;"><c:out value="View offer details" escapeXml="true" /></u>
    </div>
    <div id="offer_details" style="display: none;">
        <c:out value="${calculationCodeDBs[0].longDescriptionString}" escapeXml="false" />
    </div>
</a>

In HTML5 you can. 在HTML5中可以。 In previous versions of HTML you can't. 在以前的HTML版本中,您不能这样做。 To make this code valid you need to set the correct doctype: 要使此代码有效,您需要设置正确的文档类型:

<!DOCTYPE html>

With this doctype the browser identifies HTML5 page. 使用此文档类型,浏览器可以识别HTML5页面。 Put it before <html> tag. 将其放在<html>标记之前。

Yes, its fine to you use DIV elements inside an anchor tag, but you will need to setup your CSS correctly for each one (height, width, display, etc), otherwise, the height will revert to the line height by default. 是的,您可以在锚标记中使用DIV元素,但是您需要为每个CSS正确设置CSS(高度,宽度,显示等),否则默认情况下,高度将恢复为线条高度。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM