Centering the contents of the grid

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
.skills{
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    place-content: center;
    margin: 0 auto;
    grid-template-areas:
        'one1'
        'two2'
        'three3'
        'four4'
        'five5'
    ;
}
.skillz:nth-child(1){
    grid-area: one1;
}
.skillz:nth-child(2){
    grid-area: two2;
}
.skillz:nth-child(3){
    grid-area: three3;
}
.skillz:nth-child(4){
    grid-area: four4;
}
.skillz:nth-child(5){
    grid-area: five5;
}
.content-head_links{
    display: none;
}
.skillz{
    border-radius: 10px;
    padding: 20px;
    box-shadow: -1px 1px 22px -1px rgba(202,202,202,0.75);
    -webkit-box-shadow: -1px 1px 22px -1px rgba(202,202,202,0.75);
    -moz-box-shadow: -1px 1px 22px -1px rgba(202,202,202,0.75);
    transition: 250ms;
}
.skillz:hover{
    transform: translateY(5px);
}
.Top-skills{
    width: min(95%, 70rem);
    margin: 150px auto;
    text-align: center;
    position: relative;
}
@media screen and (min-width:1024px){
    .skills{
        margin: 0 auto;
        width: min(95%, 70rem);
        gap: 20px;
        max-width: 400px;
        grid-template-columns: 1fr 1fr 1fr;
        place-content: center;
        grid-template-areas: 
        'one1 two2'
        'three3 four4'
        'five5 .'
        ;
    }
}
</style>
<body>
    <div class="Top-skills">
    <div class="skills">
                
        <div class="skillz html">
            <img src="" alt="">
            <h3>html</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam exercitationem </p>
        </div>
        <div class="skillz css">
            <img src="" alt="">
            <h3>css</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam exercitationem </p>
        </div>
        <div class="skillz scss">
            <img src="" alt="">
            <h3>scss</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam exercitationem </p>
        </div>
        <div class="skillz javascript">
            <img src="" alt="">
            <h3>javascript</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam exercitationem </p>
        </div>
        <div class="skillz React">
            <img src="" alt="">
            <h3>React</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam exercitationem </p>
        </div>

    </div>
</div>
</body>
</html>

Trying to achieve centered grid contents with equal sizes on all screens. Challenges with responsiveness and grid sizing when reaching 768px. Seeking solutions for mobile-first design.

Answer №1

Discover a fantastic opportunity to explore CSS grid layouts through this link: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout

If you wish to center each skill card in separate rows, pay close attention to specific grid layout properties:

  1. grid-template-columns - used to define columns within the grid structure (https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-rows)
  2. grid-template-rows - indicates the number of rows in the grid layout (https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns)

To ensure proper alignment of all cards in one row, make use of the grid-template-columns property. Alternatively, if you prefer one card per row, implement the grid-template-rows property.

Incorporating grid-template-areas necessitates careful definition of row-specific areas within a unified set of ''. For additional insights, visit: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-areas

In your coding practice, consider experimenting with the following strategy:

.skills{
    display: grid;
    gap: 1.5rem;
    width: 50%;
    align-content: center;
    grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
    margin: 0 auto;
    grid-template-areas: 'one1' 'two2' 'three3' 'four4' 'five5';
}
.skillz:nth-child(1){
    grid-area: one1;
}
.skillz:nth-child(2){
    grid-area: two2;
}
.skillz:nth-child(3){
    grid-area: three3;
}
.skillz:nth-child(4){
    grid-area: four4;
}
.skillz:nth-child(5){
    grid-area: five5;
}
.content-head_links{
    display: none;
}

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

Getting the chosen option from a dropdown list mapped in ReactJS

I am working on a dropdown select option that is linked to the data of an array object called 'template_titles'. Currently, the value in the dropdown corresponds to the title in the object. My goal is to be able to extract and use the selected va ...

Tips for concealing an entire menu on WP, with the exception of items labeled as current-menu-ancestor

On my Wordpress site, I am faced with a simple problem to solve. I have a primary menu at the top and a secondary menu on the left side. While the top menu only contains level 1 items, the left menu has all the items. To customize the left menu, I am utili ...

PHPBB authentication system

After experimenting with the script based on the guidance I received from you all, I've encountered another issue. When I click 'login' on the login form, it displays this message: The page isn't redirecting properly. Firefox has detect ...

Add a new class to an element located in a separate div using JavaScript

$(document).ready(function() { $('.btn').click(function() { $(this).parent().addClass('show'); }); }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div clas ...

Ways to display or conceal various divs by employing an if/else statement?

I am aiming to conditionally display various divs based on certain criteria: Show the "x" div if it's not already visible Display the "y" div only if the "x" div is already being displayed Show the "z" div only if both the "x" and "y" divs are alrea ...

Buttons aligned vertically alongside an input text field

I am trying to align two buttons vertically under an input text box with the middle aligned. This is what I have done so far: jQuery(document).ready(function($) { // Implementing bootstrap minus and plus plugin // Reference: http://jsfiddle.net/lael ...

Load additional content seamlessly using Ajax in Django without needing to reload the entire navigation bar

I recently started working with Django as I develop my own website. I have created a base.html file which includes the main body, CSS, js, fonts, and navbar that will be present on all pages of my site. The navbar is located in another HTML file called nav ...

JavaScript error leading to ERR_ABORTED message showing up in the console

When I try to load my HTML page, my JavaScript code keeps throwing an error in the console. I am attempting to import some JavaScript code into VSCode using an app module for future reuse. The code is being run through a local server. Error Message: GET ...

Applying CSS to Align List Items to the Left with Word Wrap

Over at my blog page qavalidation.com, I am faced with an issue related to the alignment of vertical menus with links. When word wrap is applied, there seems to be a misalignment in the left indentation. Can someone provide guidance on the correct CSS sty ...

The impact of Jquery datatable version 1.10 on the dropdown component of Bootstrap version 5.1

On my website, I am utilizing Bootstrap v5.1 and Datatable v1.10 in my project. However, this version of Datatable is causing issues with the Bootstrap dropdown functionality. The dropdown menu is not opening as expected. Strangely, no errors are being gen ...

Tips on reducing the size of a display:block

Beginner in programming. I'm having trouble with my signature design. The block in the background is sticking out on both sides. How can I adjust its size? <td> <a href="https://twitter.com/TEST" color="#252e42" class="sc-hzDkRC kpsoy ...

Using JavaScript to display content on the page after handling a form

Hey there! I'm currently working on a website project where users can input their name and have it displayed on the page. My plan is to achieve this using JavaScript. HTML: <div id='errormsg'></div> <form action='' ...

Is there a way to make all DIVs in the same class have the same height as the tallest div?

I have 3 identical divs with an auto height value. How can I set the height of all divs in the same class to be equal to the highest div's height? Same Class Div Thank you in advance. ...

Parallax Effect Slows Down When Scrolling In Web Page

Currently in the process of creating a website with a scrolling parallax effect using Stellar.js on the header and three other sections. However, I'm experiencing lag when scrolling, especially at the top of the page. I've attempted to reduce la ...

Design challenges, consisting of both fixed width and elastic elements, have been resolved

After searching through various posts, I couldn't find the solution I needed. Currently, I am working on a design in Photoshop and foresee a potential issue when translating it into html+css. Picture this: my center div is set at 960px with a semi-tr ...

Is it possible to showcase two modals on a single page, positioning one to the left and the other to the right using Bootstrap?

Can someone help me learn how to display two modals on the same screen, one on the left and one on the right? I am new to bootstrap and would appreciate some guidance! ...

Is it possible to display a "click" message when a button is hovered over using CSS?

Whenever I hover over a button, I struggle to receive the appropriate message like "click" or "enter" before actually clicking it. How can I use CSS to style my buttons in a way that allows for this pre-click messaging? I have tried approaches such as .bu ...

Balancing heights with jQuery

Is there a way to set the height of an h3 element based on the tallest version of its siblings, but only for certain elements? I have a list where CSS organizes items into rows of 3. The last li element in each row has the class "endRow". I want to find t ...

Creating a dynamic input box with an add/remove button in each row using jQuery

Need help with a jQuery-based UI that allows users to dynamically add input boxes. The desired look is as follows: Default appearance: INPUT_BOX [ADD_BUTTON] [REMOVE_BUTTON] Clicking on the [Add_Button] should add another row like this, and so on: ...

Retrieve the value of another ID within a form using the .innerHTML property

I would like to be able to show the value of a text field when the Search button is clicked. Currently, I have the following code on the search button: onclick="document.getElementByid('output').innerHTML = this.value" This code successfully r ...