Welcome to the second lesson of our course on building an image generation web application with PHP! In the previous lesson, we created the foundational HTML structure for our application using PHP, including the main layout, tab navigation, form elements, and containers for displaying images and history. While the structure is in place, our application currently lacks visual appeal and usability.
In this lesson, we'll focus on improving the appearance of our application by adding a style layer. This will help transform our basic HTML structure into an attractive, user-friendly interface.
In a typical PHP project, static files such as stylesheets are stored in a folder called public or assets. In our project, we will place our stylesheet in a folder named public and link it in our PHP-generated HTML.
Here's how you can link a stylesheet in your PHP template:
This tells the browser to load the style.css file from the public folder at the root of your project. Now, let's create this file and add our styles to it.
First, create a file named style.css inside your public folder. We will start by defining the global styles for the page layout.
Explanation: This block styles the <body> element. It sets a modern, readable font and a light gray background, and it removes default margins. The body uses Flexbox to center its content both vertically and horizontally, with padding at the top and bottom for spacing.
The container acts as the wrapper for all our application content.
Explanation: The .container class creates a white, card-like area for your app's content. It adds internal padding, rounded corners, and a subtle shadow for depth. The width is responsive, but it never exceeds 600px.
Next, we style the tabs that will allow users to switch between the generator and their history.
Explanation: The .tabs class arranges the buttons in a row. .tab-button styles the buttons with a blue background and rounded corners, including a hover effect for interactivity. .tab-content adds spacing above the content area.
This section makes the input fields and the submission button look modern and accessible.
Explanation: These blocks style all <input>, <select>, and <button> elements to be full-width with comfortable padding and consistent rounded corners.
Finally, we add styles to ensure the generated images and their containers are displayed correctly.
Explanation: These styles add spacing above the image areas and ensure that images are responsive (never wider than their container) while adding a soft shadow to make them stand out.
Make sure your main PHP template includes the link to the stylesheet. Here is an example of how your main template might look:
This template includes the stylesheet and uses the class names and IDs referenced in the style.css file. The structure matches what you created in the previous lesson, so you can simply add the stylesheet link and the new CSS file.
In this lesson, we transformed our raw HTML into a professional interface. We covered how to organize static assets in a public folder and link them to a PHP template. We used CSS to create a responsive, centered container, styled navigation tabs with interactive states, and modernized form elements and image displays to ensure a high-quality user experience.
In the next lesson, we will add interactivity to our application so users can switch between tabs and interact with the form. For now, enjoy your newly styled application!
