-1

我试图将 a 和 p 元素放入 div 块中,但是当我打开开发人员工具时,它表明它们不是 div 元素的子元素。我做错了什么?有人请建议我正确的方法来做正确的事。PS我是网页设计的新手。

html和css在这里:

<div id="header">
            <!-- header -->
            <p id="banner-text">Banner Text</p>
        </div>

        <div id="body">
            <!-- body -->
            <div id="testid">
                <a href="#">
                    <img src="http://icdn.pro/images/en/g/r/green-check-icone-4881-128.png"/>
                    <p>Testing...</p>
                </a>
            </div>
        </div>

        <div id="footer">
            <!-- footer -->
        </div>

#header
{
    width: 980px;
    height: 70px;
    margin-left: auto;
    margin-right: auto;
    background: #abcdef;
}
#body
{
    width: 980px;
    height: 350px;
    margin-left: auto;
    margin-right: auto;
    background: #aaabbb;
}
#footer
{
    width: 980px;
    height: 70px;
    margin-left: auto;
    margin-right: auto;
    background: #abcdef;
}
#banner-text
{
    float: left;
    position: relative;
    left: 30px;
    top: -45px;
    font-size: 50px;
}

#testid
{
    position: relative;
    width: 100px;
    height: 100px;
    left: 0px;
    top: 0px;
}

#testid a
{
    float: left;
    position: relative;
    width: 1px;
    height: 1px;
}

#testid img
{
    float: left;
    position: relative;
    width: 70px;
    height: 70px;
    top: -70px;
    left: 15px;
}

#testid p
{
    float: left;
    position: relative;
    left: 8px;
    top: -90px;
    width: 90px;
    height: 0px;
    color: #222;
    text-shadow: 0px 2px 3px #555;
}

jsfiddle:http: //jsfiddle.net/R4anp/

问候。

4

2 回答 2

3

您正在尝试使用不符合 W3C<p>的内联元素包装块元素。<a>您可以将链接包装在段落标签中吗?

编辑:这在 HTML5 中有效。

于 2013-06-27T13:29:49.000 回答
1

使用 HTML5 文档类型应该没问题

<!DOCTYPE html>
于 2013-06-27T13:31:34.237 回答