2013-11-09 16 views
1

我試圖用div包裝img。問題是圖像加載到div的左側。我目前有一個圖像和div,並知道圖像大小之前,它被加載。 div尺寸設置爲圖像尺寸,但圖像加載到div的左側。我試過所有的東西,甚至在圖像上添加了一個垂直對齊,而我遇到的最接近的東西是將絕對的div絕對位置加載到圖像正確的文本下面。我可能可以加載在原來的另一個div圖像,但可能會損害SEO在我的情況。圖像的圖像不總是在DIV內

位置 enter image description here

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*/ 
+1

請張貼一些相關的HTML/CSS來證明這一點。 –

+0

當然。一秒。 –

+2

「我可能可以將圖片加載到原始內容的另一個div中,但這可能會損害我的案例中的SEO。」 - 我可以向你保證,它不會 – Adam

回答

2

這是正確的行爲,你的定位img絕對-72px左和4px從頂部。

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

如果你想在imgdiv裏面,然後取出絕對定位。

如果您試圖移動div,則應用此定位而不是img。這樣做,img也會有同樣的位置,因爲它是一個孩子。

jsFiddle example

+0

這樣做的CSS是由WordPress完成的。儘管如此,如果我將位置改爲繼承或初始化,我認爲它會像在jsFiddle中顯示的位置一樣,但它仍然距離左側大約50px。 –

+0

@AndreYonadam或者不改寫它,只需更改PHP中生成的代碼即可。 –