html - 问题居中图像

标签 html css

我们有一个 2000 像素宽 x 580 像素高的图像,目前它适合屏幕,即当我们调整浏览器大小时,中间的箭头居中,图像似乎失去了居中,我已经看到这样做,你有一个大图片居中,当浏览器调整大小时,图片保持居中。

谁能告诉我这是怎么做到的?

enter image description here

<div style="height:580px; margin-left:-10%; position:relative; max-width: 2000px; background-image:url("/content/largeImage.png")">
     <div class="container">
        <p>
          Do something else
        </p>
     </div>
</div>

最佳答案

在您看到的案例中,他们很可能使用了背景图像,可以使用 background-position 将其居中:

header{
background:url('http://lorempixel.com/1500/500/') no-repeat;
background-position:center;
width:100%;
height:300px;
}
<header></header>

http://fiddle.jshell.net/8L2L1ey1/

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

相关文章:

html - 将 aria-label 添加到文本元素

javascript - 将 RGB 一种颜色转换为图像 HTML 5 Canvas 的另一种颜色

html - 我有一行 X 像素宽的文本。背景颜色也是 X px 宽。如何扩展背景颜色使其比文本更长?

javascript - 自动触发下一个选定项目

javascript - IE8 中的文本溢出输入字段和占位符问题

javascript - 如何修复通知框插入符号?

jQuery - 将多个单词更改为多个图像

javascript - 使用 history.pushState 后检测浏览器后退按钮

jQuery UI 自动完成样式不正确

css - 如何为 Zend 表单设置 css?