【问题标题】:Keeping several Divs centered inside a container. Also Footer stuck in middle将多个 Div 保持在容器的中心位置。页脚也卡在中间
【发布时间】:2012-09-18 03:13:14
【问题描述】:

我意识到这个问题已经在这里出现了几次,但我似乎无法找到解决我的具体问题的方法。我目前正在建立一个摄影网站,虽然花了我很长时间,但进展顺利。我通常不会问太多问题,而是寻找答案,但这让我发疯。我对网络建设非常陌生,并认为自己是一个完全的新手。

现在我有一个“照片”主页面,该页面将链接到画廊,在这个页面中,我将拥有带有一些精美 CSS3 效果的大型缩略图。

在这个页面中,我创建了 6 个包含这些大缩略图的 div,我需要它们做的是在屏幕缩小时重新定位(或显示在较小的分辨率显示器上等)现在 img 容器实际上在显示时重新定位在较小的设备上,但我正在努力实现的是将 6 个 div 保持在屏幕中间。

我尝试的最后一个解决方案是“display: inline-block” 而且包含的 div 的高度似乎没有随着内容而扩展。我想这里有一点遗漏,所以很感激任何建议和帮助。

我还没有深入研究页脚问题,但对此的任何帮助也会很棒。问题是它只是定位在页面底部(我虽然是粘性的)但是现在页面有足够的内容来滚动它只是停留在原处。

非常欢迎对整个网站的任何其他帮助和 cmets :o) 提前非常感谢!!

有问题的页面russfrancis.co.uk/photo

请查看以下标记和 CSS:

照片标记:

<div class="photomain">
  <div class="containerwrapper">
    <div class="photoimgcontainer">
      <div class="view view-second">
        <img src="images/photo/tn/asialg.jpg" />
      <div class="mask"></div>
      <div class="content">
        <h2>Asia</h2>
        <p>In 2008 I spent 6 months backpacking around Asia.</p>
        <a href="asia.htm" class="info">View The Galleries</a>
      </div> <!-- Content Close -->
      </div> <!-- View-second close -->
    </div> <!-- Img Container Close -->
      <div class="photoimgcontainer">
      </div>
      <div class="photoimgcontainer">
      </div>
      <div class="photoimgcontainer">
      </div>
      <div class="photoimgcontainer">
      </div>
      <div class="photoimgcontainer">
      </div>
    </div> <!-- Container Wrapper Close -->
  </div>

CSS:

.photomain{
width: 90%;
height:auto;
margin: 130px auto 0;}

.containerwrapper{
display:inline-block;
height:auto;}

.photoimgcontainer{
background-color:rgba(19,19,19,1);
width: 535px;
height: 360px;
float:left;
margin: 5px 5px;}

页脚标记:

<footer>
  <div class="footdiv">
    <p align="center">Follow Me</p> 
    <div class="footimg">
     <a href="https://www.facebook.com/RussFrancisPhotography" target="_blank"><img src="images/facebook.png" width="40" height="40" border="0" alt="RFP Facebook Page"></a>
     <a href="http://www.flickr.com/photos/russfrancisphotography/" target="_blank"><img src="images/flickr.png" width="40" height="40" border="0" alt="Russ Francis Flickr"></a>
     <a href="http://vimeo.com/lucidskies" target="_blank"><img src="images/vimeo.png" width="40" height="40" border="0" alt="Vimeo - Lucid Skies"></a>
     <a href="https://twitter.com/R_F_Photo" target="_blank"><img src="images/twitter.png" width="40" height="40" border="0" alt="Russ Francis - Twitter"></a>
    </div> 
 </div>
 <p class="pleft">&copy; Russ Francis Photography 2012</p>
 <div class="pright"><a href="#">Contact Me</a></div>
</footer>

页脚 CSS:

footer {
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
color:#FFF;
position:absolute;
left: 0;
bottom: 0;
height: 115px;
width: 100%;}

.footdiv p {
padding-bottom: 10px;
border-bottom: 1px solid rgba(153,0,0,1);}

.footdiv {
margin: 0 auto 0;   
width:200px;
height:60px;}

.footimg {
padding-left: 14px;}

.pleft {
padding-left: 10px;
color:#999;
font-size:12px;
float:left;}

.pright {
font-size:15px;
padding-right: 20px;
float:right;}

.pright a {
color:#FFF;
text-decoration:none;}

【问题讨论】:

  • 请检查我的答案,如果我落后于任何地方,请告诉我

标签: css image positioning html sticky-footer


【解决方案1】:

从页脚中删除bottom: 0; 将位于底部

footer {
    color: #FFFFFF;
    font-family: "Trebuchet MS",Arial,Helvetica,sans-serif;
    height: 115px;
    left: 0;
    position: absolute;
    width: 100%;
}

.containerwrapper {

    height: auto;
    margin: 0 auto;
    max-width: 1100px;
}

只需在 &lt;footer &gt; 之前添加 &lt;div style="clear:both;"&gt;&lt;/div&gt;

输出 不要认为白线是因为有拖曳图像

【讨论】:

  • 感谢您的建议,它适用于相关页面,但在主页上它只是位于顶部。
  • 你可以通过内联css解决这个问题
  • 非常感谢您的时间和帮助,效果很好!有底:0;起飞了,这现在会导致页脚下方的空白空间吗?
【解决方案2】:

尝试在您的网站上使用此处的 css,看看它是否适合您:http://dabblet.com/gist/3739171

【讨论】:

    猜你喜欢
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 2020-07-31
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 2015-12-26
    相关资源
    最近更新 更多