html - div 中的图像

标签 html css

我无法在 div 中对齐图像。 我想将其右对齐。

将图像 float 到右侧后,我得到了这个: http://i.imgur.com/pNzY56Y.png

<img src="Images/Products/47_dolcimo-max-001.jpg" width="263" height="155" style="float:right;">

它看起来像是离开了 div,但实际上不是。

如果我将 float 设置为 none,这与什么都没有一样,我会将它放在 div 的内部和右侧。至少在视觉上。 enter image description here

<img src="Images/Products/47_dolcimo-max-001.jpg" width="263" height="155" style="float:none;">

来自 div 的 CSS:

.headerphoto {
    z-index: 0;
    position: relative;
    margin: 0 auto;
    width: 760px;
    height: 100%;
    border-width:1px;       
    border-color:#EFEDED;
    border-right-style: solid;
    border-left-style:solid;
    border-top-style:solid;
    border-bottom-style:solid;
    margin-top:20px;
}

来自 div 的 HTML:

<div class="headerphoto">

    <img src="Images/Products/practidose.fw.png" width="760" height="65" > 
    <img src="Images/Products/47_dolcimo-max-001.jpg" width="263" height="155" style="float:none;"> 

    </div>

最佳答案

图像出现在您的 div 之外,因为您没有清除 float 。有多种方法可以做到这一点。我建议将 overflow: hidden 添加到您的父 div

.headerphoto {
    z-index: 0;
    position: relative;
    margin: 0 auto;
    width: 760px;
    height: 100%;
    border-width:1px;       
    border-color:#EFEDED;
    border-right-style: solid;
    border-left-style:solid;
    border-top-style:solid;
    border-bottom-style:solid;
    margin-top:20px;
    overflow: hidden; /* ADDED THIS */
}

关于html - div 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23366206/

相关文章:

html - Grails和HTML编纂

html - 使用 HTML/CSS 的响应式设计中的意外行为

html - 为什么我不能根据CSS中的文本调整图像的大小?

javascript - 尝试创建轮播效果时出错

javascript - 自动着色文本 | JS CSS HTML

css - 如何将具有功能的高级CSS应用于除一个元素以外的主体

javascript - 存储选项卡的数据和信息

Javascript 此引用可内联使用,但并非没有内联引用

css - 使 Float 元素内联

CSS圆形边框填充动画