HTML SASS simple grid system placing items incorrectly - css

I'm trying to build a simple grid system using SASS:
app.scss:
.row,
.col {
box-sizing: border-box;
}
.row:before,
.row:after {
content: " ";
display: table;
}
.row:after {
clear: both;
}
.col {
position: relative;
float: left;
}
.col + .col {
margin-left: 1.6%;
}
.col-1 {
width: 6.86666666667%;
}
.col-2 {
width: 15.3333333333%;
}
.col-3 {
width: 23.8%;
}
.col-4 {
width: 32.2666666667%;
}
.col-5 {
width: 40.7333333333%;
}
.col-6 {
width: 49.2%;
}
.col-7 {
width: 57.6666666667%;
}
.col-8 {
width: 66.1333333333%;
}
.col-9 {
width: 74.6%;
}
.col-10 {
width: 83.0666666667%;
}
.col-11 {
width: 91.5333333333%;
}
.col-12 {
width: 100%;
}
#media only screen and (max-width: 550px) {
.col-1,
.col-2,
.col-3,
.col-4,
.col-5,
.col-6,
.col-7,
.col-8,
.col-9,
.col-10,
.col-11,
.col-12 {
width: auto;
float: none;
}
.col + .col {
margin-left: 0;
}
}
// Body
body {
font-family: $default-font;
font-weight: normal;
font-size: 13px;
color: $text-default;
}
.app {
width: auto;
height: 100%;
border-style: outset;
border-width: 1px;
padding: 5px;
}
header-container.scss:
#import '../App/App.scss';
.header-container {
border-style: outset;
border-width: 1px;
border-radius: 5px;
padding: 10px;
}
My HTML:
<header className='header-container'>
<div className='row'>
<div className='col-2'>
<p>Person 1</p>
</div>
<div className='col-2'>
<p>Person 2</p>
</div>
</div>
</header>
Person 1 is appearing above Person 2, not at the side as I expect the grid to work. I cannot find out what's wrong, but I think I'm missing something basic.

You're missing .col on the column elements
.row, .col {
box-sizing: border-box;
}
.row:before, .row:after {
content: " ";
display: table;
}
.row:after {
clear: both;
}
.col {
position: relative;
float: left;
}
.col + .col {
margin-left: 1.6%;
}
.col-1 {
width: 6.86666666667%;
}
.col-2 {
width: 15.3333333333%;
}
.col-3 {
width: 23.8%;
}
.col-4 {
width: 32.2666666667%;
}
.col-5 {
width: 40.7333333333%;
}
.col-6 {
width: 49.2%;
}
.col-7 {
width: 57.6666666667%;
}
.col-8 {
width: 66.1333333333%;
}
.col-9 {
width: 74.6%;
}
.col-10 {
width: 83.0666666667%;
}
.col-11 {
width: 91.5333333333%;
}
.col-12 {
width: 100%;
}
#media only screen and (max-width: 550px) {
.col-1,
.col-2,
.col-3,
.col-4,
.col-5,
.col-6,
.col-7,
.col-8,
.col-9,
.col-10,
.col-11,
.col-12 {
width: auto;
float: none;
}
.col + .col {
margin-left: 0;
}
}
// Body
body {
font-family: $default-font;
font-weight: normal;
font-size: 13px;
color: $text-default;
}
.app {
width: auto;
height: 100%;
border-style: outset;
border-width: 1px;
padding: 5px;
}
.header-container {
border-style: outset;
border-width: 1px;
border-radius: 5px;
padding: 10px;
}
<header class='header-container'>
<div class='row'>
<div class='col col-2'>
<p>Person 1</p>
</div>
<div class='col col-2'>
<p>Person 2</p>
</div>
</div>
</header>

For now, your col-2 class doesn't make your div float:left;
Two possibilities:
You add the class col to your divs
You set all the class starting with col to float:left; You can do it this way: [class^="col"] { float:left; }
Well, I hadn't seen that you are using className and not class, so you can change it accordingly: [className^="col"] { float:left; }

Related

1200px media query to contain content; with background colours remaining 100% width

I am stuck trying to find an appropriate solution; without adding a lot of divs to my markup.
I need the content at the 1200px media query; to stay fixed at 1200 and in the centre. Which is working.
However, the row containers with background colours, shadows etc. to stay 100% of the width.
Any guidance on how best to solve this problem; would be very much appreciated.
* {
box-sizing: border-box; margin: 0; padding: 0;
}
input[type=text] {
font-size: 1.5rem; padding: 0 0.25em 0 1.2em; height: 4rem;
line-height: 4rem; width: 50vw; color: #333;
background: #f5f5f5; border: 1px solid #f5f5f5;
}
.head_sticky {
position: sticky; top: 0; z-index: 100;
}
#media only screen and (max-width: 599px) {
.col-m-1 { width: 16.67%; } .col-m-2 { width: 33.33%; } .col-m-3 { width: 50.00%; }
.col-m-4 { width: 66.67%; } .col-m-5 { width: 83.33%; } .col-m-6 { width: 100%; }
[class*='col-'] {
float: left; padding: 5px 16px 5px 0;
}
.search_form_cls {
height: 4.5rem; line-height: 4.5rem; font-size: 3rem;
color: black; border: none; background: transparent;
}
input[type=text] {
width: 75vw;
}
}
#media only screen and (min-width: 600px) {
.col-t-1 { width: 12.5%; } .col-t-2 { width: 25%; } .col-t-3 { width: 37.5%; }
.col-t-4 { width: 50%; } .col-t-5 { width: 62.5%; } .col-t-6 { width: 75%; }
.col-t-7 { width: 87.5%; } .col-t-8 { width: 100%; }
[class*='col-'] {
float: left; padding: 5px 24px 5px 0;
}
}
#media only screen and (min-width: 768px) {
.col-d-1 { width: 8.33%; } .col-d-2 { width: 16.66%; } .col-d-3 { width: 25% }
.col-d-4 { width: 33.33% } .col-d-5 { width: 41.66% } .col-d-6 { width: 50%; }
.col-d-7 { width: 58.33%; } .col-d-8 { width: 66.66%; } .col-d-9 { width: 75%; }
.col-d-10 { width: 83.33%; } .col-d-11 { width: 91.66% } .col-d-12 { width: 100%; }
[class*='col-'] {
float: left; padding: 5px 28px 5px 0;
}
}
#media only screen and (min-width: 1200px) {
.A3_row {
max-width: 1200px;
margin-left: auto;
margin-right: auto;
}
}
[class*='col-']:first-of-type {
padding-left: 16px;
}
[class*='col-']:last-of-type {
padding-right: 16px;
}
.A3_row {
display: flex; background-color: white;
}
.A3_row [class*='col-'] {
display: flex; align-items: center; flex-wrap: wrap;
}
.A3_row::after {
content: ""; clear: both; display: table;
}
.navigation_link
text-decoration: none; color: black;
}
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Test</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id='head' class='A3_row shadow_bottom head_sticky'>
<div class='col-m-1 col-t-1 col-d-1'>
<span class='navigation_link'>☰</span>
</div>
<div class='col-m-2 col-t-2 col-d-2'>
LOGO
</div>
<div class='col-m-3 col-t-5 col-d-9 t-end'>
<input autocomplete='off' name='q' class='search_form_m' type='text' placeholder='Search' value='' maxlength='100'>
</div>
</div>
<div class='A3_row' style='background-color:blueviolet; font-size: 1.5em; font-weight: bold;'>
<div class='col-m-6 col-t-8 col-d-12'>Heading</div>
</div>
<div class='A3_row' style='background-color:blueviolet;'>
<div class='col-m-6 col-t-8 col-d-12' style="overflow-x: scroll; overflow-y: hidden; width: 100%;">Content</div>
</div>
<div class='A3_row' style='background-color:gold; font-size: 1.5em; font-weight: bold;'>
<div class='col-m-6 col-t-8 col-d-12'>Heading</div>
</div>
<div class='A3_row' style='background-color:gold;'>
<div class='col-m-6 col-t-8 col-d-12' style="overflow-x: scroll; overflow-y: hidden; width: 100%;">Content</div>
</div>
<div class='A3_row' style='background-color:lightseagreen; font-size: 1.5em; font-weight: bold;'>
<div class='col-m-6 col-t-8 col-d-12'>Heading</div>
</div>
<div class='A3_row' style='background-color:lightseagreen;'>
<div class='col-m-6 col-t-8 col-d-12' style="overflow-x: scroll; overflow-y: hidden; width: 100%;">Content</div>
</div>
<div class='A3_row'>
<div class='col-m-6 col-t-8 col-d-12' style='align-items: flex-start'>
<span>FOOTER</span>
</div>
</div>
</body>
</html>
A CSS-only solution using calc():
#media only screen and (min-width: 1200px) {
.A3_row {
width: 100%;
padding-left: calc((100% - 1200px) / 2);
padding-right: calc((100% - 1200px) / 2);
}
}
This width declaration makes the "row" 100% of the width of its containing block while the padding-* declarations ensure the "content" is 1200px.
See calc() (MDN)

Media queries are working on Inspector but not on live site

Custom css (media queries) work for WordPress and inspector but not on live site.
I added the meta viewport tag to the HTML but still it's not working.
/* Media Queries */
/* small phones */
#media (max-width: 320px) {
#intro {
margin-left: 20px;
width: 85%;
}
.logo-image {
position: relative;
}
.logo-img {
display: none;
}
main {
width: 85%;
position: relative;
top: 0px;
}
.card {
width: 85%;
}
.card .card-image img {
width: 100%;
}
footer {
flex-direction: column;
text-align: center;
}
footer #left-footer {
flex: 1;
border-right: 0;
padding-left: 0;
}
footer #right-footer {
background: #eee;
color: black;
}
footer #right-footer a {
color: black;
}
footer #social-media-footer ul li:hover a .fa-instagram {
color: purple;
transition: 0.4s;
}
nav ul {
display: none;
}
#menu-icon {
display: flex;
}
#slideout-menu {
display: block;
text-align: center;
}
#searchbox {
display: none;
}
#blogpost {
width: 100%;
border-left: 0;
}
#sidebar {
display: none;
}
.comment-form {
width: 70%;
}
}
#media (max-width: 320px) {
#slideout-menu {
width: 65%;
}
#logo-img {
display: none;
}
#intro {
width: 95%;
height: 120vw;
}
#intro .logo-image {
width: auto;
height: auto;
max-width: 680px;
max-height: 750px;
position: relative;
right: 18px;
top: 50px;
}
main {
width: 95%;
margin-top: 0px;
}
.card {
width: 95%;
}
.card .card-image img {
width: 100%;
}
.logo-img {
display: none;
}
.card .card-description {
width: 100%
}
}
#media (min-width: 375px) and (max-width: 667px) and (-webkit-min-device-pixel-ratio: 2) {
#nav ul {
display: none;
}
#slideout-menu {
width: 65%;
}
#logo-img {
display: none;
}
#intro {
width: auto;
height: 120vw;
}
#intro .logo-image {
width: auto;
height: auto;
max-width: 800px;
max-height: 750px;
position: relative;
right: 5px;
top: 50px;
}
main {
width: 85%;
margin-top: 0px;
}
.card {
width: 95%;
}
.card .card-image img {
width: 100%;
}
.logo-img {
display: none;
}
.card .card-description {
width: 100%
}
nav ul {
display: none;
}
#menu-icon {
display: flex;
}
#slideout-menu {
display: block;
text-align: center;
}
#searchbox {
display: none;
}
#sidebar {
display: none;
}
#comments-section {
width: 140%;
}
}
#media (min-width: 720px) {
.logo-image {
display: flex;
}
main {
width: 95%;
}
.card {
width: 45%;
}
.card .card-image img {
width: 100%;
}
}
/* Tablet */
#media screen and (min-width: 668px) and (max-width: 768px) {
nav {
font-size: 2vw;
}
#logo-img {
height: auto;
width: auto;
max-width: 680px;
max-height: 750px;
}
#intro {
width: auto;
height: 100vw;
}
#intro .logo-image {
width: auto;
height: auto;
max-width: 1500px;
max-height: 1000px;
position: relative;
right: 10px;
top: 10px;
}
main {
width: 95%;
}
section {
flex-direction: column;
}
.card,
.card .Card Image img {
width: 100%;
}
footer {
flex-direction: column;
text-align: center;
}
footer #left-footer {
flex: 1;
border-right: 0;
padding-left: 0;
}
footer #right-footer {
background: #eee;
color: black;
}
footer #right-footer a {
color: black;
}
footer #social-media-footer ul li:hover a .fa-instagram {
color: purple;
transition: 0.4s;
}
#searchbox {
display: ;
}
}
#media screen and (min-width: 1200px) and (max-width: 1600px) and (-webkit-min-device-pixel-ratio: 1) {
nav ul {
display: flex;
list-style: none;
padding: 0 150px;
justify-content: space-around;
align-items: center;
height: 100%;
margin: 0;
}
#logo-img {
left: 30px
}
.logo-image {
display: flex;
}
main {
width: 95%;
}
.card {
width: 45%;
}
.card .card-image img {
width: 100%;
}
}
/* ----------- Retina Screens ----------- */
#media screen and (min-width: 1200px) and (max-width: 1600px) and (-webkit-min-device-pixel-ratio: 2) and (min-resolution: 192dpi) {
#logo-img {
left: 30px
}
.logo-image {
display: flex;
}
main {
width: 95%;
}
.card {
width: 45%;
}
.card .card-image img {
width: 100%;
}
#logo-img {
height: auto;
width: auto;
max-width: 680px;
max-height: 750px;
}
#intro {
width: auto;
height: 100vw;
}
#intro .logo-image {
width: auto;
height: auto;
max-width: 2500px;
max-height: 1000px;
position: relative;
right: 10px;
top: -200px;
}
main {
width: 95%;
}
section {
flex-direction: column;
}
.card,
.card .Card Image img {
width: 100%;
}
footer {
flex-direction: column;
text-align: center;
}
footer #left-footer {
flex: 1;
border-right: 0;
padding-left: 0;
}
footer #right-footer {
background: #eee;
color: black;
}
footer #right-footer a {
color: black;
}
footer #social-media-footer ul li:hover a .fa-instagram {
color: purple;
transition: 0.4s;
}
#searchbox {
display: ;
}
}
#media screen and (min-width: 1200px) and (max-width: 1600px) and (-webkit-min-device-pixel-ratio: 1) {
nav ul {
display: flex;
list-style: none;
padding: 0 200px;
justify-content: space-around;
align-items: center;
height: 100%;
margin: 0;
}
#logo-img {
left: 30px
}
}
Here is the HTML
">
/img/fuchsifuchs.png" alt="fuchsifuchs.png" class="fuchs-intro"/>
">
Gedichte
'post',
'posts_per_page' => 2,
);
$Gedichteposts = new WP_QUERY($args);
while($Gedichteposts->have_posts()) {
$Gedichteposts->the_post();
?>
">
"
alt="Card Image">
">
" class="btn-readmore"> weiter erkunden
</section>
<a href="<?php echo site_url('/projects'); ?>">
<h2 class="section-heading"> Kurzgeschichten</h2>
<section>
<?php
$args = array(
'post_type' => 'project',
'posts_per_page' => 2,
);
$project = new WP_QUERY($args);
while($project->have_posts()) {
$project->the_post();
?>
<div class="card">
<div class="card-image">
<a href=" <?php echo the_permalink(); ?>">
<img src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>"
alt="Card Image">
</a>
</div>
<div class="card-description">
<a href="<?php the_permalink() ?>">
<h3><?php the_title(); ?></h3>
</a>
<p><?php echo wp_trim_words(get_the_excerpt(), 30); ?>
</p>
weiter erkunden
</div>
</div>
<?php }
wp_reset_query();
?>
</section>
<a href="<?php echo site_url('/about'); ?>">
<h2 class="section-heading"> Das bin ich</h2>
<section id="section-source">
<p>
Wenn Ihr mehr über mich und meine Geschichte erfahren wollt, schaut gerne hier rein. Ich erzähle euch, wie es zu diesem Blog gekommen ist und warum ihr rein schauen solltet.
</p>
Instagram Profil
</section>
A common issue I encounter when trying to write css from the WordPress admin panel is that my css is being overwritten. To solve this, you can try to match the specificity of the already existent css or if you are brave just add "!important" before the ";" of every rule.
Would recommend looking into specificity first, though.

Getting correct grid with Flexbox

Can someone point me out how can I get a grid with Flexbox that is similar to the picture below. I have green column already done but have problem doing red section.
The problem is that I need to have an access to Flex Order just re-order it on mobile resolutions.
What I have already:
JSFiddle
HTML
* {
box-sizing: border-box;
}
main,
div {
display: flex;
padding: 1rem;
}
.desktop {
flex-direction: column;
flex-wrap: wrap;
height: 400px;
width: 100%;
}
.desktop div {
flex: 1;
}
div.orange {
background-color: #FFAD77;
width: 30%;
flex: 0 0 50%;
}
div.yellow {
flex: 0 0 100%;
width: 40%;
background-color: #FFE377;
}
div.purple {
flex: 0 0 50%;
width: 30%;
background-color: #FF77C8;
}
div.green {
background-color: green;
width: 30%;
}
#media(max-width: 480px) {
.desktop div {
flex: 1;
width: 100%;
}
div.orange {
order: 1;
}
div.yellow {
order: 2;
}
div.purple {
order: 3;
}
div.green {
order: 2;
}
}
<div class="desktop">
<div class="yellow">lorem1</div>
<div class="orange">lorem2</div>
<div class="purple">lorem3</div>
<div class="green">lorem4</div>
</div>
Please adjust the width, remove border and other things are per your requirement.
.redouter {
height: 200px;
border: 1px solid green;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.red {
background: red;
width: 50%;
min-height: 20px;
text-align: center;
color: white;
font-size: 30px;
}
.one {
border: 2px solid white;
}
.two {
border: 5px solid white;
min-height: 150px;
}
.three {
min-height: 144px;
border: 3px solid white;
}
.four {
min-height: 10px;
border: 3px solid white;
}
#media(max-width: 480px) {
.redouter {
height: 100%;
}
.red {
flex: 1;
width: 100%;
}
.one {
order: 1;
}
.two {
order: 2;
}
.three {
order: 3;
}
.four {
order: 2;
}
}
.desktop {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 300px;
width: 100%;
}
.yellow,
.green,
.purple,
.orange {
flex: 1;
}
div.orange {
background-color: #FFAD77;
width: 30%;
flex: 0 0 50%;
}
div.yellow {
flex: 0 0 100%;
width: 40%;
background-color: #FFE377;
}
div.purple {
flex: 0 0 50%;
width: 30%;
background-color: #FF77C8;
}
div.green {
background-color: green;
width: 30%;
}
#media(max-width: 480px) {
.desktop div {
flex: 1;
width: 100%;
}
div[orange] {
order: -1;
flex: 2;
}
div[yellow] {
flex: 5;
}
div[purple] {
flex: 1;
}
div[purple] {
flex: 6;
}
}
<div class="desktop">
<div class="yellow">lorem 1</div>
<div class="orange">lorem 2</div>
<div class="purple">lorem 3</div>
<div class="green">lorem 4</div>
</div>
<div class="redouter">
<div class="red one">1</div>
<div class="red two">2</div>
<div class="red three">3</div>
<div class="red four">4</div>
</div>

Bootstrap grid is not working [duplicate]

This question already has an answer here:
Bootstrap 3 mixin multiple make-*-column
(1 answer)
Closed 8 years ago.
I am trying to create a page layout using bootstrap. My layout something similar to below image.
To archive for this I tried using bootstrap grid fuctions.
This is how my html look like
<div class="myLayout">
<div class="col-1">
</div>
<div class="col-2">
</div>
<div class="col-3">
</div>
</div>
In my less file
.myLayout {
.make-row();
.col-1 {
.make-md-column(6);
.make-sm-column(7);
.make-xs-column(12);
background: black;
height: 100px;
}
.col-2 {
.make-md-column(3);
.make-sm-column(5);
.make-xs-column(6);
background: blue;
height: 100px;
}
.col-3 {
.make-md-column(3);
.make-sm-column(0);
.make-xs-column(6);
.visible-lg-block;
background: red;
height: 100px;
}
}
UPDATE:
This is generating CSS from about Less
.col-1 {
position: relative;
float: left;
width: 100%;
min-height: 1px;
padding-left: 15px;
padding-right: 15px;
background: black;
height: 100px;
}
#media (min-width: 992px) {
.col-1 {
float: left;
width: 50%;
}
}
#media (min-width: 768px) {
.col-1 {
float: left;
width: 58.33333333%;
}
}
#media (min-width: 1200px) {
.col-1 {
height: 292px;
}
}
.col-2 {
position: relative;
float: left;
width: 50%;
min-height: 1px;
padding-left: 15px;
padding-right: 15px;
background: blue;
height: 100px;
}
#media (min-width: 992px) {
.col-2 {
float: left;
width: 25%;
}
}
#media (min-width: 768px) {
.col-2 {
float: left;
width: 41.66666667%;
}
}
#media (min-width: 1200px) {
.col-2 {
height: 292px;
}
}
.col-3 {
position: relative;
float: left;
width: 50%;
min-height: 1px;
padding-left: 15px;
padding-right: 15px;
display: none !important;
background: red;
height: 100px;
}
#media (min-width: 992px) {
.col-3 {
float: left;
width: 25%;
}
}
#media (min-width: 768px) {
.col-3 {
float: left;
width: 0%;
}
}
#media (min-width: 1200px) {
.col-3 {
display: block !important;
}
}
But this is not working for my expecting result. Can somebody tell me what is wrong in my code?
Thank you.
There shouldn't be any need for custom CSS/LESS code to make this happen. You can do it with the existing Bootstrap grid system classes.
BOOTPLY
div {
height: 200px;
}
.first {
background-color: black;
}
.second {
background-color: blue;
}
.third {
background-color: red;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="first col-sm-6 col-xs-12"></div>
<div class="second col-lg-3 col-sm-6 col-xs-12"></div>
<div class="third col-lg-3 visible-lg-inline"></div>

CSS Grid Style With Picture

http://imgur.com/IAHUR4U
I need to style a grid like above. The only thing I have a problem with is the 2 boxes on top of each other within the same row. Has anyone any suggestions on how to do this ?
Cheers!
css:
{ -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
.row { width: 1000px; max-width: 100%; min-width: 768px; margin: 0 auto; }
.row .row { width: auto; max-width: none; min-width: 0; margin: 0 -15px; }
.column, .columns { float: left; min-height: 1px; padding: 0 15px; position: relative; }
[class*="column"] + [class*="column"]:last-child { float: right; }
[class*="column"] + [class*="column"].end { float: left; }
.row .one { width: 8.33% }
.row .two { width: 16.66% }
.row .three { width: 25% }
.row .four { width: 33.33% }
.row .five { width: 41.66% }
.row .six { width: 50% }
.row .seven { width: 58.33% }
.row .eight { width: 66.66% }
.row .nine { width: 75% }
.row .ten { width: 83.33% }
.row .eleven { width: 91.66% }
.row .twelve { width: 100% }
.row:before, .row:after, .clearfix:before, .clearfix:after { content:""; display:table; }
.row:after, .clearfix:after { clear: both; }
.row, .clearfix { zoom: 1; }
HTML:
<div class="row">
<div class="three columns">
...
</div>
<div class="nine columns">
...
</div>
</div>
<div class="row">
<div class="six columns">
...
</div>
<div class="six columns">
this is the div i need to split up into 2 divs on top of eachother
</div>
</div>
I would use float:right, and clear:right on the one on the bottom.

Resources