响应侧边栏wordpress主题



我有以下内容,想知道是否有人能帮助解释我应该如何使标记中的侧边栏折叠并放在wordpress博客主题中的主要内容下方。我有一种感觉,我可能需要一个特定的媒体查询,但不确定是什么。

这一切都是为了一个wordpress博客主题,我正试图从头开始建立。有一个带有导航和图像的标题,我对此没有问题,但是,我需要有一个主内容容器,其中包含用于向左浮动的文章的内容div和用于向右浮动的小部件的边栏div。如果有人能帮我开始这个过程,我将永远感激。

CSS代码:

.gridContainer {
margin-left: auto;
margin-right: auto;
width: 87.36%;
padding-left: 1.82%;
padding-right: 1.82%;
}
#LayoutDiv1 {
clear: both;
float: left;
margin-left: 0;
width: 100%;
display: block;
}
#LayoutDiv2 {
clear: both;
float: left;
margin-left: 0;
width: 100%;
display: block;
}
body, html {
height: 100%;
}
#content{
display:inline-block;
float:left;
width:80%;
}
#sidebar{
display:inline-block;
float:left;
width:20%;

}

/* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */
@media only screen and (min-width: 481px) {
.gridContainer {
width: 90.675%;
padding-left: 1.1625%;
padding-right: 1.1625%;
}
#LayoutDiv1 {
clear: both;
float: left;
margin-left: 0;
width: 100%;
display: block;
}
#LayoutDiv2 {
clear: both;
float: left;
margin-left: 0;
width: 100%;
display: block;
}

/* Desktop Layout: 769px to a max of 1232px.  Inherits styles from: Mobile Layout and     Tablet Layout. */
@media only screen and (min-width: 769px) {
.gridContainer {
width: 88.2%;
max-width: 1232px;
padding-left: 0.9%;
padding-right: 0.9%;
margin: auto;
}
#LayoutDiv1 {
clear: both;
float: left;
margin-left: 0;
width: 100%;
display: block;
}
#LayoutDiv2 {
clear: both;
float: left;
margin-left: 0;
width: 100%;
display: block;
}

HTML代码

<body>
<!--HEADER, CONTENT, FOOTER-->
<div class="gridContainer clearfix">
<!--HEADER--> 
<div id="LayoutDiv1">
<!--NAVIGAIION + LOGO-->
<nav>
<div class="header">
<div id="logo"></div>   
<!--navigation list items-->
<ul>
<li><a href="">home</a></li>
<li><a href="">about</a></li>
<li><a href="">contact</a></li>
<li><a href="">work</a></li>
</ul>

</div>
</nav>
<!--end of NAVIGATION + LOGO-->

<div id="LayoutDiv2" class="clearfix">
<div id="content">
<p> This is the Content</p>     
</div>

<aside>
<div id="sidebar">
<p> This is the Sidebar</p>
</div>
</aside>


</div><!--end of LayoutDiv2-->


</div><!--end of LayoutDiv1-->


</div><!--end of Grid Container, HEADER, CONTENT, FOOTER-->

</body>

您需要为您的内容和侧边栏编写一个媒体查询,例如:

@media (max-width: 600px) {
#sidebar{ clear: both; width: 100%; }
#content{ clear: both; width: 100%; }
}

这允许您将div放在一起,并使它们成为页面的全宽。

请参阅此JSFiddle以获取一个工作示例。

最新更新