Search code examples
csscss-grid

How to make a row stretch to full size of the screen without affecting other in css grid


"I'm just learning css grid! i want to increase the width of my footer and make the footer(purple color) to fill the total width of the screen! could someone please tell me how to achieve it! thank you!

html,body
{
    margin: 0%;
    padding: 0%;
    width: 100%;
    height: 100%;
    color: white;}


#container
{display: grid;
grid-template-row: 9.6fr 2.4fr;
grid-template-columns:8.4fr 3.6fr;  }


main
{
background-color: black;
}

submain
{
  background-color: blue;
}

footer
{
  background-color:purple;
}
  <div id="container">
<main>
  <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</main>

<submain>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</submain>

<footer
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</footer>



    </div>


Solution

  • You need to add the grid-column property with value 1 / -1:

    footer {
      background-color:purple;
      grid-column: 1 / -1;
    }
    

    That's a shortcut for grid-column-start / grid-column-end. 1 being the first column and -1 being the last (first starting from the end).

    https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column

    EDIT: I just read that you want it to fill the full width of the screen "without affecting other", if your grid is not 100% width then an element inside it can't be 100% width if that's what you actually want (well, it can though, but overflowing the grid and doing weird unexpected things)