Create Cookie Banner with React JS and custom CSS - css

Hello I am new to React Js and Iam not great with CSS and struggling.
I am trying to implement a basic cookie banner design.
Here is the overall code of what I've tried so far
JS:
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 website's privacy policy.</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 tried adding my custom CSS and implementing a basic UI for cookie banner.
Here is my current Cookie Banner:
CURRENT DESIGN
Here is the design I am trying to accomplish:
MY GAOL

You can wrap your header and message div in another div like this
<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 website's privacy policy.</p>
</div>
<div className={style.click}>
<button className={style.button}>Yes I agree</button>
</div>
</div>
</div>
and add this to 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;
}

Try to chagne your content css class to this
.content {
max-width: 1200px;
display: flex;
justify-content: center;
align-items: flex-end;
}

Related

Some CSS Class selectors don't work in React

I'm working on some basic styling for my personal project, and for some reason, most of the class selectors in my css file Header.css works, except headerOptionCount. Earlier, some other classes weren't working, but putting Header.css in a styles directory seemed to help, but now it is happening again. When changing margin-left and margin-right of headerOptionCount, nothing changes. When inspecting the element in dev tools, the styles dont show up at all.
Header.css:
.header {
height: 60px;
display: flex;
align-items: center;
background-color: #131921;
position: sticky;
top: 0;
z-index: 100;
}
.headerLogo {
width: 60px;
object-fit: contain;
margin: 0 10px;
}
.headerSearch {
display: flex;
flex: 1;
align-items: center;
border-radius: 24px;
}
.headerSearchInput {
width: 100%;
height: 12px;
padding: 10px;
border: none;
}
.headerSearchIcon {
padding: 5px;
height: 22px !important;
background-color: tomato;
}
.headerOptionLineOne {
font-size: 10px;
}
.headerOptionLineTwo {
font-size: 13px;
font-weight: 800;
}
.headerOptionBasket {
display: flex;
align-items: center;
color: white;
}
.headerOptionCount {
margin-left: 10px;
margin-right: 10px;
}
.headerNav {
display: flex;
justify-content: space-evenly;
}
.headerOption {
display: flex;
flex-direction: column;
margin-left: 10px;
margin-right: 10px;
color: white;
}
Here is my Header component that imports this css file.
Header.js:
import React from "react";
import logo from "../zipshopIcon.png";
import { Search, ShoppingCart } from "#material-ui/icons";
import "../styles/Header.css";
const Header = () => {
return (
<div className="header">
<img className="headerLogo" src={logo} alt="Logo" />
<div className="headerSearch">
<input className="headerSearchInput" type="text" />
{/* Logo */}
<Search className="headerSearchIcon" />
</div>
<div className="headerNav">
<div className="headerOption">
<span className="headerOptionLineOne">Hello Guest</span>
<span className="headerOptionLineTwo">Sign In</span>
</div>
<div className="headerOption">
<span className="headerOptionLineOne">Returns</span>
<span className="headerOptionLineTwo">& Orders</span>
</div>
<div className="headerOption">
<span className="headerOptionLineOne">Your</span>
<span className="headerOptionLineTwo">Prime</span>
</div>
<div className="headerOptionBasket">
<ShoppingCart />
<span className="headerOptionTwo headerBasketCount">0</span>
</div>
</div>
</div>
);
};
export default Header;
The import directory is definitely correct since the other styles work. I've tried using css modules, but it didnt fix anything. Should i try using scss? it just baffles me why class selectors cant even work when imported as css files. Any advice would be appreciated, thanks!
None of your elements in the js have the classname headerOptionCount, you need to give the element you want to have those styles the classname for it to work.

CSS Block that goes to the end of the page but doesn't activate scroll

Look at the picture below, the purple square that I have created needs to go to the end of the page always and it cannot activate horizontal scroll or push the screen. The version I have is with a fixed width, but that doesn't work response wise, example: the laptop resolution pushes the content to the right because of it (look here: https://i.imgur.com/BXCYUx1.png ). For mobile xs version I have hidden it, so it's just for screens md, lg and xl.
I used Bootstrap for the grid creation. Here is the code for the right section (where the purple is):
<div class="col-xl-6 col-sm-12 job-details">
<div class="job-title"> Some title <div class="bgendsqaure"></div>
</div>
<div class="inner-job">
<div class="job-timelocation"> Subtitle </div>
<div class="job-info">
- Designing web applications & mobile apps <br>
- Developing responsive websites using HTML, CSS, JavaScript <br>
- Execution of sql queries in microsoft sql server <br>
- Development of apps using git <br>
- Project management using jira with everyday team meetings <br>
</div>
</div>
</div>
SCSS:
.job-details {
margin-top: 25px;
}
.job-title {
padding: 20px;
background: $maincolor;
color: white;
font-weight: bold;
font-size: 1.3rem;
text-align: center;
}
.bgendsqaure {
width: 50px;
height: 50px;
background: yellow;
width: 394px;
height: 71px;
background: #cf9bff;
position: absolute;
right: -378px;
top: 0;
display:none; /* hide */
}
.job-timelocation {
padding: 20px;
background: #4454cf14;
text-align: center;
}
.job-info {
display: flex;
justify-content: center;
padding: 20px;
}
#include xl {
.job-timelocation {
margin-left: 33px;
margin-right: 33px;
}
.bgendsqaure {
display: inline;
}
.job-hide {
display: none;
}
}
#include xs {
.explist {
text-align: center;
}
.stitle {
text-align: center;
}
}
JSFiddle: https://jsfiddle.net/n4qeodk1/

How can I keep all my navbar icons in one row when viewing from a mobile device in React?

I am making a pretty simple bottomnav for a project I am working on, and I am having difficulty with the view in mobile mode. From standard desktop, I have a pretty simple, bottomnav with 4 icons, however when I inspect the page in mobile view, it only shows you either the first, or the first and 2nd icon. all of my styling for this component is:
/* Place the navbar at the bottom of the page, and make it stick */
.navbar {
background-color: rgb(75, 90, 72);
overflow: hidden;
position: absolute;
bottom: 0;
min-width:800px;
height:64px;
/* width: 100%; */
}
.navCont {
text-align: center;
position: fixed;
bottom: 0;
width: 100%;
}
.navButton {
margin-left:10vh;
margin-right:10vh;
min-width:10px;
}
.navButtonLeft {
margin-left:10vh;
margin-right:10vh;
min-width:10px;
}
/* Style the links inside the navigation bar */
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.navbar a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.navbar a.active {
background-color: #4CAF50;
color: white;
}
img {
width:32px;
height: auto;
float:left;
margin-bottom: 20px;
}
#media screen and (max-width: 100px) {
.navbar {
display: inline-block;
height:64px;
}
.navCont {
display: flex;
align-content: space-between;
}
.navButton,
.navButtonLeft {
padding: none;
display: inline-block;
}
img {
display: inline-block;
}
}
Any advice or tips would be greatly appreciated!
edit: Here is the component i am working with.
import React from "react";
import home from "./home.png"
import post from "./post.png"
import profile from "./profile.png"
import search from "./search.png"
import "./Footer.css";
class Footer extends React.Component {
render() {
return (
<div class="navCont">
<div class="navbar">
<img src={home} alt="home icon"/>
<img src={profile} alt="home icon"/>
<img src={post} style={{width:"44px", height: "auto"}} alt="home icon"/>
<img src={search} style={{width:"44px", height: "auto"}} alt="home icon"/>
</div>
</div>
);
}
}
export default Footer;
I've revamped your css to use flexbox for laying out the icons in a row; got rid of all the floats and some other rules that seemed unnecessary. I'm not sure this does exactly what you're trying to do (since I don't know exactly what you're trying to do) but I think this is at least a better starting point.
.navCont {
position: fixed;
left: 0;
right: 0;
bottom: 0;
width: 100%;
background-color: rgb(75, 90, 72);
}
.navbar {
height: 64px;
display: flex;
justify-content: center;
}
/* Style the links inside the navigation bar */
.navbar > * {
flex: 0 0 auto;
padding: 14px 16px;
}
/* Change the color of links on hover */
.navbar a:hover {
background-color: #ddd;
color: black;
}
img {
width: 32px;
max-width: 100%;
height: auto;
}
<div class="navCont">
<div class="navbar">
<a href="/" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000/?text=A" />
</a>
<a href="Profile" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000?text=B" />
</a>
<a href="Post" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000?text=C" />
</a>
<a href="Search" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000?text=D" />
</a>
</div>
</div>

Ionic v4 ion-img eagerly loads the images instead of lazy-loading

I have a horizontal scroller that I built with FlexLayoutModule that basically let's me have a horizontally scrollable list where every item is a column of image and text. Here's the relevant code from my scroller.component.html
<div class="ion-activatable container" fxLayout="column" fxLayoutAlign="start center" fxLayoutGap="10px" *ngFor="let item of items">
<ion-ripple-effect></ion-ripple-effect>
<div *ngIf="item.movie || item.title" [routerLink]="'/tabs/discover/movie/'+ (item.movie? item.movie.ids.tmdb: item.ids.tmdb)">
<ion-img class="poster" [src]="(images$[item.movie? item.movie.ids.tmdb: item.ids.tmdb] | async) || preloaderGif"></ion-img>
<div class="item-titles">
{{item.movie? item.movie.title: item.title}}
</div>
</div>
</div>
But when the page loads up, all the hundreds of image requests are fired which I can see from the network tab as well as my API reporting I have hundreds of pending requests and that I have hit rate-limiting. Maybe I'm not using the ion-img right or maybe some of the styles are messing with it? Here's my scroller.component.scss:
.horizontal {
white-space: nowrap;
overflow-x: auto;
}
.poster {
width: 92px;
height: 138px;
}
.container {
position: relative;
cursor: pointer;
user-select: none;
}
.item-titles {
width: 100px;
white-space: normal;
text-align: center;
}
I'm open to suggestions. Maybe I should use virtual-scroll? But I don't see how I can make that horizontal.
I have done this kind of design using ion-slide. Better to do some scss change to show the part of next element. Please have a look following code.
Html
<ion-slides [options]="slideOpts" class="recent-search">
<ion-slide *ngFor="let item of recentSearch" class="slide-container" float-left text-left>
<div class="history-item" (click)="gotoDetailPage(item.id)">
<div class="container" float-left text-left>
<div class="bold-text">{{item.companyName}}</div>
<div>{{item.productName}}</div>
<div>{{item.descriptor}}</div>
</div>
</div>
</ion-slide>
</ion-slides>
Scss
.slide-container {
.history-item {
width: 100%;
padding: 3px;
.container {
padding: 15px;
background-color: #fafafa;
box-shadow: 2px 2px 11px 3px rgba(0, 0, 0, 0.12);
width: 80%;
font-size: 12px;
color: #767676;
.bold-text {
font-weight: 700;
}
div {
padding: 4px 0;
}
}
}
}
This is how it looks like.
This works nice for me with huge list of data.
Hope this may help to someone else.

How to style my drop down menu?

I have followed a tutorial to build my own drop down menu. Im having problem to style my submenus. Can't find the right class to change it. want the sub menus to come under in one line and in a box.
Can anyone help me?
This is how I do my dropdowns, a bit modified to look more like yours, and you may need to modify it to suite your needs. You can take this code, place it in a text file, and open it with a browser. It should work fine. Also, personally, I don't like using tables or lists for menus but this is just personal preference. Here you go - pure HTML and CSS:
<style>
body { margin: auto; }
.menu
{
position: relative;
background: gray;
height: 40px;
}
.menuItem, .dropdownItem
{
position: relative;
float: left;
width: 150px;
color: black;
}
.menuItem:hover, .dropdownItem:hover
{
background: black;
color: white;
}
.menuItem
{
height: 40px;
line-height: 40px;
text-align: center;
cursor: pointer;
}
.dropdownItem
{
height: 100%;
line-height: 40px;
}
.dropdown
{
position: absolute;
top: -1000px;
width: 450px;
background: gray;
height: 40px;
}
.menuItem:hover .dropdown { top: 100%; }
</style>
<div class="menu">
<div class="menuItem">
Build New
<div class="dropdown">
<div class="dropdownItem">
Bath
</div>
<div class="dropdownItem">
Bathroom Lightning
</div>
<div class="dropdownItem">
Bathroom Faucet
</div>
</div>
</div>
<div class="menuItem">
Construction Of
</div>
<div class="menuItem">
Renovating
</div>
</div>
I hope that this helps.

Resources