css - 包装表内的居中表单元格 - 3 列,流体布局

标签 css responsive-design centering css-tables fluid-layout

我第三次尝试根据 Stack Overflow 成员的更多建议重新编码我的网站以获得响应式布局。这次我使用 display:table/display:table-cell 设置来居中页面包装器,其高度由内容和粘性页脚控制。

一位成员建议了一个可行的基本布局(谢谢!)但是如果我使用的宽度小于 100%,我就无法将内联包装器置于页面包装器的中心。它强制内联包装器位于页面包装器的右侧。

我试过边距、填充和文本对齐。我可能可以用“center”标签破解它,但我希望我的代码是语义化的。

这是我的代码的浓缩 View - 我不确定我是否做错了什么,缺少语法(我之前忘记了一个逗号,这让我花了 30 分钟的时间进行故障排除),它需要 ie10 和 Opera 或其他任何东西的 hack .

<div id="page-wrapper>
 <div id="logo"><img /></div>
 <div id="inline-wrapper">
  <div id="top-content">
   <div id="left"><img /></div>
   <div id="center">content blah blah</div>
   <div id="right"><img /></div>
  </div>
  <div id="nav-menu"><ul><li><img /></li></ul></div>
  <div id="main-content">
   <div id="left"><img /></div>
   <div id="center">content blah blah</div>
   <div id="right"><img /></div>
  </div>
</div></div>
<div id="footer"></div>

html, body, #page-wrapper, #inline-wrapper, #top-content, #main-content {
      height:100%;
    width:100%;
    margin:auto;
}

#page-wrapper {
    height:100%;/* to show footer */
    width:70%;
    position:relative;
    display:table;
    table-layout:fixed;
    border:solid;
}
#logo {
    width:100%;
    top:.75%;
    z-index:99;
    position:absolute;
}
#logo > img {
    width:100%;
}
#inline-wrapper {
    position:relative;
    display:table-cell; <-- /* I removed this */
    width:90%;
    margin:auto;
    background-color:#fff;
    padding-bottom:1%;
}

#top-content, #main-content {
     display:table;
     width:98%;
     border-collapse:collapse;
}
#top-content {
     height:60%;
}

#right, #left, #center {
    display:table-cell;
}

#left {
    background-color:#CC0000;
    width:14%;
}

#left img {
    width:100%;
    height:100%;
}

#right {
    background:#0600ff;
    width:14%;
}

#center {   
    width:72%;
    background:#ccc;
}

#nav-menu {
    width:100%;
    margin:0 auto;
    text-align:center;  
}

#nav-menu li {
    color:#fff;
    margin:auto;
    display:inline-block;
    background-color:#000000;
    list-style-position:inside;
    border:1% solid #ffffff;
    padding:.75%;
    width:12.5%;
    height:31%;
    vertical-align:top;
}

#nav-menu li:hover {
    opacity: .55;
  filter: alpha(opacity=55);
}

#nav-menu li img {
    height:100%;
    width:100%;
}

#footer {
  width:100%;
  height:250px;
  background-color:#000;
  border-top:solid;
}

最佳答案

尝试关闭此处的 ID:<div id="page-wrapper> .将其更改为:< div id="page-wrapper">

关于css - 包装表内的居中表单元格 - 3 列,流体布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16972029/

相关文章:

html - 响应式全屏背景。如何让它与 FF 和 IE 一起工作?

css - 无法在页面上水平居中元素

javascript - 无法将 DIV 元素居中

android - ConstraintLayout - 垂直或水平居中 View

CSS 过渡 : Shrink height of div whose height is determined by its content

javascript - 我怎样才能使可折叠的内容默认传播(显示)

css - 模拟位置 :absolute and higher z-index without using CSS?

html - 将图像 float 在文本和段落的左侧,同时保持一切响应

mobile - Bootstrap XS 版本无法在手机和平​​板电脑上运行

css - 如何为单独的媒体查询条件使用相同的 css