javascript - 如何将网站与屏幕顶部/底部和右侧/左侧的中心对齐?

标签 javascript php css html

我想要类似dropbox的效果:https://www.dropbox.com/我的网站位于页面正中间的位置。

最佳答案

实现这种效果比应有的复杂得多。这是一个简单的工作示例:http://jsfiddle.net/JakobJingleheimer/UEsYM/

html, body { height: 100%; } // needed for vertical centre

html { width: 100%; } // needed for horizontal centre

body {
    display: table; // needed for vertical centre
    margin: 0 auto; // needed for horizontal centre
    width: 50%; // needed for horizontal centre
}

.main-container {
    background-color: #eee;
    display: table-cell; // needed for vertical centre
    height: 100%; // needed for vertical centre
    // overflow: auto; // <- probably a good idea
    vertical-align: middle; // needed for vertical centre
    width: 100%; // needed for horizontal centre
}

.container {
    background-color: #ccc;
    padding: 20px;
}

screenshot from JSFiddle example

关于javascript - 如何将网站与屏幕顶部/底部和右侧/左侧的中心对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20674317/

相关文章:

php - 尝试应用身份验证中间件时数组到字符串的转换

php - 循环出mysql数据

jquery - 在嵌套列表 block 中显示/隐藏子元素

javascript - 如何使用 Node 解析整个 Common Crawl 数据库?

javascript - 提交时抛出错误如何允许表单 POST

javascript - 验证 - 更改无效元素父级的背景颜色

html - 响应式设计 : Why isn't css responding to mobile screen size?

javascript - 使用 RSA 解密字符串

php - 数学字母数字符号的正则表达式

css - 如何编写 Angular 指令以基于表单验证更新 CSS 类