CSS Div Block re-arranging for multiple screens - html

So what I'm trying to do is design a page that has two sidebars and a main article area. As it shrinks down for tablet or phone use though, I want the two sidebars to move so they are stacked vertically beside the main area at first, and then eventually both move below it. The Problem I am having is I can't get them to re-order correctly upon doing so.
The three sections on the left (desktop/tablet/phone) is how I want it. The pages on the right are how it's appearing now. Basically I need 5 to move up under 4, and 3 to move beside 4/5 for tablet view, and then 4 to move down under 3 for phone view.
I hope that makes sense? I'm using Dreamweaver if it helps/matters. Thanks!
Clicky to see what I mean!

It can be done if certain heights are known.
Fiddle: http://jsfiddle.net/BramVanroy/Pt7sS/
The height of #contentWrap and #sideRight need to be known to make this work. If these are not known, you can fetch the heights through jQuery.
html, body, #header1, #header2, #contentWrap {
width: 100%
}
#header1 {
background: red;
height: 50px
}
#header2 {
background: green;
height: 40px
}
#sideLeft, #main, #sideRight {
box-sizing: border-box;
float: left;
height: 200px
}
#sideLeft, #sideRight {
width: 20%;
background: #333
}
#main {
background: grey;
width: 60%
}
#media screen and (max-width: 768px) {
#main {
float: right;
width: 65%
}
#sideRight {
clear: left
}
#sideRight, #sideLeft {
width: 35%;
height: 100px
}
}
#media screen and (max-width: 480px) {
#sideLeft, #main, #sideRight {
float: none;
width: 100%;
position: absolute
}
#contentWrap {
position: relative;
height: 400px
}
#main {
top: 0
}
#sideLeft {
bottom: 100px
}
#sideRight {
bottom: 0
}
}
​

Related

Resize the width of the div in mobile phone

I have two divs. One is 15%, and the other is 76%. I want to hide the 16% div on mobile phones. That is being achieved using this.
class="navbar hidden-xs"
And the code is as follows
#right {
top: -1px;
position: fixed;
background: blue;
width: 15%;
}
However, when I change the screen size, the box is getting hidden but the space remains there. I want to make the width of the content to 100% in mobile-only. How can I achieve this? My code for the content is as follows:
#content {
float: right;
width: 76%;
}
#media (max-width: 767px) {
#right {
display: none;
}
#content {
width: 100%;
float: none
}
}

How can I make that columns in html stay in a row?

#media screen and (min-width:450px){
.dark-blue{
width: 50%;
}
#container2{
width: 50%;
}
}
When this media query triggers, the dark-blue div and the div whose id is container2 will not stay in a row. Specifically, a blank below the dark-blue div is the issue. All I want to know is how to make them symmetrical. More detail in my github.https://github.com/kmfb/udacityProjects/tree/master/model.
I would try something like this:
#media screen and (min-width:450px){
.dark-blue{
width: 100%;
}
#container2{
width: 100%;
}
#container2 div {
width: 50%;
display: inline;
}
}

How to place <aside> block underneath <article> block rather than next to it

I want to place <aside> sidebar column underneath the <article> main column(rather than next to it) to suit smaller screens (mobile devices).
How to achieve it in my two-columned website Home Page?
On desktop screen, current side by side display is fine. Only on smaller screen aside block is not coming underneath article block.
#main {
width: 58%;
margin-left: 2%;
float: left;
}
#sidebar {
width: 34%;
margin-left: 4%;`
float: left;
}
Remove the ' in #sidebar
Demo
#sidebar {
width: 34%;
margin-left: 4%;
float: left;
}
#media (max-width:767px){
#main, #sidebar {
width: 100%;
margin: 0 0 20px;
}
}
Try to use #media and width: 100%;:
Here's the JsFiddle link demo.
E.g. small screen size: 767px
#media (max-width: 767px) {
#sidebar,
#main {
width: 100%;
margin-left: 0;
}
}
Hope it helps.

When coding a responsive design is it considered acceptable practice to have multiple markups for the same page elements?

I am coding a responsive design which has several different navigation layouts based on screen resolution (p.s. I have no control over the design decisions where I work).
I am finding it very difficult to achieve the different layouts with just CSS changes alone. But I also don't like the idea of having duplicate markup for the same elements in numerous places as that seems ugly for reasons or maintenance and possible bad impact on SEO (although all but the default will be set to display none on page load).
Anyway What is the thought on this? Is it terribly against good practice to do this?
Yes that is completely fine to do, make sure your keep your media queries at the bottom of you're CSS so those styles will be loaded last and In my opinion the smartest thing you can do is use a grid system with rows and columns and then say when you do your media query you can just display the width of all the columns and 100% which will stack every div you used and then yes for you navigation you'll need to rewrite some elements classes and ids for the media query but use a grid and make the column's width 100% on the mobile version.
Heres a grid simple grid system I build and you can see how I would do my navigation,
/* GRID */
*,*:before,*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.layout-row {
margin: 0 auto;
width: 96em;
zoom: 1;
}
.layout-row .layout-row { width: auto;}
.layout-row:before, .layout-row:after {
display: block;
visibility: hidden;
height: 0;
content: "\0020";
}
.layout-row:after { clear: both;}
.layout-column {
position: relative;
display: inline;
float: left;
padding: 1em ;
}
.layout-column .layout-column { padding: 0;}
.one { width: 8.33333%;}
.two { width: 16.66667%;}
.three { width: 25%;}
.four { width: 33.33333%;}
.five { width: 41.66667%;}
.six { width: 50%;}
.seven { width: 58.33333%;}
.eight { width: 66.66667%;}
.nine { width: 75%;}
.ten { width: 83.33333%;}
.eleven { width: 91.66667%;}
.twelve { width: 100%;}
/* MODULES */
.layout-navigation { margin: -2em 0 0;}
.layout-navigation li {
float: left;
padding: 3em .75em .5em;
text-align: center;
}
/* MOBILE MEDIA QUERY */
#media only screen and (max-width: 480px) {
.layout-row { width: 48em;}
.layout-column { width: 100%;}
.hide-mobile { display: none;}
.layout-navigation li {
float: none;
padding: 1em;
background: #F3F3F3;
text-align: left;
}
}

Resize before switching place?

I have a simple setup like this :
<div id="div0">
<div id="div1">Content</div>
<div id="div2">Content</div>
</div>
The two middle divs(1,2) have width:100% and max-width:390px plus floatLeft. When resizing the browser div2 will jump a row down and when getting less then width 390 thay will both start to resize.
What I need is to resize to a min-width first and then jump down to the second line.
How do I do that?
Edit1 : example : http://jsfiddle.net/dwDZx/
Here's a responsive example of what you're asking about. I changed some widths to make it easier to follow the example and see where the numbers come from. http://jsfiddle.net/dwDZx/4/
I change background colors in the different responsive layouts to show you which section is active at which point in resizing the browser.
The only change I made to the markup was to create a "content" div inside div1 and div2. This allowed me to set a border. If I set width of div1 and div2 to 50% AND set a border, then the total width would be 50%+2px (1px left + 1px right) which would cause the floats to wrap. By putting the border on the content div, it puts the borders inside the 50% instead of outside.
CSS:
* { margin: 0; padding: 0; }
.content { border: 1px solid black; }
#div1, #div2
{
float:left;
}
#media (min-width: 801px)
{
#div1, #div2
{
width: 400px;
background: green;
}
}
#media (min-width: 400px) and (max-width: 800px)
{
#div1, #div2
{
width: 49.9%;
background: red;
}
}
#media (max-width: 399px)
{
#div1, #div2
{
float: none;
width: 100%;
}
}
EDIT: I thought about it and simplified things a bit. See http://jsfiddle.net/dwDZx/5/ The CSS changes as follows: set a max-width on the parent div to be the max width of div1+div2. Then you only need one media state: for when it's < 400px and should be on one line.
CSS:
* { margin: 0; padding: 0; }
.content { border: 1px solid black; }
#container { max-width: 800px; }
#div1, #div2
{
float:left;
width: 50%;
background: green;
}
#media (min-width: 400px) and (max-width: 800px)
{
#div1, #div2
{
background: red;
}
}
#media (max-width: 399px)
{
#div1, #div2
{
float: none;
width: 100%;
background: blue;
}
}