Having trouble with my responsive layout. My twelve columns blocks are not on one row the last two float under it but should be all in one line.
Each row will be having its own column blocks.
You can get full code view of what I mean at my codepen snippet.
http://codepen.io/riwakawebsitedesigns/pen/zbmLE
.container {
display: block;
width: 94%;
max-width: 1280px;
margin: 2% auto 0 auto;
}
.row {
display: block;
}
.row:after {
content: "";
display: table;
clear: both;
}
.column {
background: #e5e5e5;
min-height: 40px;
text-align: center;
float: left;
margin-right: 20px;
}
.block-1 {
width: 8.33333333%;
}
.block-2 {
width: 16.66666667%;
}
.block-3 {
width: 25%;
}
.block-4 {
width: 33.33333333%;
}
.block-5 {
width: 41.66666667%;
}
.block-6 {
width: 50%;
}
.block-7 {
width: 58.33333333%;
}
.block-8 {
width: 66.66666667%;
}
.block-9 {
width: 75%;
}
.block-10 {
width: 83.33333333%;
}
.block-11 {
width: 91.66666667%;
}
.block-12 {
width: 100%;
}
.last, .omega, .end{
margin: 0;
}
Remove the margin on the columns:
.column {
background: #e5e5e5;
min-height: 40px;
text-align: center;
float: left;
margin-right: 20px; <!-- remove -->
}
Instead of the reaching 100% width the margin is causing less width for them due to the 20px x 12. So your getting 100% + 240px, this is causing the last 2 to move below.
DEMO HERE
Ruddy is right, you are not considering the gutter between columns. Do his way or...
SIMPLE SOLUTION:
Try to subtract 2% from each block class, worked here.
FANCY SOLUTION:
If you use LESS you can work with variables, so you could do something like this:
/*LESS FILE*/
#gutter: "20px";
.block1 {
width: (8.333% - #gutter);
}
Hope it helps.
Related
I have a page with a simple 2 column CSS table inside a general container div, like so:
#container:after {
content: "";
display: table;
clear: both;
}
#col_1 {
float: left;
width: 50%;
padding-right: 20px;
}
#col_2 {
width: 50%;
}
It works correctly on computers but on mobile the two columns overlap/overlay and I would like col2 to go underneath col1. In other words float ONLY if there is room for both, otherwise become two rows.
How can I do that?
Thank you
Since I don't have your HTML code, I can only do a mock-up by myself. Add media query for breakpoint for the mobile device.
html,
body,
#container {
width: 100%;
margin: 0;
}
#container:after {
content: "";
display: table;
clear: both;
}
#col_1 {
float: left;
width: 50%;
height: 100px;
padding-right: 20px;
background: orange;
}
#col_2 {
float: left;
width: calc(50% - 20px); /* The 20px is the padding-right of the col_1 */
height: 100px;
background: lime;
}
#media screen and (max-width: 576px) {
#col_1 {
width: 100%;
}
#col_2 {
width: 100%;
}
}
<div id="container">
<div id="col_1"></div>
<div id="col_2"></div>
</div>
I'd like to know why my code is adding this almost ghost margin of 10px? No matter what I do the .wrapper and everything in it seems to ignore the right -10px of margin???
***I first forgot to mention that the whole thing is border-box
Here's the code:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.container{
position: relative;
width: 90%;
margin: 0 auto;
padding: 0 10px;
}
.wrapper{
width:100%;
max-width: none;
margin-left: -10px;
margin-right: -10px;
}
.col-m1, .col-m2, .col-m3,
.col-m4, .col-m5, .col-m6,
.col-m7, .col-m8, .col-m9,
.col-m10, .col-m11, .col-m12,
.col-l1, .col-l2, .col-l3,
.col-l4, .col-l5, .col-l6,
.col-l7, .col-l8, .col-l9,
.col-l10, .col-l11, .col-l12,
.col-xl1, .col-xl2, .col-xl3,
.col-xl4, .col-xl5, .col-xl6,
.col-xl7, .col-xl8, .col-xl9,
.col-xl10, .col-xl11, .col-xl12 {
width: 100%;
position: relative;
float: left;
padding:0 10px;
}
#media (min-width: 768px) {
.container {
width: 720px;
}
.col-m1, .col-l1, .col-xl1 { width: 8.333%; }
.col-m2, .col-l2, .col-xl2 { width: 16.666%; }
.col-m3, .col-l3, .col-xl3 { width: 24.999%; }
.col-m4, .col-l4, .col-xl4 { width: 33.333%; }
.col-m5, .col-l5, .col-xl5 { width: 41.666%; }
.col-m6, .col-l6, .col-xl6 { width: 49.999%; }
.col-m7, .col-l7, .col-xl7 { width: 58.333%; }
.col-m8, .col-l8, .col-xl8 { width: 66.666%; }
.col-m9, .col-l9, .col-xl9 { width: 74.999%; }
.col-m10, .col-l10, .col-xl10 { width: 83.333%; }
.col-m11, .col-l11, .col-xl11 { width: 91.666%; }
.col-m12, .col-l12, .col-xl12 { width: 100%; }
.offset-col-m1 { margin-left: 8.333%; }
.offset-col-m2 { margin-left: 16.666%; }
.offset-col-m3 { margin-left: 24.999%; }
.offset-col-m4 { margin-left: 33.333%; }
.offset-col-m5 { margin-left: 41.666%; }
.offset-col-m6 { margin-left: 49.999%; }
.offset-col-m7 { margin-left: 58.333%; }
.offset-col-m8 { margin-left: 66.666%; }
.offset-col-m9 { margin-left: 74.999%; }
.offset-col-m10 { margin-left: 83.333%; }
.offset-col-m11 { margin-left: 91.666%; }
}
THE HTML
Some HTML markup for the site. This is specifically the image grid on the homepage. But the whole site has this problem.
This is an image of the non-extension/extra margin on the right side. Very annoying and I just don't understand.
Remove width: 100% of the wrapper class.
I'm working on a layout with 100% height sections and have been struggling to make this sections expand with the content when necessary.
I've tried height: auto; min-height: 100%; but it doesn't work.
Here's a FIDDLE
Use
.wrapper {
height: 100vh; /* vh instead of % */
}
For some reason - which I have no time to investigate further at this point - this solves it only if I reduce your markup to the relevant minimum, see the fiddle:
https://jsfiddle.net/jt49a064/6/
This should serve you as a starting point to fix it yourself now.
try this in your css
display:inline-block;
does this work for you??to change it itself you need to use auto instead of %
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
color: white;
}
.wrapper {
width:auto;
height: auto;
background: SkyBlue;
}
.container {
width: auto;
height: auto;
background: green;
}
.table {
display: table;
width: auto;
height: auto;
}
.row {
display: table-row;
width: auto;
}
.cell1, .cell2, .cell3 {
display: table-cell;
width: 33%;
}
.cell1 {
background: blue;
}
.cell2 {
background: red;
}
.cell3 {
background: LightSalmon;
}
You can use display: table; and table-row for you containers :
In the CSS for the parent write this :
display: parent;
For the children :
display: table-row;
My website uses a Foundation Front-end framework for my website, so it's a responsive design for mobile devices.
I have an issue, with how the data is displayed on my website when used on a mobile.
I would like the sidebar widget contents on my website to display above the items (health clubs) on the mobile version of the website. See my sidebar widget has a filter section, So I really need that displayed before the (health clubs).
Question: What do I need to change to display the sidebar widget on top? Apologises I'm ok at CSS but this is pretty advanced for my skill level.
Here is the website: (PC version)
http://s10.postimg.org/cl1n43w95/website.png
Here is how the website is displayed on the mobile. Note How my items are all above the sidebar. I'd like the sidebar widget above the items:
http://s27.postimg.org/8adw402gz/screenshot2_sidebarunder_items.png
Here is the foundation code I believe I need to change:
/* #Foundation Style
================================================== */
.row .column, .row .columns{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
.container{ margin: 0px auto; max-width: 960px; padding: 0px 20px; }
.container.wrapper{ margin: 0px auto; max-width: 1000px; padding: 0px; }
.row { width: 1140px; max-width: 100%; min-width: 727px; margin: 0 auto; }
.row .row { width: auto; max-width: none; min-width: 0; margin: 0 -10px; }
.column, .columns { float: left; min-height: 1px; padding: 0 10px; position: relative; margin-bottom: -12px; }
.row .one { width: 8.333%; }
.row .two { width: 16.667%; }
.row .three { width: 25%; }
.row .four { width: 33.333%; }
.row .five { width: 41.667%; }
.row .six { width: 50%; }
.row .seven { width: 58.333%; }
.row .eight { width: 66.667%; }
.row .nine { width: 75%; }
.row .ten { width: 83.333%; }
.row .eleven { width: 91.667%; }
.row .twelve { width: 100%; }
.row .one-fifth{ width: 20%; }
.row .one-sixth{ width: 16.667; }
img{ max-width: 100%; height: auto; }
img { -ms-interpolation-mode: bicubic; }
object, embed { max-width: 100%; }
/* #Foundation Mobile Size
================================================== */
#media only screen and (max-width: 767px) {
body { -webkit-text-size-adjust: none; -ms-text-size-adjust: none;
width: 100%; min-width: 0; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
.container{ margin: 0px auto; max-width: 420px; }
.container.wrapper{ margin: 0px auto; max-width: 460px; padding: 0px; }
.row { width: auto; min-width: 0; margin-left: 0; margin-right: 0; }
.row .column, .row .columns { width: 100%; float: none; }
.column:last-child, .columns:last-child { float: none; }
[class*="column"] + [class*="column"]:last-child { float: none; }
.column:before, .columns:before, .column:after, .columns:after { content: ""; display: table; }
.column:after, .columns:after { clear: both; }
}
/* #Custom Style
================================================== */
/*--- header area ---*/
.header-wrapper .responsive-menu-wrapper{ display: none; }
/* #Custom Mobile size
================================================== */
#media only screen and (max-width: 767px) {
/*--- header area ---*/
.header-wrapper .logo-wrapper{ float: none; }
.header-wrapper .navigation-wrapper{ display: none; }
.header-wrapper .responsive-menu-wrapper{ display: block; }
.header-wrapper .top-search-form{ display: none; }
div.logo-right-text{ float: none !important; text-align: center !important;
padding-top: 0px !important; padding-bottom: 20px; }
div.feedback-wrapper{ display: none; }
div.top-navigation-left, div.top-navigation-right{ text-align: center; float: none; }
div.social-wrapper { float: none; display: inline-block; margin-top: 5px; }
/*--- single page ---*/
div.single-portfolio .port-media-wrapper { max-width: 100%; width: 100%; float: none; margin-bottom: 20px; }
div.single-portfolio .port-content-wrapper { overflow: visible; }
div.single-portfolio .port-nav .port-prev-nav, div.single-portfolio .port-nav .port-next- nav { margin-bottom: 15px; }
/*--- page item ---*/
div.gdl-blog-medium .blog-media-wrapper { margin-right: 0px; width: 100%; }
div.gdl-blog-medium .blog-context-wrapper { overflow: visible; }
div.price-item{ margin-bottom: 20px; }
div.column-service-row{ border-left-width: 0px; }
/*--- shortcode ---*/
.shortcode1-4, .shortcode1-4.last,
.shortcode1-3, .shortcode1-3.last,
.shortcode1-2, .shortcode1-2.last,
.shortcode2-3, .shortcode2-3.last,
.shortcode3-4, .shortcode3-4.last,
.shortcode1-5, .shortcode1-5.last,
.shortcode2-5, .shortcode2-5.last,
.shortcode3-5, .shortcode3-5.last,
.shortcode4-5, .shortcode4-5.last{ width: 100%; }
/*--- slider ---*/
.flex-caption{ display: none !important; }
.nivo-caption{ display: none !important; }
.anythingSlider{ display: none !important; }
/*--- footer ---*/
div.copyright-left, div.copyright-right{ float: none; text-align: center; }
}
Thanks Guys, Sorry if i'm not very clear.
With the foundation grid you can change the order of columns, which is probably what you are looking for.
http://foundation.zurb.com/docs/components/grid.html
Look for "Source Ordering"
That should guide you on the right path. Otherwise it would be helpful if you post the relevant markup.
second attempt
If you look at the source of your second page http://goo.gl/ijZ1JF you find three elements:
<div class="row single page"> ...
<div class="eight column columnopaddingright"> ...
<div class="four column columnopaddingleft"> ...
Do you get the desired result if you modify them for testing purpose like this?
<div class="row single page" style="display: table;">
<div class="eight column columnopaddingright" style="display: table-footer-group;">
<div class="four column columnopaddingleft" style="display: table-header-group;">
Have a class for the page, a container class for rows of div-boxes, and box class to style all of the boxes..
The rows of div-boxes need to be centered on the page..
What combination of width + display + margin is required (cross-browser)?
The boxes are floating-left, which seems to be the origin of the question..
Current CSS:
.page {
width: 100%;
}
.container {
width: 100%;
display: block;
margin: 0 auto;
}
.box {
float: left;
margin: %;
}
You'd want to use display:inline-block in your boxes, effectively treating them like text and then set text-align:center in your container
.container {
width: 100%;
display: block;
margin: 0 auto;
text-align: center;
}
.box {
display: inline-block;
width: 200px;
height: 200px;
background: grey;
}
Demo fiddle
I made a jsFiddle. Its fixed width. my question is how many .box elements will there be?
if its dynamic then use some javascript to work out the widths of '.box'
http://jsfiddle.net/james_nicholson/4P9s8/10/
.page {
width: 100%;
border:1px solid black;
height:auto;
}
.container {
width: 440px;
display: block;
margin: 0 auto;
background:blue;
min-height:500px;
}
.box {
float: left;
width: 100px;
background: red;
margin: 5px;
display: block;
height: 100px;
}