2016-05-02 78 views
0

第一個div內的圖像應該與頂部第二個div中的列表水平對齊。但是,正如你所看到的,這個名單與上面有差距。請指導如何消除這種差距?如何將圖像與頂部列表進行水平對齊?

FIDDLE:https://jsfiddle.net/sryzdn/svg0716k/

HTML:

<div id="container"> 
    <div id="div1"><img src="http://placehold.it/200x100"></div> 
    <div id="div2"> 
    <ul> 
     <li>aaa</li> 
     <li>bbb</li> 
     <li>ccc</li> 
    </ul> 
    </div> 
</div> 

CSS:

#container { 
    width: 400px; 
    height: 400px; 
    background-color: red; 
} 

#div1 { 
    width: 200px; 
    height: 200px; 
    background-color: green; 
    float: left; 
    position: relative; 
} 

#div1 img { 
    position: absolute; 
    top: 0; 
} 

#div2 { 
    width: 200px; 
    height: 200px; 
    background-color: blue; 
    float: left; 
    positive: relative; 
} 

#div2 ul { 
    position: absolute; 
    top: 0; 
} 

#div2 li { 
    display: inline-block; 
    border: 1px solid black; 
} 
+1

'ul {margin:0}'? –

回答

0

看到這個https://jsfiddle.net/0guuehj8/

評論postiton絕對和重新填充

#div2 ul { 
    /*position: absolute; 
    top: 0;*/ 
    margin:0px; 
    -webkit-padding-start: 0px; 
    padding: 0; 
} 
+0

我已經更新了不是web.kit瀏覽器的asnwer – scaisEdge

1

取出top:0財產和#div2 ul添加margin-top: 0px;

#div2 ul { 
    position:absolute; 
    margin-top:0px; 
}