Designing a calendar with a grid template

I am attempting to design a calendar that resembles an actual calendar, but I am facing an issue where all created divs (representing days) are being saved in the first cell. I am not sure how to resolve this. Any help would be greatly appreciated. css

.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(5, 1fr);
    height: 100%;
    position: relative;
    grid-column-gap: 1px;
    grid-row-gap: 1px;
    border-top: solid 1px;
}

.calendar-day {
    position: relative;
    min-height: 100px;
    font-size: 22px;
    padding: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: auto;
    height: 20px;
  }
<React.Fragment>
            <div className="calendar-month">
                <CalendarHeader />
                <div className="days-grid">
                    <Month month={currentMonth} />
                </div>
            </div>
   </React.Fragment>
function Month({ month }) {
    return (
        <div>
            {
                month.map((row, i) => (
                    <React.Fragment key={i}>
                        {row.map((day, idx) => (
                            <Day day={day} key={idx} />
                        ))}
                    </React.Fragment>
                ))
            }
        </div >
    )
}
function Day({ day, rowIdx }) {
    return (
        <div className="calendar-day">
            {day.format()}
        </div>
    )
}

Answer №1

days-grid represents a grid and consists of a single child, the Month component. For the grid to function properly, multiple children must be set, such as the days component. Here is a simple example:

const App = () => {
  const myDays = [1,2,3,4,5,6,7,8,9,10,11]
  const buildDays = (days)=>days
     .map((cur,idx)=><div key={idx} className="my-day">{cur}</div>)
  return(
    <div className="my-grid">
      {buildDays(myDays)}
    </div>
  );
}

Some sample CSS:

.my-grid{
  border: solid 2px royalblue;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(5, 1fr);
  grid-column-gap: 1px;
  grid-row-gap: 1px;
}

.my-day{
  display: flex;
  justify-content: center;
  align-items: center;
  border: solid 2px royalblue;
}

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

What is the best way to initiate a slideshow using an external .js file?

Having an issue with my slideshow. When I put the CSS and JavaScript code in the same page, it kind of "works" but quickly goes transparent, which is not ideal for me. I prefer keeping things organized with separate files - one for each. However, when I mo ...

Retrieve the scope object using angular.element and the $ID parameter

In order to transfer data from an angular application to scripts that operate outside of angular, I am seeking a solution since I cannot modify the code of the angular app. By utilizing Angular Batarang and NG-Inspector extensions in Chrome, I have identi ...

Elevate a div over another div

I have a situation where I need to nest two divs inside another div with the ID "video-wrapper". Here is the HTML code: <div class="row"> <div class="video-wrapper col-lg-2"> <div class="video-thumbnail"> <img ...

Unspecified data output from jquery datepicker

I am currently utilizing a datepicker to select a date. I have implemented the jQuery datepicker, however, it is returning an undefined value. Can someone please assist me with this issue? My HTML CODE: <input type="text" class="form-control fromdate" ...

Setting response character encoding in Node.js/Express - how is it done?

Assume I have the following code: app.get('/json', function(req, res) { res.set({ 'content-type': 'application/json' }).send('{"status": "0"}'); }); I've been attempting to send the response as ...

Implementing clickable URLs in ag-Grid using React

Currently experimenting with ag-grid and attempting to create a table where users can click on a column value to be directed to a page with more details about that specific entry. Is there a way to make a cell value clickable in ag-grid? I've been t ...

Adding an element to an array using useState is successful, but the map method fails to render the newly added elements

I've encountered an issue with updating my array of objects using useState. Although I can see that the array is being successfully updated in the console with the new elements added, these new elements are not displaying when I try to map through the ...

Steps for adding custom text/symbols from a button on the textAngular toolbar

My goal is to include a button on the toolbar that allows users to insert © into the textangular editor (). However, I am struggling to grasp how to add functionality to my registered button. The examples provided by textangular for custom functionali ...

Expanding Row Feature in React-Admin Data Grid (Version 3.19)

I'm currently exploring how to implement react-admin 3.19 using the customized datagrid example. I'm facing some difficulties getting the expand feature to function properly. In the code snippet below, I manually added an expand button but am st ...

What is the methodology behind incorporating enumerations in typescript?

I've been curious about how typescript compiles an enumeration into JavaScript code. To explore this, I decided to create the following example: enum Numbers { ONE, TWO, THREE } Upon compilation, it transformed into this: "use strict ...

An effective method for binding items permanently while still being able to update the entire selection

Imagine a scenario where a list of 1000 items is displayed using infinite scrolling. Each item on the list includes a person's firstName, lastName, and mood for simplicity. Initially, I didn't want to constantly listen for updates. Fortunatel ...

Problem with user scalability in desktop browsers: when zooming out to 33% and lower, all CSS vanishes

Having trouble understanding why my styling disappears at 33% zoom on Chrome and even worse at 75% on IE11. <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"> <meta name="viewport" content="w ...

What is the best way to interpret the JavaScript code within a Vue/Quasar project?

Sample Code: <script type="text/javascript" src="https://widget.example.com/widgets/<example_id>.js" async defer></script> I am looking to integrate this code into Quasar Framework and utilize it with Vue.js. Do you have any suggesti ...

Allow one child to be visible even if the parent container has hidden overflow (or a different setting)

Is there a way to achieve the same look as shown in this example, but without repeating the border-radius code for the div.left in the CSS? It feels redundant and I suspect my approach may not be optimal. If you have any suggestions on how to accomplish t ...

What is the best way to create this server backend route?

I'm currently working on a fullstack project that requires a specific sequence of events to take place: When a user submits an event: A request is sent to the backend server The server then initiates a function for processing This function should ru ...

Encountering an issue while attempting to send a variable to an Apollo mutation in GraphQL

When using the apollo mutation in my react app, everything was working fine until I attempted to pass a variable to the mutation. Below is my code snippet: const DELETE_WORD = gql` mutation($eng_word: String!) { deleteWord(eng_word: $engWord) { ...

What is the best way to control and manipulate this parallax effect?

Having trouble getting the icon dog to appear correctly in this parallax effect. I want the full body of the dog icon to be displayed over the section, but I'm having no luck so far. Please see my code below and let me know if there are any correction ...

Pass the object either in JSON format or as a variable using the drag and drop feature

Here's a quick question: when using the Drag and Drop system, I'm not sure which method is better. Is it more efficient to : utilize setData and getData to transfer a JavaScript object? (Utilizing JSON conversion since setData only passes st ...

Is it possible to utilize a global variable in place of a React.Context for transmitting constant props in this scenario?

I am considering the drawbacks of using a globally shared variable instead of a Context in my specific scenario: This variable will only be set once during the initial rendering It will not change throughout the runtime The variable is needed in multiple ...

Maintain parent hover effect while child is being hovered over

After exploring various solutions to fix an issue, I've hit a roadblock. Adding CSS and jQuery code seemed promising at first, but upon refreshing the browser, a new problem emerged. The parent element retained its hover state background color, but th ...