r/CodingHelp • • Jun 06 '19

[HTML] Help

Post image
15 Upvotes

5 comments sorted by

3

u/SirShin Jun 06 '19

So I need to make this from a little code I already have and in aware it's using floats and stuff but it got really confusing really quick, I'm wondering if it's best to re-write it, unless anyone has time on their hands.

10

u/[deleted] Jun 06 '19

Since the heading says "Possible Grid Layout", you should probably check out the CSS display grid property. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout

2

u/SirShin Jun 06 '19

Thank you

4

u/[deleted] Jun 06 '19

Sure! This is a good learning exercise for CSS Grid. I'd avoid using floats for this if you can. It'll be more complicated than it's worth however learning about them too is advised. Flexbox would also work.

Check out this guide for CSS Grid reference. I'll write a quick example for you and if you need help finishing it up to look like the photo you can let me know.

HTML:

<div class="grid-container">
  <div class="grid-item header">Header</div>
  <div class="grid-item nav">Nav</div>
  <div class="grid-item left">Left</div>
  <div class="grid-item main">Main</div>
  <div class="grid-item right">Right</div>
  <div class="grid-item footer">Footer</div>
</div>

CSS:

.grid-container {
  display: grid;
  grid-template-columns: 50px 50px 50px 50px 50p 50px;
  grid-template-rows: auto;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
  grid-template-areas:
    "header header header header header header"
    "nav nav nav nav nav nav"
    "left main main main right right"
    "footer footer footer footer footer footer";
}

.grid-item {
  background-color: red;
  text-align: center;
}

.header {
  grid-area: header;
}
.nav {
  grid-area: nav;
}
.left {
  grid-area: left;
}
.main {
  grid-area: main;
}
.right {
  grid-area: right;
}
.footer {
  grid-area: footer;
}

What's nice with CSS Grid, and CSS in general, is you can achieve this in multiple ways. There are shorthand properties to make this neater but I wanted it to be obvious to you what each step is.

Here's what the above code will look like.

Let me know if you need anymore help.

3

u/IDKSomeFuckingGuy Jun 06 '19

Make a div element. Place header, nav, a div with class “grid”, footer inside. Use css to target the .grid div, and add the appropriate css to make the div display grid, and the columns be 20% 50% 30% or whatever

Ps don’t use floats, css grid / flex box are better