Apply Styles to QR Code Generator Application

The next step is to add styles to each element to make it visually appealing using CSS. We can create n styling files one for each component. In this project, we will create two CSS files, one for the QrGenerator component and another for the App component.

  • Modify the QrGenerator component to add styling for each element. Using the className attribute, we can match the styling to the element. Make sure to import the style file into the component.
// QrGenerator.jsx



import "./QrGenerator.css";



function QrGenerator() {

  return (

    <div className="qr-generator">

      <div className="input-container">

        <input

          type="text"

          id="input"

          placeholder="Eg: https://google.com/ "

        />

        <button className="submit">

          Generate

        </button>

      </div>

      <div className="display-container">

        <img src="/" alt="QR code" id="qr" />



        <a className="download-btn" href={qrCode} download="qrcode.png">Download QR Code</a>

      </div>

    </div>

  );

}



export default QrGenerator;
  • The next step is to create a styling file for QrGenerator. Create a file in the component folder QrGenerator.css. And write styles for each element.
/* QrGenerator.css */



/* Applying style for the body */

body{

    background-colorrgb(14666);

    color: white;

}



/* Main container for QR generator */

.qr-generator{

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

    width100%;

}



/* Input container */

.input-container{

    display: flex;

    flex-direction: row;

    align-items: center;

    justify-content: space-between;

    gap2rem;

    padding10px;

    margin35px 5px;

}



/* Input[text] field */

#input{

    width25rem;

    height50px;

    padding1rem;

    border-radius15px;

    border2px solid rgb(000);

}



/* QR generate button */

.submit{

    width: max-content;

    height50px;

    background: none;

    border: none;

    font-size1.5rem;

    font-weight: bold;

    color: white;

    cursor: pointer;

}



/* Hover style for generate button */

.submit:hover{

    colorrgb(8325112);

}



/* Display container */

.display-container{

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

    gap2rem;

}



/* QR code image */

.qr{

    height5rem;

    width5rem;

}



/* Download button */

.download-btn{

    width: max-content;

    text-decoration: none;

    colorrgb(2220334);

    align-content: center;

    padding10px;

    border-radius25px;

    height50px;

    font-size1rem;

    font-weight: bold;

    cursor: pointer;

}



/* Download button hover feature */

.download-btn:hover{

    color: white;

}
  • Now, let’s add some styling to the App component.
// App.js

import "./App.css";

import QrGenerator from "./components/QrGenerator";

function App() {

  return (

    <div className="App">

      <h1>QR Code Generator</h1>

      <QrGenerator />

      <a href="https://www.guvi.in/" className="copywright">

        Made by Guvi💚

      </a>

    </div>

  );

}



export default App;
  • Modify the App.css file to include new stylings.
/* App.css */



*{

  margin0;

  padding0;

  box-sizing: border-box;

  font-family: Georgia;

}



.App{

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: center;

  height100vh;

}



.copywright{

  color: white;

  text-decoration: none;

  font-size1rem;

  margin-top20px;

  top0%;

  bottom100%;

}
  • Once you add the styling, the application will look like the below output.