cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="main-grid actual-grid">

    <main class="about">
        <h1>Hello World</h1>
        <p>About Ipsum</p>
    </main>
    <aside class="news">
        <h4>Latest News</h4>
        <h3>News article goes here</h3>
        <p class="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae eros a ex consequat interdum. Vestibulum velit felis, fermentum sit amet convallis eget, suscipit ut est. Curabitur aliquet ante sit amet nisl suscipit mollis. Quisque in sodales nulla, eu finibus felis. Nam venenatis blandit metus a dignissim. </p>
        <a href="#">Learn more</a>
    </aside>

        <aside class="photo">
        <img src="https://placekitten.com/1000/800" alt="" />
    </aside>
</div>






<div class="controls">
    <h3>Layout On the Grid (click) </h3>
    <button class="button gridButton" data-selectClass="about">About</button>
    <button class="button gridButton" data-selectClass="news">News</button>
    <button class="button gridButton" data-selectClass="photo">Photo</button>
<div class="main-grid">
  
      <div class="box about" data-row="1" data-column="1"></div>
      <div class="box news" data-row="1" data-column="2"></div>
      <div class="box photo" data-row="1" data-column="3"></div>
      <div class="box" data-row="1" data-column="4"></div>
      <div class="box" data-row="1" data-column="5"></div>
      <div class="box" data-row="1" data-column="6"></div>
      <div class="box" data-row="2" data-column="1"></div>
      <div class="box" data-row="2" data-column="2"></div>
      <div class="box" data-row="2" data-column="3"></div>
      <div class="box" data-row="2" data-column="4"></div>
      <div class="box" data-row="2" data-column="5"></div>
      <div class="box" data-row="2" data-column="6"></div>
      <div class="box" data-row="3" data-column="1"></div>
      <div class="box" data-row="3" data-column="2"></div>
      <div class="box" data-row="3" data-column="3"></div>
      <div class="box" data-row="3" data-column="4"></div>
      <div class="box" data-row="3" data-column="5"></div>
      <div class="box" data-row="3" data-column="6"></div>
      <div class="box" data-row="4" data-column="1"></div>
      <div class="box" data-row="4" data-column="2"></div>
      <div class="box" data-row="4" data-column="3"></div>
      <div class="box" data-row="4" data-column="4"></div>
      <div class="box" data-row="4" data-column="5"></div>
      <div class="box" data-row="4" data-column="6"></div>
      <div class="box" data-row="5" data-column="1"></div>
      <div class="box" data-row="5" data-column="2"></div>
      <div class="box" data-row="5" data-column="3"></div>
      <div class="box" data-row="5" data-column="4"></div>
      <div class="box" data-row="5" data-column="5"></div>
      <div class="box" data-row="5" data-column="6"></div>
      <div class="box" data-row="6" data-column="1"></div>
      <div class="box" data-row="6" data-column="2"></div>
      <div class="box" data-row="6" data-column="3"></div>
      <div class="box" data-row="6" data-column="4"></div>
      <div class="box" data-row="6" data-column="5"></div>
      <div class="box" data-row="6" data-column="6"></div>
  </div>
  
    <a class="button save">
    Save
    </a>
    <span class="close">(close)</span>
    
</div>

            
          
!
            
              img {
    width: 100%;
    object-fit: cover;
    height: 100%;
}
body {
   
}
* {
    box-sizing: border-box;
}
.button {
    display: inline-block;
    background-color: purple;
    color: white;
    padding: 10px 15px;
    cursor: pointer;
    text-align: center;
    &.save {
        display: block;
    }
    &:hover {
        background-color: darken(purple, 10%);
       
    }
}
.actual-grid {
    background-color: tomato;
}
.controls .main-grid {
    height: 30vh;
    margin: 10px 0;
    grid-template-rows: repeat(6, 1fr);
    grid-gap: 2%;

}
.controls h3 {
    margin: 0 0 10px 0;
}
.main-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: minmax(100px, 1fr);
    grid-gap: 1vw;
}
.box {
    background-color: tomato;
    &:hover {
        background-color: darken(tomato, 10%);
    }
    &.about {
        background-color: pink;
        &:hover {
            background-color: darken(pink, 10%);
        }
    }
    &.news {
        background-color: lightblue;
        &:hover {
            background-color: darken(lightblue, 10%);
        }
        
    }
    &.photo {
        background-color: goldenrod;
        &:hover {
            background-color: darken(goldenrod, 10%);
        }
    }
}




.controls {
    position: fixed;
    opacity: .5;
    right: 0;
    bottom: 0;
    background-color: #efefef;
    width: 30vw;
    padding: 20px;
    transition: .3s ease-out;
    transform: translatey(87%);
    .close {
        font-size: .7em;
    }
    &:hover {
        opacity: 1;
    }
    &.active {
        opacity: 1;
        transform: translatey(0);
    }
    .active {
        color: tomato;
    }
}
.about {
    background-color: pink;
    padding: 1vw;
}
.photo {
    background-color: goldenrod;
}
.news {
    background-color: lightblue;
    padding: 1vw;

}
            
          
!
            
              let selectClass = "";
const classes = ['about', 'news', 'photo'];
$('.gridButton').on('click', function(e) {
    e.preventDefault;
    $('.controls').find('.active').toggleClass('active');
    $(this).toggleClass('active');
    selectClass = $(this).data('selectclass');
    
})


$('.controls .main-grid').on('mousedown', function(e) {
    // e.preventDefault;
    $('.box').bind('mouseover', function() {
        $(this).toggleClass(selectClass);
    });
});
$(window).on('mouseup', function() {
    $('.box').unbind('mouseover');
})




$('.box').on('click', function(e) {
    e.preventDefault;
    $(this).toggleClass(selectClass);
})


$('.save').on('click', function(e) {
    e.preventDefault;  
    getGridPosition();
});


function findBoxes() {
    let boxes = [];
    $('.box').each(function(i, elem) {
        if (elem.classList.length > 1) {
            boxes.push(elem);
        }
    });
    return boxes
    
    
}

function splitBoxArray(array) {
    let subArray = [];
    $(classes).each(function(i, elem) {
       subArray[elem] = array.filter(function(item) {
           return $(item).hasClass(elem);
       });
    });
    
    return subArray;
    
}

function setGrid(className, boxes) {
    const rows = [];
    const columns = [];
    $(boxes).each(function(i, elem) {
            let row = $(elem).data("row");
            let col = $(elem).data("column");
            rows.push(row);
            columns.push(col);
    });
    if (rows.length > 0) {
        let firstCol = Math.min(...columns);
        let lastCol = Math.max(...columns) + 1;
        let firstRow = Math.min(...rows);
        let lastRow = Math.max(...rows) + 1;
        let gridArea = firstRow + " / " + firstCol + " / " + lastRow + " / " + lastCol;
        console.log(firstCol, lastCol, firstRow, lastRow);
        $('.actual-grid .' + className).css('grid-area', gridArea);
    }
}

function getGridPosition(item) {
    let boxArray = findBoxes();
    let splitArray = splitBoxArray(boxArray);

    setGrid("about", splitArray.about);
    setGrid("news", splitArray.news);
    setGrid("photo", splitArray.photo);
    
}

$('.controls h3').on('click', function(e) {
    $(this).parent().toggleClass('active');
});
$('.close').on('click', function(e) {
    $(this).parent().toggleClass('active');
})
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console