Develop a Cookie Banner using React JS combined with personalized CSS styles

Hey there, I'm diving into the world of React JS and finding the CSS aspect a bit challenging.

Currently, I'm working on creating a simple cookie banner design and here's what I have so far:

JavaScript:

import React from "react";
import { withWidth } from "@material-ui/core";
import style from './Cookie.module.css';

function Cookies(props) {
    return (
        <React.Fragment>

            <div ref={props.forwardedRef}>

                <div className={style.cookies}>
                    <div className={style.content}>
                        <p className={style.header}>We use cookies on this site to enhance your user experience</p>

                        <p className={style.message}> By clicking any link on this page you are giving your consent for us to set cookies. Detailed information, also on the right to withdraw consent, can be found in the <a href="/" target="_blank" rel="noreferrer">website's privacy policy.</a></p>

                        <div className={style.click}>
                            <button className={style.button}>
                                Yes I agree
                            </button>
                        </div>

                    </div>

                </div>

            </div>
        </React.Fragment >
    )
}
export default withWidth()(Cookies);

CSS:

.cookies {
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0;
  width: 100%;
}

.content {

  padding-left: 100px;
  padding-top: 5px;
}

.header {
  color: #FFFFFF;
  font-size: 20px;
}

.message {
  color: #FFFFFF;
  font-size: 16px;
}

.click {
  left: 0;
}

.button {
  background-color: #3f7edf;
  color: #FFFFFF;
  font-size: 13px;
  height: 50px;
  width: 100px;
  border-radius: 5px;
  border-color: #3f7edf;
}

I've added my own custom CSS to create a basic UI for the cookie banner.

Here's a look at my current Cookie Banner: CURRENT DESIGN

And here's the design I'm striving towards achieving: MY GOAL

Answer №1

To create a structured layout for your header and message div, you can wrap them within another div as shown below:

<div className={style.cookies}>
  <div className={style.content}>
    <div className={style.main}>
      <p className={style.header}>We use cookies on this site to enhance your user experience</p>
      <p className={style.message}> By clicking any link on this page you are giving your consent for us to set cookies. Detailed information, also on the right to withdraw consent, can be found in the <a href="/" target="_blank" rel="noreferrer">website's privacy policy.</a></p>
    </div>
    <div className={style.click}>
      <button className={style.button}>Yes I agree</button>
    </div>
  </div>
</div>

Don't forget to include the following styles in your css file:

.content {
  padding-left: 100px;
  padding-top: 5px;
  display: flex;
  justify-content:center;
  align-items:flex-end
}
.main{
  width: 55%
}

.click {
  width:45%;
  margin-right: 5px
  left: 0;
}

Answer №2

Consider updating your content css class to the following

.content {
    max-width: 1000px;
    display: grid;
    justify-items: center;
    align-content: flex-end;
}

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

Utilize XML and Javascript to create a captivating donut chart

I am currently experimenting with XML and JavaScript to generate a donut chart. I attempted to implement this JS code. However, I am struggling to create XML that is compatible with the JS. var SCIENCE = 0; var ART = 0; var MATH = 0; $(document).ready ...

Adjust the border color of the <input> element when it is clicked on

I'm currently working on a login screen for my next.js application and I've encountered an issue where the border color changes to a mixture of white and blue when I select an input field. https://i.stack.imgur.com/R2yKa.png I attempted to reso ...

Unable to modify the href of the footer icons on Pancakeswap

Hello all, I am new to working with React. I am a huge fan of the DeFi world, so I have decided to try forking the PancakeSwap frontend from GitHub. So far, I have been able to customize the styling, update the menu items, and more. However, I am facing a ...

The resurgence of React JS in its role as a powerful tool

Although I struggle with React JS, I couldn't find a solution for this particular issue. I'm trying to incorporate this function into my tsx file and display it on the screen within a component. function displayUsers() { const UserListComponent ...

Include dimensions in the images using the width and height attributes, either in the HTML or CSS code

I've recently been working on my wordpress site and have made a change to how I handle image sizes. I've been removing the width and height attributes when adding images, as they are automatically added. Instead, I've been using the followin ...

Strategies for reducing the amount of space between cards in Bootstrap 4

After creating 4 cards using Bootstrap version 4.5, I noticed that the spacing is not right. I'm struggling to reduce the spacing between the cards. Have a look at the image below if you're still confused: https://i.sstatic.net/RrJLL.jpg .car ...

I am looking to establish a secure path specifically designated for an administrative role

How can I securely pass a token from the backend to the frontend in order to protect routes? Currently, my tech stack consists of Symfony 5.4 and React 18.16. I am working on establishing an admin role and securing that specific route. Although I can view ...

Can you explain the distinction between using useContext and Redux?

Can you explain the distinction between useContext and Redux? Is Redux similar to using useContext? Do I no longer require useContext when implementing Redux in my project? ...

Adjust CSS to properly position links alongside details summary

Currently enhancing my Hugo site (repository link is here). I am aiming to integrate a details element alongside anchors, maintaining a consistent style. The desired layout is depicted in the initial screenshot where "abstract" serves as the details elemen ...

What techniques can be used to avoid blinking while forcefully scrolling to the left?

In my previous inquiry about dynamically adding and removing divs on scroll, I was unable to find a satisfactory solution among the responses provided. However, I decided to take matters into my own hands and attempted to implement it myself. My approach ...

What is the solution for fixing the overflowing items in a flexbox with a row direction

I am facing an issue where I have two rows, with the first row containing an image and the second row text. However, when I use flexDirection: 'row', the text overflows the width and the ellipsis does not show up. Can someone please review my cod ...

Issues encountered with Nextjs 13.4 and Next-Auth 4.2 regarding the signIn("credentials", { }); functionality not functioning as expected

When using next-auth credentials in my current project, I encountered an issue with the signIn() function from next-auth/react. It appears that the redirection to the admin page persists regardless of whether the login details are correct or not. {error: n ...

The webpage is currently experiencing difficulty in displaying any information

As a beginner in React and typescript, I am working on a simple application that fetches data from an API and displays it on a web page. Despite fixing some errors and seeing the data in the console log, I am struggling to display any data on the actual we ...

I am facing difficulties with invoking the popOpen() function within my parameters in JS, HTML, and CSS

I'm currently facing an issue with my code. I am attempting to invoke my openPop() function with the input parameter 'pop' within some of my sensor code, but no pop-up is appearing even though I believe I am calling the popup correctly. If a ...

React password eye icon feature designed for numerous input fields

I have a total of three password fields, each equipped with an eye icon that allows users to toggle the visibility of their passwords. At present, I am facing an issue where toggling the visibility of one field affects all other fields as well when using ...

Modifying jQuery CSS causes certain CSS rules from a file to be deleted

When using jQuery to change the css of an element, I've noticed that it can remove some previously specified css rules for that element. For example, .className, .className2, etc... { background-color: black; color : silver; } .className: ...

"What is the best way to use JavaScript to dynamically modify the hover color of a button

I am looking to customize the hover color of all buttons on my website to align with the overall theme. The challenge is that I need the hover color to vary based on the page it originates from. I have successfully identified the referring page, but I am s ...

Angular text input with customizable placeholder text and embedded icon

Hey there, I'm looking to create a unique custom textbox that includes a text placeholder and a help icon that will display useful information in a popover. https://i.sstatic.net/Zh0IK.png When typing into the input, the textbox should have a specif ...

Check that a string field includes specific characters and digits using JavaScript

I'm in the process of developing a React application that includes an input field requiring a specific format: The first four characters (char 1,2,3, and 4) must be "VTF_" followed by numbers for the remaining part of the string. For example, VTF_12 ...

Removing the Shadow from Material UI's Dialog Box

I am currently struggling with the Material UI dialog component that displays information about a location marker. My issue is with disabling the unattractive box shadow that surrounds the component. Despite setting box-shadow: none and trying different so ...