css - 试图让一个 div 向右浮动 - 包括 jsfiddle

标签 css

我使用 div 在图像周围创建框架。我正在尝试获取 div,它包含要向右浮动的图像,以便周围的段落环绕它。

jsfiddle 链接:http://jsfiddle.net/0vnfngws/

样式:

.imgframe {
    margin: 12px;
    position: relative;
    display: inline-block;
    padding: 8px;
    border: 1px solid #cbcbcb;
    background: #f7f7f7;
    box-shadow: 2px 2px 5px 0 #e5e5e5;
    -moz-box-shadow: 2px 2px 5px 0 #e5e5e5;
    -webkit-box-shadow: 2px 2px 5px 0 #e5e5e5;
}
.imgframe img {
    margin: 0;
    padding: 8px;
}
.floatright { 
    float: right;
}

HTML:

<p>This is some text here. I want the paragraph to wrap around the image, not to be positioned above and below it.</p>

<div class="imgframe"> <img src="http://www.hdicon.com/wp-content/uploads/2010/06/Firefox_2004_2.png" alt="#" class="floatright" /> </div>

<p>This is some more text here. I want the paragraph to wrap around the image, not to be positioned above and below it.</p>

最佳答案

您需要做的就是将 float: right; 添加到您的 .imgframe

.imgframe {
    float: right;
    margin: 12px;
    position: relative;
    display: inline;
    padding: 8px;
    border: 1px solid #cbcbcb;
    background: #f7f7f7;
    box-shadow: 2px 2px 5px 0 #e5e5e5;
    -moz-box-shadow: 2px 2px 5px 0 #e5e5e5;
    -webkit-box-shadow: 2px 2px 5px 0 #e5e5e5;
}

参见 updated JSFiddle .

关于css - 试图让一个 div 向右浮动 - 包括 jsfiddle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31910525/

相关文章:

jquery - 如何检测窗口大小,然后用 jquery switch 语句做一些事情

javascript - 如何在网页上执行内联导航?

html - 使用 css 边框形成 Angular 点

ASP.Net 呈现的不正确的背景图像样式

css - 即 : nth-child() using odd/even isn't working

html - IE 11 中的相对定位不正确的像素宽度

html - 对齐列底部的内容

html - 如何将两个超链接并排放置?

html - 使 IE 10 重复 svg 背景

html - 两个内联 div 不遵守宽度