Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Change the flexbox gap property using Javascript

I'm trying to change the flexbox gap property of a div when calling a JavaScript function, but I cannot seems to access it, here is the current code:

.bottomCont {
  position: absolute;
  display: flex;
  left: 25%;
  top: 80%;
  right: 25%;
  bottom: 0;
  flex-wrap: nowrap;
  align-items: center;
  margin: 5% 5%;
  justify-content: center;
  gap: 10%;
}
<div id="botCont" class="bottomCont">
  <div class="leftControls"></div>
  <div class="eraser">๐Ÿšจ erase ๐Ÿšจ</div>
  <div class="rightControls"><button id="sizeGrid" class="gridSize">CHANGE GRID SIZE</button></div>
</div>

Here is what I've tried to add in the main.js file, none worked:

document.getElementById('botCont').style.gap = 40;
document.getElementById('botCont').style.flex.gap(40);
document.getElementsByClassName('bottomCont').css('gap', '40%')

I tried to use console.log to inspect but I do no get any returned value.

about 4 years ago ยท Juan Pablo Isaza
2 answers
Answer question

0

You need to specify the unit as well, so

document.getElementById('botCont').style.gap = '40px';

or

document.getElementById('botCont').style.gap = '40%';
about 4 years ago ยท Juan Pablo Isaza Report

0

in gap property the value will be length like (px) or percentage. check mdn

in js file you will add value with length or percentage like this:

let changeGap = document.querySelector("#sizeGrid"),
    botCont = document.querySelector("#botCont");

changeGap.addEventListener("click", function () {
    botCont.style.gap = "20%";
});
        .bottomCont {
            position: absolute;
            display: flex;
            left: 25%;
            top: 80%;
            right: 25%;
            bottom: 0;
            flex-wrap: nowrap;
            align-items: center;
            margin: 5% 5%;
            justify-content: center;
            gap: 10%;
        }
    <div id="botCont" class="bottomCont">
        <div class="leftControls"></div>
        <div class="eraser">๐Ÿšจ erase ๐Ÿšจ</div>
        <div class="rightControls">
            <button id="sizeGrid" class="gridSize">CHANGE GRID SIZE</button>
        </div>
    </div>

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!