【问题标题】:Need advice and solution需要建议和解决方案
【发布时间】:2013-01-27 09:50:32
【问题描述】:
<div class="wrapper">
  <div class="header">
   <img id="back" />
   <img id="front" />
  </div>
  <div class="body">
   ...
  </div>
  <div class="footer">
   ...
  </div>
</div>

<style type="text/css">
.wrapper {
    margin-left: auto;
margin-right: auto;
margin-top: -8px;
width: 1024px;
height: 1500px;
background-color: #CCC;
border: 1px solid;
/*display: run-in;*/
/*position:fixed;*/
text-align: center;
}

.header {
background-color: #FFC;
/*margin: 0 auto;*/
height: 150px;
width: 1000px;
display: box;
z-index: 10;
text-align:center;
vertical-align:middle;
position: fixed;
display:block;
}

#back {
position: relative;
width: 100%;
}

#front{
position: relative;
z-index: 10;

}

我需要将标题固定在页面顶部(包装器是固定宽度),包装器内的图像在标题内水平和垂直居中。如何实现?

好的。 澄清 Wrapper 是固定宽度的。 页眉应贴在页面顶部(包装器内部)并包含两张图片/图像。图像应相互重叠,并在标题内垂直和水平居中。 希望我现在足够精确。

【问题讨论】:

  • 不得不说这个问题可能不应该回答,如果你改进你的问题,我会改进我的答案
  • 当然,我会改进问题,不需要那样。
  • 为什么你没有发布任何CSS? SO 的目的不是让人们为您编写代码,而是帮助您解决代码中的问题。您的问题中的任何内容都无法在网络搜索中轻松找到
  • 图片尺寸?标题高度?您已经在使用任何其他 CSS 规则了吗?

标签: jquery css


【解决方案1】:

怎么样:[简单地说更多未经测试的伪代码]

css:

.wrapper{
 width: 960px;
 margin-left: auto;
 margin-right: auto;
}

.banding{
/*add stuff*/
}

.header{
 position: absolute;
 top: 0px;
 width: 100%;
 min-height: 150px;
 margin-top: 40%; /*this will depend on images etc*/
}

然后在html中:

<div class="header banding">
       <img />
       <img />
   </div>
    <div class="wrapper">

      <div class="body">
       ...
      </div>
      <div class="footer">
       ...
      </div>
    </div>

【讨论】:

  • 不。页眉位于页面中心,并延伸超过 960px 的包装器。页眉应该贴在包装器内的页面顶部。我会尽快发布我尝试过的内容。
  • 对不起,我对标题的定义就是这样。
  • 没问题,但我正在努力实现这一目标......我如何在此处发布图片以便更好地了解我的需求?
猜你喜欢
  • 2018-12-11
  • 2011-01-26
  • 1970-01-01
  • 1970-01-01
  • 2016-03-31
  • 1970-01-01
  • 1970-01-01
  • 2023-01-26
  • 1970-01-01
相关资源
最近更新 更多