简体   繁体   English

如何使侧边栏显示在响应式网页的底部?

[英]How do I make my sidebar appear at the bottom of my responsive webpage?

First time on these boards, so please go easy. 第一次使用这些主板,所以请放轻松。

I've been trying to make my website http://sartorialequity.com/ responsive by using media queries. 我一直在尝试使用媒体查询来使我的网站http://sartorialequity.com/响应。 However, my right sidebar is currently displayed above my content, while I'd like it to appear at the bottom of my content. 但是,我的右侧边栏当前显示在内容上方,而我希望它显示在内容底部。

Here's a simplified version of my code: 这是我的代码的简化版本:

#container {
            width: 960px; 
            margin: auto;
        }

#content {
            width: 66.67%; 
        }

#sidebar {
            width: 260px;
            float: right;
            top: 70px; 
            position: relative;
        }

@media screen and (max-width: 768px) {
#container {
width: 91%
        }

#content {
float: none;
width: auto;
line-height: 135%;
       }

#sidebar {
float: none;
width: auto;
top: 10px;
       }

<div id="container"></div>
<div id="sidebar"></div>
<div id="content"></div>

The solutions I've tried so far: 到目前为止,我尝试过的解决方案:

1. Using display: table-footer-group 1.使用显示:table-footer-group

#content-sidebar-wrap {display:table;}
#content {display:table-header-group; float: none; width: auto}
#sidebar {display:table-footer-group; float: none; width: auto}

On a mobile phone, this was successful in getting the sidebar to appear below the content, at least on the main page. 在手机上,这成功地使侧栏显示在内容下方,至少出现在主页上。 However, it caused the content and sidebar of PermaLink Pages to extend beyond the width of the header. 但是,这导致PermaLink Pages的内容和侧栏超出了标题的宽度。

2. Rearranging div id="sidebar" and div id="content" 2.重新排列div id =“ sidebar”和div id =“ content”

<div id="container">
<div id="content"></div>
<div id="sidebar"></div>
</div>

On a mobile phone, this was successful in getting the sidebar to appear below the content. 在手机上,这成功使边栏显示在内容下方。 However, when on my PC's browser window, it caused the sidebar to appear at the bottom of the page. 但是,当在我的PC的浏览器窗口中时,它导致边栏出现在页面底部。

I'd truly appreciate any suggestions. 我真的很感激任何建议。 Thanks! 谢谢!

Content appearance is not merely concerned with the order of your raw html. 内容外观不仅与原始html的顺序有关。 Styles can bring a lot of change. 样式可以带来很多变化。

First try to use this layout: 首先尝试使用此布局:

<div id="content"></div> // Content div comes first 
 <div id="sidebar"></div> // Then Comes Sidebar.

Remember, this layout does not mean you may not use your sidebar right to your page. 请记住,这种布局并不意味着您不能在页面右侧使用侧边栏。 If content div is not floated, sidebar will come after content and at the bottom of page, float to right. 如果content div未浮动,则sidebar将位于content之后,并在页面底部浮动至右侧。 So, you have to float the content div to left, this will cause a space of 33.3334% to it's right, that will be filled up by sidebar . 因此,您必须将content div向左浮动,这将在其右侧造成33.3334%的空间,并由sidebar填充。
But for mobile device, since you have set float:none to both divs, the order of raw html will itself play the role for appearing sidebar to bottom. 但是对于移动设备,由于已将float:none设置到两个div,原始html的顺序本身将起到使侧边栏显示在底部的作用。

Hence, try some minor style changes: 因此,请尝试一些小的样式更改:

    #content {
    float: left; //This line will bring the change. It is necessary.
    width: 66.67%;
    width: calc(100% - 294px); //you may or may not add this line 
    height: 100%;
    font-family: Georgia, Palatino, 'Palatino Linotype', Times, 'Times New    Roman', serif;
    line-height: 160%;
}

The content div should be first in the markup. 内容div应该位于标记的第一位。 That would solve the issue you have. 这样可以解决您遇到的问题。

<div id="content"></div>
<div id="sidebar"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM