【问题标题】:Inside a div, I have an image, then paragraph, then image at the end. I can't get the second image to be 'inside' the paragraph在一个 div 中,我有一个图像,然后是段落,最后是图像。我无法将第二张图片放在段落的“内部”
【发布时间】:2012-12-26 18:17:56
【问题描述】:

所以,我有一个 div,里面有 3 个东西; 1. 一张图片(左大引号) 2. 实时文本段落 3.末尾的另一张图片(一个大的右引号)。

第一张图片,当它放在 div 中时,会导致文本换行,这很棒。它似乎是段落的一部分。

我的问题:我无法将第二张图片放在末尾的段落“内部”。它被推到段落区域下方。我希望它与我的段落文本“换行”。

#textarea {
width: 185px;
height: 70px;
padding: 49px;

}

#textarea p {
font-size: 15px;
font-weight: bold;
color: #4D6F79;
line-height: 230%;
text-align: center;
-webkit-margin-after: 0em;
-webkit-margin-before: 0em;

}

<div id= "textarea">
            <img src="images/leftquote.png" width="36" height="43" alt="left quotation" align="left"/>
            <p>The kids really loved it!</p>
            <img src="images/rightquote.png" width="32" height="20" alt="right quotation" align="right"/>
        </div>

任何帮助/想法将不胜感激!谢谢!!

【问题讨论】:

    标签: image html division word-wrap paragraph


    【解决方案1】:

    我不完全确定您希望段落中的第二张图片是什么意思,但我知道使用 css 将您的第二张图片重新定位到您想要的位置的一种非常简单且便宜的方法...... 首先在您的图片上添加一个 ID:

    <img id='image2' src="images/rightquote.png" width="32" height="20" alt="right quotation" align="right"/>
    

    然后使用 CSS 重新定位它:

    <style>
    #image2 {
    position:relative;
    top:-50px; // These numbers are just examples you can change them to anything to properly reposition your text.
    left:20px;
    z-index:-1; //depending on whether you want your image infront or behind the text you can change your z-index to either a positive number e.g.(5) or negative number e.g.(-2).
    }
    </style>
    

    如果您担心不同浏览器之间的不同格式,它们不会因为这个定位而出现巨大差异,但如果您可以使用溢出将文本环绕在图像周围,还有另一种方法可以做到这一点。例如:

     <div class='floating-eg'>
    <p>The kids really loved it!</p>
            <img class='left' src="images/rightquote.png" width="32" height="20" alt="right quotation" align="right"/>
    </div>
    <style>
    .floating-eg {
        overflow: auto;
    }
    p {
        overflow: auto;
    }
    </style>
    

    您可以查看包装here的相关示例。

    【讨论】:

    • 这里有一张图片,如果你想看看的话。 flickr.com/photos/77703125@N07/8371503407/in/photostream
    • @Anne:我认为最简单的方法是重新定位您的图像......但这也可能有助于使用
      paragraph
      所以至少你的图像是在线的,而不是在块之外......无论哪种方式,你都可能需要稍微调整一下位置;但我上面发布的代码可以做到这一点。
    • 不幸的是,独立定位图像并不会在所有浏览器中显示相同。它在 Chrome 中工作,但在 Explorer 和 Firefox 中,它较低(与文本不对齐)。
    • 溢出导致一些奇怪的事情发生。它放了一个滚动条并稍微重新格式化了我的文本。嗯。好吧,无论如何感谢您的帮助。我想我可能只是绝对定位它,然后只在 Chrome 中显示(如果我得到这次采访)。 :D
    猜你喜欢
    • 2019-03-28
    • 2020-10-23
    • 2014-01-26
    • 1970-01-01
    • 2014-04-22
    • 2016-10-31
    • 2020-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多