1

我正在尝试imgdiv. 问题是图像在div. 我目前有一张图片,div并且在加载之前知道图片大小。div尺寸设置为图像的尺寸,但图像在 div 的左侧加载。我已经尝试了一切,甚至向图像添加了垂直对齐,而我遇到的最接近的事情是制作div绝对位置,它刚刚在图像右侧的文本下加载了 div。我可能可以将图像加载到div原始图像中的另一个中,但在我的情况下这可能会损害 SEO。

图像的位置 在此处输入图像描述

HTML

<ul id="UL_1" class="ab-submenu">
    <li id="LI_2">
        <a class="ab-item" tabindex="-1" href="http://techdigy.com/wp-admin/profile.php" id="A_3"></a>
        <div class="avatar-holder" id="DIV_4">
            <img alt="" src="http://1.gravatar.com/avatar/95fef2e7b4a23f9cc0439619db1af0a6?s=64&amp;d=identicon&amp;r=G" class="avatar avatar-64 photo" height="64" width="64" id="IMG_5" />
        </div><span class="display-name" id="SPAN_6">Andre</span>
    </li>
    <li id="LI_7">
        <a class="ab-item" href="http://techdigy.com/wp-admin/profile.php" id="A_8">Edit My Profile</a>
    </li>
    <li id="LI_9">
        <a class="ab-item" href="http://techdigy.com/wp-login.php?action=logout&amp;_wpnonce=c7d2e50651" id="A_10">Log Out</a>
    </li>
</ul>

CSS

#UL_1 {
    background: rgba(0, 0, 0, 0) none repeat scroll 0px 0px / auto padding-box border-box;
    border: 0px none rgb(204, 204, 204);
    color: rgb(204, 204, 204);
    font: normal normal normal 13px/28px sans-serif;
    height: auto;
    line-height: 28px;
    list-style: none outside none;
    margin: 0px;
    outline: rgb(204, 204, 204) none 0px;
    padding: 6px 0px;
    position: relative;
    text-align: left;
    text-shadow: rgb(68, 68, 68) 0px -1px 0px;
    transition: none 0s ease 0s;
    width: auto;
    z-index: 99999;
}/*#UL_1*/

#LI_2 {
    background: rgba(0, 0, 0, 0) none repeat scroll 0px 0px / auto padding-box border-box;
    border: 0px none rgb(204, 204, 204);
    color: rgb(204, 204, 204);
    font: normal normal normal 13px/28px sans-serif;
    height: auto;
    line-height: 28px;
    list-style: none outside none;
    margin: 6px 16px 15px 88px;
    outline: rgb(204, 204, 204) none 0px;
    position: relative;
    text-shadow: rgb(68, 68, 68) 0px -1px 0px;
    transition: none 0s ease 0s;
    width: auto;
    z-index: 99999;
}/*#LI_2*/

#A_3 {
    background: rgba(0, 0, 0, 0) none repeat scroll 0px 0px / auto padding-box border-box;
    border: 0px none rgb(33, 117, 155);
    color: rgb(33, 117, 155);
    display: block;
    font: normal normal normal 13px/26px sans-serif;
    line-height: 26px;
    list-style: none outside none;
    min-width: 140px;
    outline: rgb(33, 117, 155) none 0px;
    padding: 0px 12px 0px 8px;
    text-align: left;
    text-decoration: none;
    transition: none 0s ease 0s;
    white-space: nowrap;
}/*#A_3*/

#DIV_4 {
    border: 0px none rgb(204, 204, 204);
    color: rgb(204, 204, 204);
    font: normal normal normal 13px/28px sans-serif;
    height: 64px;
    line-height: 28px;
    list-style: none outside none;
    outline: rgb(204, 204, 204) none 0px;
    text-align: left;
    text-shadow: rgb(68, 68, 68) 0px -1px 0px;
    transition: none 0s ease 0s;
    white-space: nowrap;
    width: 64px;
}/*#DIV_4*/

#IMG_5 {
    background: rgba(0, 0, 0, 0) none repeat scroll 0px 0px / auto padding-box border-box;
    border: 0px none rgb(204, 204, 204);
    color: rgb(204, 204, 204);
    display: block;
    font: normal normal normal 13px/28px sans-serif;
    height: 64px;
    left: -72px;
    line-height: 28px;
    list-style: none outside none;
    outline: rgb(204, 204, 204) none 0px;
    position: absolute;
    text-align: left;
    text-shadow: rgb(68, 68, 68) 0px -1px 0px;
    top: 4px;
    transition: none 0s ease 0s;
    vertical-align: middle;
    white-space: nowrap;
    width: 64px;
}/*#IMG_5*/

#SPAN_6 {
    background: rgba(0, 0, 0, 0) none repeat scroll 0px 0px / auto padding-box border-box;
    border: 0px none rgb(51, 51, 51);
    color: rgb(51, 51, 51);
    display: block;
    font: normal normal normal 13px/28px sans-serif;
    height: 18px;
    line-height: 28px;
    list-style: none outside none;
    outline: rgb(51, 51, 51) none 0px;
    text-align: left;
    transition: none 0s ease 0s;
    white-space: nowrap;
}/*#SPAN_6*/

#LI_7, #LI_9 {
    background: rgba(0, 0, 0, 0) none repeat scroll 0px 0px / auto padding-box border-box;
    border: 0px none rgb(204, 204, 204);
    color: rgb(204, 204, 204);
    font: normal normal normal 13px/28px sans-serif;
    height: auto;
    line-height: 28px;
    list-style: none outside none;
    margin: 0px 16px 0px 88px;
    outline: rgb(204, 204, 204) none 0px;
    position: relative;
    text-shadow: rgb(68, 68, 68) 0px -1px 0px;
    transition: none 0s ease 0s;
    width: auto;
    z-index: 99999;
}/*#LI_7, #LI_9*/

#A_8, #A_10 {
    background: rgba(0, 0, 0, 0) none repeat scroll 0px 0px / auto padding-box border-box;
    border: 0px none rgb(33, 117, 155);
    color: rgb(33, 117, 155);
    display: block;
    font: normal normal normal 13px/26px sans-serif;
    height: 26px;
    line-height: 26px;
    list-style: none outside none;
    min-width: 140px;
    outline: rgb(33, 117, 155) none 0px;
    padding: 0px 12px 0px 8px;
    text-align: left;
    text-decoration: none;
    transition: none 0s ease 0s;
    white-space: nowrap;
}/*#A_8, #A_10*/
4

1 回答 1

2

这是正确的行为,您将img绝对-72px左侧和4px顶部定位。

#IMG_5 {
    position:absolute;
    left: -72px;
    top: 4px;
}

如果您希望 位于img内部div,则删除绝对定位。

如果您试图移动div应用此定位而不是img. 在这样做时,img意志也有同样的地位,因为它是一个孩子。

jsFiddle 示例

于 2013-11-09T19:37:31.137 回答