html - 如何更改图像的位置而不影响其左侧的文本?

标签 html css

代码:

<div class="container_bottom_tip">
    <div class="container_bottom_desc">This is some text
        <img class="browser_button_img" src="images/something.png">
    </div>
</div>

.container_bottom_tip {
    text-align: center;
}
.container_bottom_desc {
    color: #333;
}

使用上面的代码,我想将图像向上移动一点。因此,当我在图像上执行类似 margin-top 之类的操作时,它会拖动文本“This is some text”。

如何在不影响文本“This is some text?”的位置的情况下向上或向下移动图像?

最佳答案

你可以使用position:relative

然后您可以通过更改 css 的“top”属性来调整图像的位置。这将在不影响父 div 的情况下移动它。

http://jsfiddle.net/MCJhs/

.container_bottom_tip {
    text-align: center;
}
.container_bottom_desc {
    color: #333;
}
.browser_button_img{
    position: relative;
    top: 30px;
}

关于html - 如何更改图像的位置而不影响其左侧的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18255675/

相关文章:

javascript - HTML5 Canvas 粒子效果与图标

javascript - 用于通过 AJAX 提交表单的 jQuery?

jquery - 查找和替换问题

javascript - Ajax 加载程序图像不工作

javascript - 为什么嵌入后没有应用 css 样式?

internet-explorer - DOCTYPE、iFrame、HTML5——一起

javascript - jQuery 未检测到 div 调整大小

html - 使用 css/html 将一个元素移动到另一个元素之前

html - 在同一类中引用 CSS 属性

javascript - 我怎样才能垂直固定 div 元素?