2017-05-28 147 views
0

我想在div上的某个位置放置图像。 Here is what it looks like so far.盒装区域是我希望显示图像(圈出来)的地方。如何将图像浮动到div内的某个位置?

我累了复式方式尚未形象似乎只

  1. 留在左
  2. 向右移动,但文本

我试图做到的,是在去将图像放置在列出的文本的顶部,以便它可以填充空白区域。此外,我试图确保滚动条不会出现

任何帮助非常感谢!

CSS

body { 
    font-size: 12px; 
    background-color: #f1f6f9; 
    color: #7e7e7e; 
    background-image: url("none.png"); 
    background-repeat: repeat; 
} 

* { 
    cursor: url('cursor.png'), auto; 
} 

.box { 
    border-style: solid; 
    border-width: 1px; 
    box-shadow: 3px 3px black; 
    border-color: #000; 
    background-color: #ffffff; 
    margin-top: 100px; 
    margin-bottom: 10px; 
    margin-right: auto; 
    margin-left: auto; 
    padding: 15px 22px 15px 22px; 
    height: 250px; 
    width: 265px; 
    font-family: 'mplus 1p', sans-serif; 
    overflow-y: auto; 
    overflow-x: hidden; 
    position: relative; 
} 

.links { 
    text-align: center; 
    border-style: solid; 
    border-width: 1px; 
    box-shadow: 3px 3px black; 
    border-color: #000; 
    background-color: #ffffff; 
    margin-top: none; 
    margin-right: auto; 
    margin-left: auto; 
    padding: 10px; 
    height: 15px; 
    width: 289px; 
    font-family: 'mplus 1p', sans-serif; 
} 

.icon { 
    width: auto; 
    height: 85px; 
    border-radius: 50px; 
    margin-bottom: 12px; 
} 

li { 
    list-style-image: url('bullet1.gif'); 
    list-style-position: inside; 
    margin-left: 1em; 
} 

::-webkit-scrollbar { 
    width: 5px; 
    height: auto; 
} 

::-webkit-scrollbar-thumb { 
    background: #ffc9e5; 
    border: 1px solid #000; 
    border-right: none; 
} 

::-webkit-scrollbar-track { 
    background: #d6ffee; 
    border-left: 1px solid #000; 
} 

::-webkit-scrollbar-corner { 
    background: transparent; 
} 

HTML

<div class="box"> 
<center><img class="icon" src="icon1.png"></center> 
    <li>text</li> 
    <li>text</li> 
    <li>text</li> 
    <li>text</li> 
    <li>text</li> 
    <li>text</li> 
    <li><a href="personality.html">text</a></li> 
    <li><a href="more.html">text</a></li> 
    <img src="bunny1.gif" style="float: right"> 
    </div> 
    <div class="links"> 
    text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text 
    </div> 

回答

0

您需要img的还是要浮动的旁边的元素之上。因此,只需在列表前移动img即可。如果您想在页面上将其向下移动,请使用margintransform: translateY()

但你li'也需要在ulcenter标签已经过时 - 你需要使用CSS为代替。

body { 
 
    font-size: 12px; 
 
    background-color: #f1f6f9; 
 
    color: #7e7e7e; 
 
    background-image: url("none.png"); 
 
    background-repeat: repeat; 
 
} 
 

 
* { 
 
    cursor: url('cursor.png'), auto; 
 
} 
 

 
.box { 
 
    border-style: solid; 
 
    border-width: 1px; 
 
    box-shadow: 3px 3px black; 
 
    border-color: #000; 
 
    background-color: #ffffff; 
 
    margin-top: 100px; 
 
    margin-bottom: 10px; 
 
    margin-right: auto; 
 
    margin-left: auto; 
 
    padding: 15px 22px 15px 22px; 
 
    height: 250px; 
 
    width: 265px; 
 
    font-family: 'mplus 1p', sans-serif; 
 
    overflow-y: auto; 
 
    overflow-x: hidden; 
 
    position: relative; 
 
} 
 

 
.links { 
 
    text-align: center; 
 
    border-style: solid; 
 
    border-width: 1px; 
 
    box-shadow: 3px 3px black; 
 
    border-color: #000; 
 
    background-color: #ffffff; 
 
    margin-top: none; 
 
    margin-right: auto; 
 
    margin-left: auto; 
 
    padding: 10px; 
 
    height: 15px; 
 
    width: 289px; 
 
    font-family: 'mplus 1p', sans-serif; 
 
} 
 

 
.icon { 
 
    width: auto; 
 
    height: 85px; 
 
    border-radius: 50px; 
 
    margin-bottom: 12px; 
 
} 
 

 
li { 
 
    list-style-image: url('bullet1.gif'); 
 
    list-style-position: inside; 
 
    margin-left: 1em; 
 
} 
 

 
::-webkit-scrollbar { 
 
    width: 5px; 
 
    height: auto; 
 
} 
 

 
::-webkit-scrollbar-thumb { 
 
    background: #ffc9e5; 
 
    border: 1px solid #000; 
 
    border-right: none; 
 
} 
 

 
::-webkit-scrollbar-track { 
 
    background: #d6ffee; 
 
    border-left: 1px solid #000; 
 
} 
 

 
::-webkit-scrollbar-corner { 
 
    background: transparent; 
 
} 
 

 
ul { 
 
    padding: 0; margin: 0; 
 
} 
 
.center { 
 
    text-align: center; 
 
}
<div class="box"> 
 
    <div class="center"><img class="icon" src="icon1.png"></div> 
 
    <img src="bunny1.gif" style="float: right; margin-top: 2em;"> 
 

 
    <ul> 
 
    <li>text</li> 
 
    <li>text</li> 
 
    <li>text</li> 
 
    <li>text</li> 
 
    <li>text</li> 
 
    <li>text</li> 
 
    <li><a href="personality.html">text</a></li> 
 
    <li><a href="more.html">text</a></li> 
 
    </ul> 
 
</div> 
 
<div class="links"> 
 
    text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text <img src="bullet2.png" style="margin-left:2px; margin-right:2px"> text 
 
</div>

+0

谢谢!我唯一担心的是,它似乎使上图和“ul”之间的空间更大,如[https://tomoya.neocities.org/show.html]所示。 – Ren

+0

@欢迎您。看起来像你需要添加'margin:0;填充:0;'到'ul'(就像我上面的代码)。 –