【问题标题】:Floating picture to right of <p> within a <div><div> 内 <p> 右侧的浮动图片
【发布时间】:2013-08-01 18:53:27
【问题描述】:

我正在尝试在网页上创建一个图表,每个条目都被编码为一个包含 &lt;p&gt; 元素的 div,以便为最左侧的条目编号和旁边的图片。但是,当我尝试此代码时:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD\xhtml1-strict.dtd">
<html xmlns="hhtp://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title></title>
        <style>
            .entry {
                background-color: #99d699;
                width: 600px;
                height: auto;
                margin-left: auto;
                margin-right: auto;
                padding: 1px;
                border-color: #808080;
                border-width: 2px;
                border-bottom-style: solid;
                position: relative;
                overflow: hidden;
            }
            .entry p {
                color: white;
                font-weight: bold;
                font-size: 30px;
                margin-top: 15px;
                margin-bottom: 15px;
                margin-left: 10px;
            }
            .art {
                width: 80px;
                height: 80px;
                margin-top: auto;
                margin-bottom: auto;
                margin-left: 10px;
                float: left;
                overflow: hidden;
            }
        </style>
    </head>
    <body style="background-color: #D6DDD6;">

        <div class="entry">
            <p>
                1
            </p>
            <img class="art" src="http://wvs.topleftpixel.com/photos/2008/04/Dundas_Square_Pano_Fisheye_tunnel_crop.jpg"     alt="Random pic" />
        </div>
    </body>
</html>

...图片在段落下方结束。如何将图像干净地定位在段落的右侧?

【问题讨论】:

    标签: image html css-float


    【解决方案1】:

    这里是JSBin

    只需在您的 CSS 中添加以下代码

    p{
      float:left;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-10
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2018-06-20
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 2013-11-26
      相关资源
      最近更新 更多