html - 如何在响应式设计中将多个 <article> 元素垂直居中?

标签 html css responsive-design

我想将我的文章类居中放置在我旁边的垂直位置。如果浏览器窗口的大小发生变化或变小(如在手机上),则居中应相应调整并且模板应响应。

顺便说一句:我谈谈我的三个“war-boxes”,你可以通过“Gegner 1”、“Gegner 2”和它们周围的灰色背景来识别它们。如果屏幕宽度大于或者等于1200px,文章要并排,分辨率小的文章要动态适配,在手机分辨率下相互支持。

我该怎么做?

HTML:

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Funfighter Alliance</title>
<link rel="stylesheet" href="/include/designs/FFA/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/include/designs/FFA/style.css" type="text/css" media="screen" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans|Roboto' rel='stylesheet' type='text/css'>
<script src="/include/designs/FFA/js/modernizr.js"></script>
<script src="/include/designs/FFA/js/respond.min.js"></script>
</head>

<body>
<!--Header mit Navigation-->
<header id="side-header-wrapper">
  <section id="side-header"> 
    <!--Logo + Logounterschrift-->
    <a href="http://funfighteralliance.de"><img alt="Funfighter Alliance - Offizielle Projekt-Homepage" src="/include/designs/FFA/bilder/Logo-FFA.jpg"></a>
    <p>Offizielle Projekt-Homepage</p>
    <!--Navigation-->
    <nav>
      <h2 class="hidden">Navigation</h2>
      <ul>
        <li><a href="index.php">Home</a></li>
        <li><a href="">News</a></li>
        <li><a href="">Teams</a></li>
        <li><a href="">Forum</a></li>
        <li><a href="">Kontakt</a></li>
      </ul>
    </nav>
  </section>
  </header>

<!--Spacer mit Log-In-->
<section id="spacer">
  <h2 class="hidden">Log-In</h2>
  <div class="login">{_boxes_VTEC-LOGINH}</div>
</section>

<!--3 Boxen für den War-Content-->
<aside>
<h2 class="hidden">Our Matches</h2>
<!--Topmatch Team 1-->
<article>
<img class="topwar_picleft" alt="Logo 1" src="/include/images/teams/team1.png" />
<p class="bluebox_versus">versus</p>
<img class="topwar_picright" alt="Logo 2" src="/include/images/teams/team1.png" />
<div class="topwar_whitebox">
<p class="whitebox_teamleft">Gegner links</p>
<p class="whitebox_versus">VERSUS</p>
<p class="whitebox_teamright">Gegner links</p>
</div>
</article>
<!--Topmatch Team 2-->
<article>
<img class="topwar_picleft" alt="Logo 1" src="/include/images/teams/team1.png" />
<p class="bluebox_versus">versus</p>
<img class="topwar_picright" alt="Logo 2" src="/include/images/teams/team1.png" />
<div class="topwar_whitebox">
<p class="whitebox_teamleft">Gegner links</p>
<p class="whitebox_versus">VERSUS</p>
<p class="whitebox_teamright">Gegner links</p>
</div>
</article>
<!--Last Matches-->
<article>
<img class="topwar_picleft" alt="Logo 1" src="/include/images/teams/team1.png" />
<p class="bluebox_versus">versus</p>
<img class="topwar_picright" alt="Logo 2" src="/include/images/teams/team1.png" />
<div class="topwar_whitebox">
<p class="whitebox_teamleft">Gegner links</p>
<p class="whitebox_versus">VERSUS</p>
<p class="whitebox_teamright">Gegner links</p>
</div>
</article>
<br class="clear" />
</aside>

<!--Content mit dynamischen Inhalt (je nach Unterseite generiert)-->
<div id="post"> {EXPLODE}</div>

<!--Footer, am Ende der Seite-->
<footer> </footer>
</body>
</html>

CSS:

/*Allgemeine Definitionen*/
body {
    background-color: #FFFFFF;
    border-top: 5px solid #009CFF;
    color: #272934;
    font-family: 'Open Sans',sans-serif;
    overflow-y: scroll;
    position: relative;
}
p {
    line-height: 25px;
    margin: 5px 0;
}
a {
    color: inherit;
    text-decoration: none;
    transition: color 0.5s ease 0s;
}
strong {
    font-weight: bold;
}
img {
    height: auto;
    max-width: 100%;
}
.hidden {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute;
}
.clear {
    clear: both;
}
/*Header*/
#side-header {
    color: #444444;
    font-family: 'Roboto',sans-serif;
    margin: 0 auto;
    max-width: 1200px;
    position: relative;
    width: auto;
}
#side-header-wrapper {
    background-color: #E8E8E8;
    background-image: linear-gradient(to top, #E8E8E8 0%, #FFFFFF 100%);
    background-repeat: repeat-x;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    height: 81px;
    padding-bottom: 20px;
    padding-top: 10px;
}
#side-header p {
    font-size: 14px;
    margin-left: 107.5px;
}
/*Navigation*/
nav {
    bottom: 0;
    font-size: 20px;
    position: absolute;
    right: 0;
}
nav ul li {
    display: block;
    float: left;
    padding: 3px 15px;
}
/*Spacer m. Login*/
#spacer {
    color: #444444;
    font-family: 'Open Sans',sans-serif;
    font-size: 14px;
    height: 70px;
    position: relative;
}
.login {
    max-width: 100%;
    overflow: hidden;
}
/*War-Boxes*/

.topwar_bluebox {
    background: none repeat scroll 0 0 #009CFF;
    float: left;
    font-size: 14px;
    height: 95px;
    margin-right: 45px;
    width: 256px;
}
aside {
    background: none repeat scroll 0 0 #808080;
    margin: 70px auto 45px;
    max-width: 1200px;
    width: auto;
}
aside article {
    width: 256px;
    margin-right: 45px;
    float: left;
    font-size: 14px;
}
.bluebox_versus {
    background: none repeat scroll 0 0 #FFFFFF;
    float: left;
    font-family: 'Open Sans',sans-serif;
    height: 22px;
    line-height: 25px;
    margin: 40px 0 0 12px;
    text-align: center;
    width: 46px;
}
.topwar_picleft {
    background: none repeat scroll 0 0 #FFFFFF;
    float: left;
    margin-left: 22px;
    margin-top: 12px;
    width: 72px;
}
.topwar_picright {
    background: none repeat scroll 0 0 #FFFFFF;
    float: right;
    margin-right: 22px;
    margin-top: 12px;
    width: 72px;
}
.topwar_whitebox {
    background: none repeat scroll 0 0 #FFFFFF;
    float: left;
    font-size: 11px;
    font-weight: bold;
    margin-right: 45px;
    width: 256px;
}

.whitebox_teamleft {
    background: none repeat scroll 0 0 #FFFFFF;
    float: left;
    margin-left: 22px;
    max-width: 72px;
}
.whitebox_versus {
    background: none repeat scroll 0 0 #EEEEF1;
    color: #2099DC;
    float: left;
    font-family: 'Open Sans',sans-serif;
    height: 14px;
    line-height: 14px;
    margin: 10px 0 0 13px;
    text-align: center;
    width: 44px;
}
.whitebox_teamright {
    background: none repeat scroll 0 0 #FFFFFF;
    float: right;
    margin-right: 22px;
    max-width: 72px;
}
/*Content*/
#post {
    clear: both;
    font-family: 'Open Sans',sans-serif;
    line-height: 25px;
    margin: 0 auto;
    max-width: 1200px;
    position: relative;
    width: auto;
}
/*News*/
#news_headline {
    border-top: 2px solid #009CFF;
    max-width: 1200px;
    padding-bottom: 7px;
    padding-top: 14px;
}
.news_headline_kate {
    background-color: #00A3FF;
    float: left;
    font-size: 11px;
    height: 15px;
    line-height: 15px;
    max-width: 48px;
    text-align: center;
}
.news_headline_title, .news_headline_title_1 {
    display: inline-block;
    font-weight: 700;
    margin-top: -3.5px;
    max-width: 250px;
    overflow: hidden;
    padding-left: 48px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.news_headline_title_1 {
    max-width: 470px;
}
img.news_headline_writersgraphic {
    height: 16px;
    margin-top: -3.5px;
    max-width: 17px;
    position: absolute;
}
.news_headline_username {
    font-size: 11px;
    margin-left: 18px;
    margin-top: -1px;
    position: absolute;
}
.news_headline_datum {
    color: #858A9F;
    font-size: 11px;
    margin-left: 171px;
    margin-top: -1px;
    position: absolute;
    white-space: nowrap;
}
#news_content {
    font-size: 14px;
    margin-top: 12px;
    padding-bottom: 12px;
}
#news_footer {
    max-width: 1200px;
    padding-bottom: 16px;
    padding-top: 14px;
    position: relative;
}
a.news_headline_comment {
    background-color: #272934;
    color: #FFFFFF;
    float: left;
    font-size: 11px;
    height: 17px;
    line-height: 17px;
    max-width: 48px;
    position: absolute;
    text-align: center;
    text-decoration: none;
    top: 7px;
}
#news_headline, #news_content {
    border-bottom: 1px solid #009CFF;
}
/*Footer*/
footer {
    background: none repeat scroll 0 0 #333333;
    clear: both;
    height: 350px;
    position: relative;
    width: auto;
}

链接到我的代码的 jsfiddle 示例:Click me

最佳答案

垂直居中的一种响应式方法是使用 Flexbox即使它还没有得到所有浏览器的完全支持,并且它不适用于旧浏览器 (ref)。

关于html - 如何在响应式设计中将多个 <article> 元素垂直居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21203401/

相关文章:

html - 无法使此框响应

html - 响应式设计和图像尺寸

css - 使用视口(viewport)高度会导致某些屏幕尺寸的某些部分出现像素线

html - 如何创建一个标题,在整个宽度上用一种颜色填充背景

javascript - 将 jQuery 偏移量从一个元素复制到另一个元素会将它们放在不同的位置

html - 缩放页面时对齐问题

html - 使textarea填充表格中整个单元格的方法

javascript - 动态创建的样式元素

javascript - onClick时取消流,javascript

html - 带滚动的两部分 div