I'm struggling with organizing my webpage layout using CSS flexbox and CSS grid

  1. Currently, I am working on creating a checkers game using HTML and CSS with the inclusion of CSS Flexbox and CSS Grid for layout design. However, I have encountered an issue where the page is not responsive vertically. When resizing the browser height in Chrome, the checkers board extends beyond its container and overlaps the nav and section elements. While it looks fine at full viewport height, it becomes problematic when the browser height is reduced.
  2. I also need assistance in setting up the page layout so that the nav takes up 20% of the viewport height and the section occupies the remaining space. The current setup I have attempted does not work as expected, so I am open to suggestions for a better approach.

Edit: To clarify my requirements, I want the chessboard to remain contained within its parent (in this case, a section) even when resizing the browser's height. I aim for the elements to stay locked within their respective containers without overlapping other sections, similar to how Twitter handles element positioning during browser resizing.

body {
    margin: 0 auto;
}

/* Styling for Nav */

nav {
    background: black;
    height: 20vh;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Styling for Section */

section {
    background: pink;
    height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

h1 {
    font-family: 'Architects Daughter', cursive;
    font-size: 3rem;
}


/* Setting up the Board */

.container {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
}

.zone-1 {
    background: #CEB67B;
    width: 60px;
    height: 60px;
}

.zone-2 {
    background: #735131;
    width: 60px;
    height: 60px;
}


/* Checkers styling */

.checkers-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.home-checkers {
    cursor: pointer;
    height: 35px;
    width: 35px;
    border-radius: 30px;
    background: red;
    border: 3px solid white;
}

.away-checkers {
    cursor: pointer;
    height: 35px;
    width: 35px;
    border-radius: 30px;
    border: 3px solid white;
    background: black;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Grid Checkers</title>

    <link rel="stylesheet" href="gridDraft.css" />

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Architects+Daughter&display=swap" rel="stylesheet" />
</head>

<body>
    <nav>
        <h1>Checkers Game</h1>
    </nav>
    <section>
        <div class="container">
            <!-- Home Section -->
            <!-- Include your grid structure here-->
            <!-- Away Section -->  
            <!-- Include your grid structure here-->
        </div>
    </section>
</body>

</html>

Answer №1

To ensure the board squares adapt to the screen height, utilize the following CSS:

width: calc(80vh / 8); height: calc(80vh / 8);
instead of width: 60px; height: 60px;.

With 80vh available and 8 vertical stack squares, calculate the height using height: calc(80vh / 8);. Then set the width of each square to match the height with width: calc(80vh / 8);.

body {
    margin: 0 auto;
}
/* THE NAV */
nav {
    background: black;
    height: 20vh;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* SECTION */
section {
    background: pink;
    height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
h1 {
    font-family: 'Architects Daughter', cursive;
    font-size: 3rem;
}
/* setting up the board */
.container {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
}

.zone-1 {
    background: #CEB67B;
    width: calc(80vh / 8);
    height: calc(80vh / 8);
}

.zone-2 {
    background: #735131;
    width: calc(80vh / 8);
    height: calc(80vh / 8);
}

/* Checkers */

.checkers-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.home-checkers {
    cursor: pointer;
    height: 35px;
    width: 35px;
    border-radius: 30px;
    background: red;
    border: 3px solid white;
}

.away-checkers {
    cursor: pointer;
    height: 35px;
    width: 35px;
    border-radius: 30px;
    border: 3px solid white;
    background: black;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Grid Checkers</title>

    <link rel="stylesheet" href="gridDraft.css" />

    <!-- fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Architects+Daughter&display=swap" rel="stylesheet" />
</head>

<body>
    <nav>
        <h1>Checkers Game</h1>
    </nav>
    <section>
        <div class="container">
            <!-- Home Section -->

            <!-- rows and checkers details -->

            <!-- Away Section -->

            <!-- rows and checkers details -->

        </div>
    </section>
</body>

</html>

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

Should I consider implementing Flexbox even if I need to cater to users still using IE9?

Currently, I am embarking on a fresh project centered around constructing a chat window. Typically, I would readily employ Flexbox for this endeavor; nevertheless, one of the stipulations for this project is to ensure compatibility with IE9. While I under ...

How to effectively utilize `MutationObserver` for monitoring the properties of an `HTMLElement` instead of focusing on its attributes

By using the MutationObserver.observe() method, I am able to monitor changes in a specific attribute. For instance, if I have a Div element and the attribute value is modified, then the designated callback function will be executed. However, if the propert ...

My index.html not successfully linking to the CSS file

I'm new to this and still learning, so please bear with me. I'm having trouble linking my CSS file to my index.html document in order to create a black banner at the top of the page. I've tried opening it in both Chrome and Explorer but noth ...

Loading Kendo JS on the client side proves to be rather time-consuming

Working on my project, I have encountered a problem with the kendo ui scheduler where the downloading of the kendo js and css files on the client side is causing slowness on our website. To address this issue, we are attempting to download the kendo js and ...

Whenever the download bar emerges at the bottom, the slideshow content on the page suddenly shifts upwards

Each time the download bar shows up at the bottom, the slideshow content on the Homepage suddenly moves up. It returns to its original position after I close the download bar.https://photos.app.goo.gl/F482eMfkXyfEZkdA9. My assumption is that this issue is ...

Tips on adjusting a position that shifts with changes in window size

Working on a website for my grandpa, I'm planning to include a small biker character that runs across the screen. When hovered over, he stops and advises "wear a helmet." The animation works well, but there's an issue with the positioning when th ...

Tips for utilizing the router instance on a different HTML page within the Backbone JS framework

I'm new to Backbone JS and still learning its intricacies. In main.js, I have created a router class that is included in index.html. I've also created an object of that router class associated with the same HTML page. However, when I redirect t ...

The attribute selector is malfunctioning

Currently, I am attempting to target img tags based on the alt attribute in order to correctly load a background-image on mobile devices. The issue I am encountering is that regardless of the combination of attribute selectors I use, it does not seem to w ...

Aligning a block of text containing two varying font sizes in the center

I'm attempting to center a paragraph element with a span inside that has a different font size, causing the alignment to be slightly off. Below is the HTML code: <p class="priceWrap"><span class="moneySign">$</span>60000.50</p> ...

Cannot locate module: Error: Unable to find the path '../containers/Layout' in '/home/yusquen/Projectss/react-shop/src/components'

https://i.stack.imgur.com/U1097.png description of image goes here Issue with module: Error: The file '../containers/Login' could not be found in the 'react-shop/src/components' directory. ...

Prevent drag and drop functionality in QtWebkit

As I work on creating an HTML GUI for my application using Qt's WebKit, everything is going smoothly with one minor issue. I am trying to prevent users from dragging and dropping images from the GUI itself. While I have successfully disabled text sele ...

Customizing CSS float labels for individual inputs

For my project, I've implemented CSS code to create a floating label effect for form inputs. If you need the original code reference, it can be accessed here. However, since there are multiple examples in the original codebase, I have extracted and m ...

illuminate selected row in datatable using a jquery plugin

My data is displayed using the jQuery plugin DataTable, and everything appears to be working well. I am retrieving my data from PHP using AJAX. However, I encountered an issue when trying to highlight the row that was hovered over while navigating around ...

Arranging cells within a table with numerous rowspan configurations

I need some help creating a table that will be divided using rowspans for a PDF rendering with BFOreports. I have included an example layout below (numbers are just for reference): https://i.stack.imgur.com/Wbe96.png However, the output I am currently ge ...

Shooting star css animation featuring pre and post effects

Trying to create a falling star using CSS animation. I made a star with a pseudo element, but I'm having trouble setting the animation in the pseudo-element. i{ position: relative; width: 0; height: 0; border-left: 12px solid transpa ...

What is the best way to create a "select all" check box in HTML and display the selected values in a div?

$(function () { //This function selects all checkboxes and unchecks selectall if any checkbox is not checked. var checkall = $('#checkall'); var boxes = $('input[type="checkbox"]').not(checkall); checkall.click(function ...

Execute a function on elements that are added dynamically

I'm in the early stages of learning javascript and jquery, so this issue might be very basic. Please bear with me. Currently, I am dynamically adding new link (a) elements to a division with the id "whatever" using the following code: $("#whatever") ...

Numerous HTML forms for submission

How can I distinguish between different forms and submit buttons that are directed to a specific php function? On my current page, I have two forms but each submit button triggers different actions. I attempted to use ISSET to manage the submit actions, ...

Overflowing Collection of Hidden CSS Assets

Here is a unique question. I'm currently implementing some CSS lasers for a futuristic website design: https://codepen.io/jefferymills/pen/xpmDK The code below showcases how to incorporate the lasers using HTML: <div class="laser-beam"></di ...

Chrome isn't showing the Background Image

I am currently working on coding a basic HTML/CSS page and I want to include a background-image within a div element that links to a URL. Interestingly, my code is functioning properly in Safari (Mac) and Firefox but unfortunately not showing the desired r ...