Vuejs nested post and comment unwanted model binding - ruby-on-rails

In my vuejs code, i am fetching data from a Rails Api, which works fine for the post, i can create a new post but when i want to post a comment and i type in one input field, it types on every other field, i'm a beginner, please help, i don't really know how to phrase a question. Here's the code
<template>
<div class="home">
<div class="panel panel-default panel-shadow">
<div class="panel-body">
<form class="form-group" #submit.prevent="postGossip" style="margin: 10px;">
<textarea class="font-control" v-model="micropost.body" placeholder="What's Happening ?" style="padding: 10px;" rows="5"></textarea>
<span style="color:red">{{ errors.body }}</span>
<button class="btn btn-danger text-right pull-right">Post</button>
</form>
</div>
</div>
<div class="panel panel-white post panel-shadow" v-for="post in microposts" transition="item">
<div class="post-heading">
<div class="pull-left image">
<img src="http://bootdey.com/img/Content/user_1.jpg" class="img-circle avatar" alt="user profile image">
</div>
<div class="pull-left meta">
<div class="title h5">
<b>Anonymous</b>
</div>
<h6 class="text-muted time">{{ getHumanDate(post.created_at) }}</h6>
</div>
</div>
<div class="post-description">
<p>{{post.body}}</p>
<div class="stats">
<div v-on:click="isShow = !isShow" class="text-right">
Comments {{post.comments.length}}
</div>
</div>
</div>
<div class="post-footer" v-show="isShow">
<div class="input-group">
<input class="form-control" placeholder="Add a comment" type="text" v-model="comment.body">
<span class="input-group-addon">
<button class="btn btn-primary" #click="postComment">Post</button>
</span>
</div>
<ul class="comments-list" v-for="comment in post.comments">
<li class="comment">
<a class="pull-left" href="#">
<img class="avatar" src="http://bootdey.com/img/Content/user_1.jpg" alt="avatar">
</a>
<div class="comment-body">
<div class="comment-heading">
<h5 class="time">{{ getHumanDate(comment.created_at) }}</h5>
</div>
<p>{{comment.body}}</p>
</div>
</li>
</ul>
</div>
</div>
</div>
</template>
<script>
import moment from 'moment'
export default {
name: 'home',
data () {
return {
micropost: {
body: ''
},
errors: {},
microposts: [],
comment: {
micropost_id: '',
body: ''
},
isShow: false
}
},
methods: {
postGossip: function () {
let self = this
this.axios.post('http://localhost:3000/api/v1/microposts', {
micropost: self.micropost
}).then(function (response) {
self.errors = {}
self.microposts.unshift(response.data)
self.micropost.body = ''
}).catch(function (response) {
console.log(response)
self.errors = 'response.data.error'
})
},
getPosts: function () {
let self = this
this.axios.get('http://localhost:3000/api/v1/microposts').then(function (response) {
self.microposts = response.data
}).catch(function (errors) {
console.log(errors)
})
},
postComment: function () {
console.log(self.comment)
},
getHumanDate: function (date) {
// return moment(date, 'YYYY-MM-DD').format('DD/MM/YYYY')
return moment(date).fromNow()
}
},
mounted () {
this.getPosts()
}
}
</script>
<style>
body{
background-image: url('../assets/background.png');
}
.panel-shadow {
box-shadow: rgba(0, 0, 0, 0.1) 3px 3px 3px;
}
.panel-white {
border: 1px solid #dddddd;
}
.panel-white .panel-heading {
color: #333;
background-color: #fff;
border-color: #ddd;
}
.panel-white .panel-footer {
background-color: #fff;
border-color: #ddd;
}
.input-group-addon{
background-color: transparent !important;
}
.post .post-heading {
height: 95px;
padding: 20px 15px;
}
.post .post-heading .avatar {
width: 60px;
height: 60px;
display: block;
margin-right: 15px;
}
.post .post-heading .meta .title {
margin-bottom: 0;
}
.post .post-heading .meta .title a {
color: black;
}
.post .post-heading .meta .title a:hover {
color: #aaaaaa;
}
.post .post-heading .meta .time {
margin-top: 8px;
color: #999;
}
.post .post-image .image {
width: 100%;
height: auto;
}
.post .post-description {
margin: 15px;
}
.post .post-description .stats {
margin-top: 20px;
}
.post .post-description .stats .stat-item {
display: inline-block;
margin-right: 15px;
}
.post .post-description .stats .stat-item .icon {
margin-right: 8px;
}
.post .post-footer {
border-top: 1px solid #ddd;
padding: 15px;
}
.post .post-footer .comments-list {
padding: 0;
margin-top: 20px;
list-style-type: none;
}
.post .post-footer .comments-list .comment {
display: block;
width: 100%;
margin: 20px 0;
}
.post .post-footer .comments-list .comment .avatar {
width: 35px;
height: 35px;
}
.post .post-footer .comments-list .comment .comment-heading {
display: block;
width: 100%;
}
.post .post-footer .comments-list .comment .comment-heading .user {
font-size: 14px;
font-weight: bold;
display: inline;
margin-top: 0;
margin-right: 10px;
}
.post .post-footer .comments-list .comment .comment-heading .time {
font-size: 12px;
color: #aaa;
margin-top: 0;
display: inline;
}
.post .post-footer .comments-list .comment .comment-body {
margin-left: 50px;
}
.post .post-footer .comments-list .comment > .comments-list {
margin-left: 50px;
}
.item {
box-sizing: border-box;
background-color: #eee;
border: 1px solid black;
display: inline-block;
width: 100px;
height: 100px;
}
.item-enter {
opacity: 0; /* the state right after enter (enter from this state) */
}
.item-leave {
opacity: 0; /* the state right before leave (leave to this state) */
}
.item-enter-active, .item-leave-active {
transition: opacity .5s ease; /* applied during enter/leave transition */
}
.item-move {
border-color: red;
transition: transform .5s cubic-bezier(.55,0,.1,1); /* applied during moving transition */
}
</style>
And this is what happens:
1
It writes on every comment box insert of just one, any help would be greatly appreciated

This is happening because the object post, that you get from the API returns many comments. Than in your iterator v-for=comment in post.comments you call the iteratee defined in your object locally as comment, what causes a "collision" with the object your defined in your component data.
As post is also a iteratee of microposts you should add the newly created object to microposts. Try the following.
change the iteratee name v-for='comment in post.comments' to c. Of course change the references also in
<div class="comment-body">
<div class="comment-heading">
<h5 class="time">{{ getHumanDate(c.created_at) }}</h5>
</div>
<p>{{c.body}}</p>
</div>
Then your postComment method you can clone the object | clone an object
<button class="btn btn-primary" #click="postComment(post)">Post</button>
Define the method
postComment: function (post) {
post.comments.push({body: this.comment.body});
}
Remember that if a comment has other fields, you need to set them before appending to the parent object post

Related

jquery draggable issue can't drag in any empty parent div

I am working on nested parent and child list item.
Here is demo link https://jsfiddle.net/fahadsheikh/kq5oxbrs/2/
The sortable and draggable working fine but when if one of parent div is empty than draggle not working.
$(document).ready(function() {
// Sort the parents
$(".sortMenu").sortable({
containment: "document",
items: "> div",
tolerance: "pointer",
cursor: "move",
opacity: 0.7,
revert: 300,
delay: 150,
placeholder: "menuPlaceholder",
start: function(e, ui) {
ui.placeholder.height(ui.helper.outerHeight());
}
});
// Sort the children
$(".menuItems").sortable({
items: "> div",
tolerance: "pointer",
containment: "document",
connectWith: '.menuItems'
});
});
$('#btn1').click(function() {
getSortableList('.sortMenu');
})
$('#btn2').click(function() {
getSortableList('.menuItems');
})
function getSortableList(className){
var sortables = $(className);
var myArray = new Array();
sortables.each(function() {
myArray = myArray.concat($(this).sortable('toArray'));
})
alert(myArray.length);
}
.menuGroup {
margin: 10px;
padding: 10px;
border: 1px solid #000000;
}
.menuGroup h2 {
margin: 0;
padding: 0px 0px 20px 0px;
}
.menuItems {}
.menuItem {
margin: 5px;
padding: 10px;
margin-left: 50px;
border: 1px solid #000000;
background-color: #cecece;
}
.menuPlaceholder {
width: 100%x;
height: 50px;
padding: 20px;
display: block;
margin: 0 0 15px 0;
background: #cccccc;
border: 1px dashed #000000;
}
<script src="https://code.jquery.com/jquery-3.2.1.min.js">
</script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<button id="btn1">get sortMenu </button>
<button id="btn2">get menuItems </button>
<div class="sortMenu">
<div class="menuGroup">
<h2>Parent #1</h2>
<div class="menuItems">
<div class="menuItem">
Child 1.1
</div>
<div class="menuItem">
Child 1.2
</div>
<div class="menuItem">
Child 1.3
</div>
<div class="menuItem">
Child 1.4
</div>
</div>
</div>
<div class="menuGroup">
<h2>Parent #2</h2>
<div class="menuItems">
<div class="menuItem">
Child 2.1
</div>
<div class="menuItem">
Child 2.2
</div>
</div>
</div>
</div>
This is a known bug.
Applying min-height should fix the issue
Add the following css
<style>
.menuItems {
min-height: 100px;
background: yellow; // optional
}
</style>

ruby on rails create loop inside onclick

How can I make a loop inside currentSlide(1) so I want everytime .each work to add currentSlide(1) then currentSlide(2) then currentSlide(3) and so on.
<div class="approach" id="app">
<style>
#media (max-width: 600px){
.btn {
padding: 2px 2px 2px 2px !important; */
}}
#myBtnContainer{
display: flex;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
display: none;
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 282px;
}
.column:hover{
border: 1px solid #777;
}
/* Clear floats after rows */
.row:after {
content: "";
display: table;
clear: both;
}
/* Content */
.content {
width: 100%;
height: 400px;
overflow: hidden;
/*display: flex;*/
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
}
.content img{
object-fit: cover;
height: auto;
width: 100%;
position: absolute;
}
/* The "show" class is added to the filtered elements */
.show {
display: block;
}
/* Style the buttons */
.btn {
border: none;
outline: none;
padding: 10px 10px;
background-color: #333333;
cursor: pointer;
color: white;
}
.btn:hover {
background-color: #ddd;
}
.btn.active {
background-color: #666;
color: white;
}
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: black;
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
width: 90%;
max-width: 500px;
}
/* The Close Button */
.close {
color: white !important;
position: absolute;
top: 170px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}
.mySlides {
display: none;
}
.cursor {
cursor: pointer
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
img {
margin-bottom: -4px;
}
.caption-container {
text-align: center;
background-color: black;
padding: 2px 16px;
color: white;
}
.demo {
opacity: 0.6;
}
.active,
.demo:hover {
opacity: 1;
}
img.hover-shadow {
transition: 0.3s
}
.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}
.mySlides img{
padding-top: 70px;
background-color: black;
}
div.desc {
padding: 15px;
text-align: center;
}
#media (max-width:600px) {
.close {
color: white !important;
position: absolute;
top: 120px;
right: 25px;
font-size: 45px;
font-weight: bold;
z-index: 1000;
}
.column {
float: left;
display: none;
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 83px;
}
}
#media (max-width: 320px){
.column {
float: left;
display: none;
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 70px;
}
}
#media only screen and (min-width: 812px) {
.column {
float: left;
display: none;
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 90px;
} }
</style>
<body>
<!-- MAIN (Center website) -->
<div class="container">
<h1>GALLERY</h1>
<div id="myBtnContainer">
<button class="btn" onclick="filterSelection('conversion')"> Conversion</button>
<button class="btn" onclick="filterSelection('fixed-hybrid')"> Fixed Hybrid</button>
<button class="btn" onclick="filterSelection('removal-bar-over-denture')"> Removable Bar Over Denture</button>
<button class="btn" onclick="filterSelection('surgical-guides')"> Surgical Guides</button>
<button class="btn active" onclick="filterSelection('all')"> Show all</button>
</div>
<br>
<!-- Portfolio Gallery Grid -->
<div class="row">
<% #galleries.each do |g| %>
<% [g.image1, g.image2, g.image3, g.image4, g.image5].compact.each_with_index do |image, index| %>
<div class="column <%= g.product_name %>">
<div class="content">
<%= image_tag image.url, style: "width:100%", onclick: "openModal();currentSlide(#{index + 1})" ,class: "hover-shadow cursor"%>
</div>
</div>
<% end %>
<% end %>
<!-- END GRID -->
</div>
<!-- END MAIN -->
</div>
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<% #galleries.each do |g| %>
<% [g.image1, g.image2, g.image3, g.image4, g.image5].compact.each_with_index do |image, index| %>
<div class="mySlides">
<div class="numbertext">1 / 4</div>
<%= image_tag image.url, style: "width:100%" %>
</div>
<% end %>
<% end %>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<div class="caption-container">
<p id="caption">hr</p>
</div>
</div>
<script>
filterSelection("all")
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("column");
if (c == "all") c = "";
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i], "show");
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
}
}
function w3AddClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
}
}
function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}
// Add active class to the current button (highlight it)
var btnContainer = document.getElementById("myBtnContainer");
var btns = btnContainer.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function(){
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}
</script>
</div>
<script>
function openModal() {
document.getElementById('myModal').style.display = "block";
}
function closeModal() {
document.getElementById('myModal').style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
var captionText = document.getElementById("caption");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>
Looks like you just need an index to interpolate into currentSlide.
Start by removing duplication and instead of checking every related image with <% if g.image1.present? %> put them into an array and iterate over it with:
<% [g.image1, g.image2, g.image3].compact.each_with_index do |image, index|
compact will make sure that only present images are there, so you don't have to use if present any more.
And then use onclick: "openModal();currentSlide(#{index + 1})" (as index starts at 0, and you seem to need it to start from 1)
Update:
<% #galleries.each do |g| %>
<% [g.image1, g.image2, g.image3, g.image4, g.image5].compact.each_with_index do |image, index| %>
<div class="column <%= g.product_name %>">
<div class="content">
<%= image_tag image.url,
alt: "conversion",
style: "width:100%",
onclick: "openModal();currentSlide(#{index + 1})",
class: "hover-shadow cursor" %>
</div>
</div>

Random Gap in Row of 3 Columns

Here is what I mean, as you can see there is a gap in the second row and the missing panel is shuffled down to a fourth row that shouldn't exist. It makes no sense. I'm using Bootstrap 3 if that helps at all. Let me know if you guys need anything else.
Here is my html: app\views\blog_posts\index.html.erb and scss: app\assets\stylesheets\blog_posts.scss
.banner {
font-family: 'Pacifico', cursive;
color: white;
text-shadow: 1px 1px 8px $myw-pink;
font-size: 80px;
text-align: center;
margin: 50px 0 40px 0;
}
.panel, .panel-default {
.panel-blog-post {
.panel-heading {
padding: 0px;
p {
font-family: 'Pacifico', cursive;
font-size: 30px;
text-shadow: 2px 2px 2px black;
text-align: center;
padding: 15px;
position: absolute;
}
img {
width: 100%;
border-radius: 2px 2px 0 0;
// .blog-pic-style {
// &:hover {
// filter: brightness(200%);
// transition: ease 1s;
// }
// }
}
}
}
.panel-body {
img {
border-radius: 100%;
}
}
}
.navbar {
margin-bottom: 40px;
background-color: $myw-pink;
border: none;
.navbar-header {
margin: 0 50px 0 50px;
button {
border-width: 2px;
border-color: white;
&:hover {
background-color: $myw-blue;
transition: ease .25s;
}
&:focus {
background-color: $myw-blue;
}
.icon-bar {
background-color: white;
}
}
.navbar-brand {
color: white;
font-family: 'Patua One', cursive;
&:hover {
color: $myw-blue;
transition: ease .25s;
}
}
}
.collapse, .navbar-collapse {
.nav, .navbar-nav, .navbar-right {
margin: 0 50px 0 50px;
li {
a {
color: white;
font-family: 'Patua One', cursive;
&:hover {
color: $myw-blue;
transition: ease .25s;
}
}
}
}
}
}
.panel-default {
border: none;
font-family: 'Patua One', cursive;
.panel-footer {
background-color: $myw-blue;
}
.panel-heading {
background-color: $myw-blue;
color: white;
a {
color: white;
text-decoration: none;
&:hover {
color: $myw-pink;
transition: ease .25s;
text-shadow: 2px 2px 2px white;
}
}
}
}
.container {
margin: 60px auto 20px auto;
}
.contact {
margin: 20px 0 20px 0;
text-align: center;
.custom-button {
height: 34px;
margin: 0 auto 20px auto;
width: 110px;
border: solid white 3px;
font-family: 'Patua One', cursive;
font-size: 20px;
a {
text-decoration: none;
color: white;
}
&:hover {
background-color: $myw-pink;
transition: ease .25s;
}
}
.social-buttons {
.facebook {
#include social-button($facebook);
}
.twitter {
#include social-button($twitter);
}
.linkedin {
#include social-button($linkedin);
}
}
}
<div class="row">
<% #blog_posts.each do |blog_post| %>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-blog-post">
<div class="panel-heading">
<p><%= link_to blog_post.title, blog_post %></p>
<!-- <div class="blog-pic-style"> -->
<%= link_to (image_tag blog_post.blog_pic.url), blog_post %>
<!-- </div> -->
</div>
</div>
<div class="panel-body">
by <%= blog_post.user.username %>
<% if blog_post.user.avatar.nil? %>
<%= image_tag blog_post.user.avatar.url, size: 40 %>
<% else %>
<%= image_tag 'user.svg', size: 40 %>
<% end %><br />
<p><i>Created: <%= blog_post.created_at.strftime('%m/%d/%Y at %I:%M%p') %></i></p>
<p><%= blog_post.blog[0..150] %>..<%= link_to "Read More", blog_post %></p>
</div>
<% if signed_in? && (current_user.role == "admin" || current_user.role == "manager") %>
<div class="panel-footer">
<%= link_to 'Edit', edit_blog_post_path(blog_post), class: "btn btn-warning" %>
<%= link_to 'Destroy', blog_post, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-danger" %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
Thanks in advance for the help!

Owl carousel and parallax backgrounds

I have to use parallax.js to background images in owl carousel. For example I wanna use http://pixelcog.github.io/parallax.js/ with https://owlcarousel2.github.io/OwlCarousel2/docs/started-welcome.html
How can I do it?
pen: https://codepen.io/naaatasha/pen/gRdoej
<div class="owl-carousel slider">
<div class="item slide-wrapper parallax-window" data-parallax="scroll" data-image-src="http://trawnik.nazwa.pl/TrawnikProducent2016/wp-content/uploads/slide-strong-1.jpg">
<div class="container">
<div class="box">
<h2 class="h2 wow fadeIn text-right">co tam</h2>
<span class="subtitle wow fadeIn">ihsisdijbvjd</span>
</div>
</div>
</div>
<div class="item slide-wrapper parallax-window" data-parallax="scroll" data-image-src="http://www.focus.pl/upload/galleries/19/trawa-19061_l.jpg">
<div class="container">
<div class="box">
<h2 class="h2">lorem ipsum</h2>
<span class="subtitle">asdsk jbsjfd</span>
</div>
</div>
</div>
</div>
.slider {
position: relative;
display: table;
}
.box {
display: table-cell;
vertical-align: middle;
width: 1%;
}
.slide-wrapper {
height: 800px;
width: 100%;
background-color: #333;
backround-size: cover;
}
.h2 {
font-size: 40px;
font-weight: 500;
margin: 0;
text-transform: uppercase;
}
.subtitle {
display: block;
font-family: 'latolight', sans-serif;
font-size: 30px;
text-transform: uppercase;
}
.parallax-window {
min-height: 400px;
background: transparent !important;
}
jQuery(document).ready(function() {
jQuery(".slider").owlCarousel({
items: 1,
loop: true,
nav: false,
dots: false,
autoplay: true,
autoplayTimeout: 4000,
animateIn: 'fadeIn',
//onChange : callback
});
// function callback(event) {
// jQuery('.parallax-window').parallax();
// }
});

Flexbox not working in Safari and IOS

I have made a responsive flexbox grid. It works in Chrome, but not in Safari and IOS. I must be missing something. Can anyone tell me what I'm doing wrong?
codepen
section {
max-width: 1280px;
display: block;
margin: 0 auto;
}
section:not(.grid) {
.wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
}
.box {
-webkit-box-flex: 1;
-webkit-flex: 1 1 12em;
-ms-flex: 1 1 12em;
flex: 1 1 12em;
}
}
.wrapper {
display: -ms-grid;
display: grid;
-ms-grid-columns: (minmax(12em, 1fr))[auto-fill];
grid-template-columns: repeat(auto-fill, minmax(12em, 1fr));
}
.box {
padding-right: 1em;
}
.box:last-of-type {
padding-right: 0;
}
Remove this enclosing element from your SCSS, but keep everything inside it:
section:not(.grid) {}
it means those flex styles will NOT be applied.
section {
max-width: 1280px;
display: block;
margin: 0 auto;
border: 1px dashed red;
}
.wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: start;
-ms-flex-pack: start;
justify-content: flex-start;
}
.box {
-webkit-box-flex: 1;
-webkit-flex: 1 1 12em;
-ms-flex: 1 1 12em;
flex: 1 1 12em;
border: 1px dashed blue;
}
.wrapper {
display: -ms-grid;
display: grid;
-ms-grid-columns: (minmax(12em, 1fr))[auto-fill];
grid-template-columns: repeat(auto-fill, minmax(12em, 1fr));
}
.box {
padding-right: 1em;
}
.box:last-of-type {
padding-right: 0;
}
<section class="grid">
<h4>All projects</h4>
<div class="wrapper">
<div class="box">
<h5>Project 1<br>
<span>Category</span>
</h5>
</div>
<div class="box">
<h5>Project 2<br>
<span>Category</span>
</h5>
</div>
<div class="box">
<h5>Project 3<br>
<span>Category</span>
</h5>
</div>
<div class="box">
<h5>Project 4<br>
<span>Category</span>
</h5>
</div>
<div class="box">
<h5>Project 5<br>
<span>Category</span>
</h5>
</div>
<div class="box">
<h5>Project 6<br>
<span>Category</span>
</h5>
</div>
</div>
</section>

Resources