Using CSS to Utilize Grid or Table Display

Hey everyone, I could really use some assistance with formatting a layout using CSS. This is the look I am aiming for:

https://i.sstatic.net/HCIJ0.png

I have made some progress with my CSS but I'm struggling to get the menu zone to expand to the full height. Any suggestions? My layout is based on display grid.

.page {
  display: grid;
  grid-template-columns: 29% 71%;
  justify-content: flex-start;
  align-content: start; 
}
.section-header {
  grid-column: 1/3;
  display: grid;
  grid-row: row;
  background-color: blue;
  color: #fff;
}
.zone-menu-wrapper {
  grid-row: 1/3;
  background-color: #286dc5;
}
.zone-topper-wrapper {
  grid-row: 1/3;
}
.section-main {
  grid-column: 2/3;
  background-color: orange;
}
.section-footer {
  grid-column: 2/3;
  background-color: yellow;
}
.zone-branding-wrapper {
  grid-column: 2/3;
}

.zone-menu {
  width: 29%;
  display: inline-block;
}
<div class="page"> <header class="section-header"> <div class="zone-topper-wrapper">Top Zone</div> <div class="zone-menu-wrapper">Menu Zone</div> </header> <main class="section-main"> <div class="zone-branding-wrapper">Branding Zone</div> <div class="zone-content-wrapper">Content Zone</div> </main> <footer class="section-footer"> <div class="zone-footer-wrapper">Footer Zone</div> </footer>

Answer №1

If you're looking for a solid solution that offers better support than traditional grid columns, consider implementing a flexbox layout. Alternatively, for even more robust support, you can opt for a float-based approach.

Here are some key points to keep in mind:

  • flex-grow: This property instructs an element to occupy any remaining space within its parent container. It's particularly useful for creating flexible layouts with unknown widths.
  • min-height: 100vh on the body element: Setting the minimum height of the body to 100% of the viewport height ensures that your layout fills the entire screen even if there isn't enough content. This provides a context for elements to grow into when using flex-grow.
  • 100vh for min-height: Utilizing viewport units allows you to specify the minimum height of the body element as 100% of the viewport height.

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-height: 100vh;
}

.wrap {
  display: flex;
  flex-direction: row;
  flex-grow: 1;
  background-color: indianred;
}

.content {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

header {
  background-color: darkseagreen;
}

aside {
  background-color: skyblue;
}

main {
  flex-grow: 1;
  background-color: gold;
}
<header>
  Header
</header>

<div class="wrap">

  <aside>
    Sidebar
  </aside>
  
  <div class="content">
  
    <main>
      Main
    </main>
    
    <footer>
      Footer
    </footer>
    
  </div>
  
</div>

Answer №2

Utilizing the grid layout allows for a more streamlined and efficient use of markup:

body {
  display: grid;
  grid-template-columns: 29% 71%;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "header header" "nav main" "nav footer";
  height: 100vh
}

header {
  grid-area: header ;
}

nav {
  grid-area: nav ;
  grid-column: 1;
}

main,
footer {
  grid-column: 2;/* or grid-area for each of them */
}

/*styling*/
header,
nav {
  background: tomato;
}

main {
  background: turquoise
}

footer {
  background: orange;
  }
body>* {
  padding:1em;
  box-shadow:0 0 1px
}
<header>header</header>
<nav> nav </nav>
<main> main</main>
<footer>footer</footer>

Answer №3

<div class="page">
    <header class="section-header">
        <div class="zone-topper-wrapper">Top Zone</div>

    </header>
  <div class="zone-menu-wrapper">Menu Zone</div>
    <main class="section-main">
    <div class="zone-branding-wrapper">Branding Zone</div>
        <div class="zone-content-wrapper">Content Zone</div>
    </main>
    <footer class="section-footer">
        <div class="zone-footer-wrapper">Footer<br> Zone</div>
    </footer>
</div>

CSS

.page{
  display: grid;
  grid-template-columns:29% 71%;
  justify-content: flex-start;
  align-content: start; 
}
.section-header{
 grid-column: 1/3;
 display:grid
 grid-row:row;
 background-color:blue;
 color:#fff;
}
.zone-menu-wrapper{
grid-row:2/4;
background-color:#286dc5;
}
.zone-topper-wrapper{
grid-row:1/3;
}
.section-main{
 grid-column:2/3;
 background-color:orange;
}
.section-footer{
  grid-column: 2/3;
  background-color:yellow;
}
.zone-branding-wrapper{
  grid-column:2/3;
}

.zone-menu{
width:29%;
display:inline-block;
}

Link to codepen

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible in Angular to first escape HTML strings and then add HTML markup?

Working with a search form in Angular that pulls data from a database and includes an array of strings, I implemented a pipe to highlight the search query in the results by wrapping it with <mark></mark>. This feature has been quite useful so f ...

Troubleshooting unexpected issues with dynamically updating HTML using innerHTML

Need help with a renderWorkoutUpdated function that replaces specific workout records with updated values. _renderWorkoutUpdated(currentWorkout) { let html = `<li class="workout workout--${currentWorkout.type}" data-id="${ curre ...

What sets apart auto, 0, and no z-index values?

Can you explain the distinctions between the following: z-index: auto z-index: 0 the absence of z-index In all scenarios mentioned, we have a container div that contains two inner divs, named div1 and div2, with respective z-index values of 9 and 10. T ...

Activating the CSS :active selector for elements other than anchor tags

How can I activate the :active state for non-anchor elements using JavaScript (jQuery)? After reading through Section 5.11.3 of the W3C CSS2 specification in relation to the :hover pseudo selector in hopes of triggering the activation of an element, I stu ...

Guide to capturing and playing audio on iOS6 with HTML5

Our team is currently working on a web application using HTML5 and Javascript. We are facing a challenge with implementing voice recording functionality, as the Wami Api we tried is not compatible with iPad due to its use of flash for recording. Could yo ...

What could be causing my CSS dropdown menu to not display properly?

I'm having trouble getting the dropdown to work when hovering over the li element with "portfolio" in the text. The code seems correct, but nothing happens when I try to hover over "Portfolio." Below is the code snippet: #navmenu ul { position: ...

Leveraging CSS display:inline-block or float:left for arranging elements containing different lengths of text

Seeking expert advice on the best way to style this HTML structure: <body> -Some content- <div class="parent" style="height:50%;"> <div class="child" style="background-color:#FF9999;">An image</div> <div class="child" style="bac ...

Reduce the value in the database when a button is clicked using PHP

I am currently working on a carpooling website and I could really use some assistance. I have implemented a button that, once clicked, should decrease the number of available free spaces in the car by one (meaning the person who clicks it will reserve a ...

How can I prevent Bootstrap from conflicting with my custom styles?

My HTML menu was functioning perfectly with specific CSS styles, until I decided to add a Bootstrap reference in the header: New Link Added <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> Afte ...

Text in the middle of a button

I've been attempting to recreate the design of this "subscribe to the newsletter button". I'm struggling with achieving the white "inside border or outline" effect. Here is an example of the button ...

Creating a spinning Cube with separate fields for x, y, and z rotation speeds: a step-by-step guide

After dabbling in Java, Visual Basic, HTML, and CSS, I'm now looking to create an interface featuring a central spinning cube with 3 fields to control its x, y, and z rotation speeds. Can you suggest which language would be the best fit for this proje ...

Trouble encountered when utilizing jQuery for XML to HTML conversion and vice versa (CDATA mistakenly transformed into HTML comments)

I am in the process of developing a plugin/bookmarklet that is designed to extract an XML document from the <textarea> element on a web page, make modifications to the XML content, and then reinsert the updated version back into the <textarea> ...

Guide to parsing the HTML structure of a webpage from a different domain

Struggling with parsing the DOM of a remote webpage using AJAX. Can't find any examples or tutorials on this process. My goal is to navigate through the DOM of a remote page, locate a tag with a specific id/class, extract the content within that tag, ...

Animations in Angular fail to operate within mat-tabs after switching back when custom components are being utilized

I am facing a similar issue as Olafvv with my angular 16 project. The problem occurs in a mat-tab-group where the :enter animations do not work when navigating away from a tab and then returning to it. However, in my case, the issue lies within a custom su ...

Unable to get the div to properly follow when scrolling, even when using the fixed position attribute

My webpage is divided into two sections - left and right. I've used divs to create the left navigation and right content. However, when scrolling down the page, only the right portion scrolls while the left navigation remains fixed. I'm looking ...

I keep encountering an issue when trying to load the website <a href="linktext.com">linktext.com</a> using SQL and PHP

I recently encountered an issue while trying to retrieve data from an SQL database on a webpage using PHP. The process was interrupted whenever there was a hyperlink present in the SQL text data, such as linktext.com. I attempted to use HTML special chara ...

How can I make my div change color when the check-box is selected?

I have a dynamic table in my web application that is populated with data from a database. Each row in the table represents multiple time slots for a specific date. I am working on a feature where the background color of a time block can be changed if a che ...

What is the best way to add borders to table cells that have a non-zero value

I am trying to create a table using a function and it currently looks like this: table { border: 1px solid; } td { width: 30px; height: 30px; text-align: center; } <table> <tr> <td>2</td> <td>0</td> ...

Dynamic content moves unpredictably when adding or modifying TextBoxes or DropDownList items

Whenever I navigate from one textBox to another in my .aspx form, it starts jumping around. The problem is exacerbated when I switch focus to or from a DropDownList. I only have a few textboxes on the form and nothing complex like gridviews or labels. So ...

What causes the entire set of dynamically created cards to collapse when using the toggle collapse button in ngb-bootstrap's Collapse control?

I am currently implementing the ngb-bootstrap collapse feature in my Angular 9 application. Incorporating the ngb-bootstrap collapse functionality within a Bootstrap card, I have multiple cards being generated. Each card is equipped with a collapse button ...