【问题标题】:CSS Header Image AlignmentCSS 标题图像对齐
【发布时间】:2017-08-04 14:40:01
【问题描述】:

我想就我的 subreddit 页面的标题图像对齐寻求 CSS 方面的帮助。这是标题图像和叠加层的当前代码,请忽略 z-index 和其他代码:

  #header {
  z-index: 2147483647;
  height: 260px;
  border: 0;
  box-shadow: inset 0 -90px 0 0 rgba(21, 27, 33, .6);
  background: url(%%overlay%%) fixed center/auto auto, linear-gradient(45deg, rgba(39, 161, 227, .65), rgba(231, 35, 42, .65)), url(%%header%%) 0 0/cover

从这段代码中,我的标题图像将与左边缘对齐,即使我调整浏览器大小或在移动设备上查看也是如此。我希望更改对齐方式,即使我调整浏览器大小或在移动设备上查看,它也会使标题图像居中。

这是另一个模板,其中标题图像给出了我正在寻找的结果:

#header {
border: 0;
height: 200px;
background-color: #000000;
background-image: url(%%banner1%%);
background-repeat: repeat;
background-position: center;
}
#header #header-img { display: none; }
@media (max-width: 1800px) {
    #header {
        background-size: cover;
        background-position: center;

我在这方面真的很弱,我无法将它们投射出来以获得相同的结果,如果有人能帮助我解决这个问题,我将不胜感激,谢谢!

【问题讨论】:

    标签: css image browser header alignment


    【解决方案1】:

    尝试像这样将 margin:auto 添加到您的#header 样式中

    #标题{ 边距:自动; …… }

    【讨论】:

    • 嗨,理查德,感谢您的回复!我已经尝试了你的建议,#header {margin:auto; z-index:2147483647;高度:260px;边框:0;盒子阴影:插图 0 -90px 0 0 rgba(21, 27, 33, .6);背景: url(%%overlay%%) 固定中心/自动自动, 线性渐变(45deg, rgba(39, 161, 227, .65), rgba(231, 35, 42, .65)), url(% %header%%) 0 0/cover 虽然它似乎不起作用
    • 您能否添加 html 布局并解释标题图像需要如何居中。我的意思是它是页面的中心还是相对于某些 div 居中
    • 你好,理查德,感谢你的帮助,我已经设法跨模板移植部分代码,但它们没有按预期工作:D
    猜你喜欢
    • 2017-01-18
    • 2014-02-05
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多