Using ChatGPT AI to create CSS Grid Templates

I have been using ChatGPT to create mostly CSS Grid Column Template expressions. I.e. the bit to enter into the Source Grid Column Definition (Advanced).

Not only does this work very well but it also adds an additional explanation of what it creates.

E.g. If you want to use CSS Grid to centre some text on a page and use the width of the text to underline or fill with a background colour that does not extend beyond the width of the text,

You could ask: create a css grid column template with 3 columns, where the centre column is sized to the content

Certainly! Here’s an example CSS grid column template where the center column is sized to the content:

.grid-container { display: grid; grid-template-columns: 1fr auto 1fr; }

In this example, the grid container has three columns. The 1fr value for the first and third columns means they will take up an equal share of the available space in the grid container. The auto value for the center column will size it based on the content it contains.

or in the following example, I also wanted the text to be between 300-400px wide

You could ask: create a css grid column template with 3 columns, where the centre column is sized to the content with a minimum value of 300px and a maximum value of 400px

The answer you get back is:

Sure, here’s an example CSS grid column template that meets your requirements:

.grid-container { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px) minmax(0, 1fr); }

In this example, the grid container has three columns, with the centre column set to a minimum width of 300 pixels and a maximum width of 400 pixels. The minmax() function is used to ensure that the column will resize based on the content if it’s smaller than 300 pixels or larger than 400 pixels.

The 1fr value in the column template for the first and third columns means that they will take up an equal share of the remaining space in the grid container after the centre column has been sized.

6 Likes

That is amazing. I am also using AI to use Source. I have an app based on GPT 3.5 and GPT4. I can upload pdfs to it and ask any questions about the content of the Source Manual. I have of course uploaded the Source manual which is the same as having a Source Oracle :-) That is super helpful.

1 Like

minmax(300px, 400px) for the center column makes sense, but the minmax(0, 1fr) seems odd - isn’t that the idendical behavior as ‘1fr’ alone ? ie minmax(0, 1fr) == 1fr, or do I misunderstand the ‘fr’ unit in CSS gid ?

no, minmax(auto, 1fr) is the same as just 1fr

2 Likes

Can you tell us which app you are using for this purpose? :-)

1 Like

Yes, it is an app called MagicChat, and it runs both on Mac and IOS. I am not sure if it runs on older Macs. But there are others also. This one is developed by one of my former neighbours when I lived in Copenhagen, so I support him. There is also some you can find in Github, that can be installed on your computer. And then there is this one, where you can make a free account, https://www.chatpdf.com, I used this one until i got MagicChat.

Best Regards
Kent

2 Likes

Thanks so much, Kent. MagicChat looks great! :-)

1 Like