how to change font awesome icon color - reactjs

Please help me I am new at web development, how do I change the font awesome icon color?
In my Navbar.js
import { Component } from "react";
import "../Css/Elements/Navbar.css";
class Navbar extends Component {
state = { clicked: false };
handleClick = () => {
this.setState({ clicked: !this.state.clicked });
};
render() {
return (
<>
<nav>
<a id="navlogo" href="/">Blank</a>
<div>
<ul
id="navbar"
className={this.state.clicked ? "#navbar active" : "#navbar"}
>
<li>
<a href="/">
Home
</a>
</li>
<li>
Shop
</li>
<li>
Blog
</li>
<li>
About
</li>
<li>
Contact
</li>
</ul>
</div>
<div id="mobile" onClick={this.handleClick}>
<i
id="bar"
className={this.state.clicked ? "fas fa-times" : "fas fa-bars"}
></i>
</div>
</nav>
</>
);
}
}
export default Navbar;
Css (i put this here just in case)
/* Nav */
nav {
font-family: sans-serif;
display: flex;
position: fixed;
align-items: center;
justify-content: space-between;
background: #F1F5F9;
width: 100%;
padding: 20px 23px;
z-index: 100;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.06);
}
a {
text-decoration: none;
}
#navlogo {
font-weight: 700;
font-size: 25px;
color: #1D3053;
text-transform: uppercase;
transition: all 0.2s ease;
}
#navlogo:hover {
color: #319afc;
}
#navbar {
display: flex;
align-items: center;
justify-content: center;
}
#navbar li {
list-style: none;
padding: 0 20px;
position: relative;
}
#navbar li a {
text-decoration: none;
font-size: 15px;
font-weight: 700 !important;
color: #1D3053;
text-transform: uppercase;
transition: 0.2s ease-in-out;
}
#navbar li a:hover {
color: #319afc;
}
#navbar li a:hover::after {
content: "";
width: 30%;
height: 2px;
background: #319afc;
position: absolute;
bottom: -4px;
left: 20px;
}
#mobile {
display: none;
}
#mobile i {
color: #ffff;
align-items: center;
}
#media screen and (max-width: 769px) {
#navbar {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
position: fixed;
top: 69px;
right: -100%;
width: 270px;
height: 100%;
background: #ffff;
box-shadow: 0 40px 60px rgba(0, 0, 0, 0.1);
padding: 40px 0 0 10px;
z-index: 100;
transition: 0.3s ease-in-out;
}
#navbar.active {
right: 0px;
}
#navbar li {
margin-bottom: 25px;
z-index: 100;
}
#mobile {
display: block;
}
#mobile i {
font-size: 24px;
cursor: pointer;
}
}
how do I change the "fa-bars" and the "fa-times" icon color my website theme is white and the icon is white too, so its hard to see the icon
Sorry for the bad English :)

You can add style={{color: "<color-name>"}} like this:
<i id="bar"
className={this.state.clicked ? "fas fa-times" : "fas fa-bars"}
style={{color: "red"}}>
</i>

The color of icon is controlled either by itself.
#mobile i {
color: red;
align-items: center;
}
I believe fontawesome also allow you to define color from its parent, because by default it also has this line built-in depending on the UI library you are using.
i {
color: inherit;
}

Related

Hide header in mobile only

I'm making a header for my website, and I added this snippet
#media only screen and (max-width: 993px)
{ .site-header, .rightside, .site-identity, .nav, .leftside, .search, .search-container, .iconbar,
{display: none !important;}
}
to hide it on mobile, I've used it previously with different classes and it used to work, but now it doesn't seem to work with my current header. What am I doing wrong?
Header code:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://kit.fontawesome.com/706d8a1355.js" crossorigin="anonymous"></script>
<style>
body {
margin: 0;
}
a {
text-decoration: none;
color: #a1a1a1;
transition: all 0.2s ease;
}
a:hover {
color: #f8f8ff;
}
.site-header {
overflow: hidden;
background-color: #333;
width: 100vw;
display: flex;
align-items: center;
justify-content: space-between;
}
.site-identity {
float: left;
display: flex;
white-space: nowrap;
align-items: center;
}
.site-identity h1 {
font-size: 1.2em;
}
.site-identity img {
max-width: 50px;
float: left;
margin: 0.3em; /*LOGO*/
}
.nav {
display: flex;
margin-left: 3em;
white-space: nowrap;
font-weight: bold;
}
.nav a {
/* Leave 0 the first, the second is between them*/
padding: 0em 1em;
}
.search {
float: left;
border: none;
overflow: hidden;
border-radius: 20px;
background: #1B1B1B;
width: 60%;
padding: 0.5px 0.5px;
}
.search input[type="text"] {
border: 0px;
width: 67%;
background: none;
font-size: 14px;
}
.search input[type="text"]:focus {
outline: 0;
color: #f8f8ff;
}
.icon-bar {
display: flex;
margin-left: 0.5em;
margin-right: 0.5em;
}
.icon-bar a {
color: #a1a1a1;
font-size: 20px;
padding: 0em 0.2em;
}
.icon-bar a:hover {
color: #f8f8ff;
}
button[type=submit] {
overflow: hidden;
float: right;
cursor: pointer;
color: #a1a1a1;
background: none;
border: 1px solid transparent;
}
button[type=submit]:hover {
color: #f8f8ff;
}
.leftside {
display: flex;
justify-content: right;
align-items: center;
width:42%;
}
.rightside {
display: flex;
align-items: center;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media only screen and (max-width: 993px)
{ .site-header, .rightside, .site-identity, .nav, .leftside, .search, .search-container, .iconbar,
{display: none !important;}
}
</style>
<body>
<header class="site-header">
<div class="rightside">
<div class="site-identity">
<img src="http://via.placeholder.com/400" alt="title"/>
<h1>title</h1>
</div>
<div class="nav">
opt1
opt2
opt3
opt4
</div>
</div>
<div class="leftside">
<div class="search">
<div class="search-container">
<form action="/action_page.php">
<input type="text" placeholder="Search..." name="search">
<button type="submit"><i class="fa-solid fa-magnifying-glass"></i></button>
</form>
</div>
</div>
<div class="icon-bar">
<a class="active" href="mio-account"><i class="fa fa-user-circle"></i></a>
<i class="fa fa-heart"></i>
<i class="fa fa-bell"></i>
<i class="fa fa-shopping-cart"></i>
</div>
</div>
</header>
</body>

Structuring Sidebar in React

Relatively new to React, and am wanting to recreate the design below
enter image description here
I have the base formatting down, but as you will notice, there are lines separating the logo blocks, from the login and signup blocks, with the signup and login buttons pushed to the bottom.
Below is my current code
CSS:
width: 100vw;
height: 100vh;
}
body {
margin: 0;
padding: 0;
}
.Sidebar {
height: 100%;
width: 20%;
background-color: white;
border-right: 1px solid #F0F4FB;
padding-left: 15px;
box-sizing: border-box;
}
.SidebarList {
height: auto;
width: 100%;
padding-left: 15px;
font-size: 18px;
border: 2px #FD954E;
box-sizing: border-box
}
.SidebarList .row {
width: 100%;
height: 50px;
background-color: white;
list-style-type: none;
margin: 0%;
padding-bottom: 15px;
display: flex;
color: #A7ACB6;
justify-content: center;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
}
.SidebarList .row:hover {
cursor: pointer;
background-color: #E7E7E7 ;
}
.SidebarList #active {
background-color: white;
color: #FD954E
}
.SidebarList .Login {
background-color: white;
color: #FD954E;
width: 279px;
height: 39px;
right: 1596px;
top: 958px;
border: 1px solid #FD954E;
box-sizing: border-box;
border-radius: 19.5px;
}
.SidebarList .SignUp {
width: 279px;
height: 39px;
right: 1596px;
top: 1011px;
background: #FD954E;
border-radius: 19.5px;
border: none;
}
.row #icon {
flex: 30%;
display: grid;
place-items: center;
transform: scale(1.2)
}
.row #title {
flex: 70%;
}
.Logo {
padding-left: 25px;
padding-top: 25px;
padding-bottom: 30px;
border-bottom: 1px solid #F0F4FB;
width: 55%;
}
Sidebar.js
import React from "react";
import "../App.css";
import { SidebarData } from './SidebarData'
import Logo from './Logo.svg'
function Sidebar() {
return (
<div className="Sidebar">
<div>
<img src = {Logo} alt='Logo’ className=‘Logo’ />
</div>
<ul className="SidebarList">
{SidebarData.map((val, key) => {
return (
<li
key={key}
className="row"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="icon">{val.icon}</div> <div id="title">{val.title}</div>
</li>
);
})}
</ul>
<div className= "SidebarList">
<button className="Login">
Login
</button>
</div>
<div className= "SidebarList">
<button className="SignUp">
Sign Up
</button>
</div>
</div>
);
}
export default Sidebar;
How should I structure my code in order to acheive my desired result? Ex: with the logo at the top with the seperator, the list of navigation elements, and then the login and signup buttons at the bottom with the seperator?
Currently, my sidebar looks as follows, with the seperator not full width between the logo and navigation elements, and the buttons extending beyond the sidebar.
enter image description here
It would be easier to simplify the problem with just HTML and CSS as that's much easier to troubleshoot. Part of your problem is that you are defining the width of the sidebar as a percentage of the screen width but elements within the sidebar are defined with a width in pixels. When the browser window is too small, your buttons will appear outside the full width of the sidebar. You could either code all your values as percentages or in pixels. Alternatively, you could use a mix and just set a min-width for the sidebar so that you don't end up with elements out of place.
The reason that your line break is not the full width of your sidebar is because you are defining it with the border-bottom property of the logo. Your logo is not 100% the width of the sidebar so your line break will only be the width of the logo. A better solution would be to define a div that is set to width: 100%. This way, you will have more control.
Here is a simplified solution to your sidebar problem using pixels to define the widths.
HTML:
<div class="sidebar">
<div class="header">
<div class="logo">Logo</div>
</div>
<div class="line-break" />
<div class="content">
<ul class="nav">
<li>Home</li>
<li>Blog</li>
</ul>
</div>
<div class="line-break" />
<div class="footer">
<button class="login">Login</button>
<button class="sign-up">Sign up</button>
</div>
</div>
CSS:
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.sidebar {
width: 300px;
height: 100%;
border-right: 1px solid grey;
}
.line-break {
height: 1px;
width: 100%;
background-color: grey;
}
.header .logo {
height: 40px;
width: 200px;
background-color: grey;
margin: 20px;
}
ul.nav {
list-style-type: none;
padding: 20px 0 0 40px;
}
ul.nav li {
margin-bottom: 14px;
}
ul.nav li:last-child {
margin-bottom: 0;
}
.footer {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px 0;
}
.footer button {
padding: 6px 0;
width: 80%;
margin-bottom: 14px;
}
.footer button:last-child {
margin-bottom: 0;
}
And here is a link to a CodePen
where you can see this in action.

Pushing Sign Up & Login buttons to bottom of sidebar

I am trying to recreate this design:
Click to view
However, the below is currently occurring.
Click to view
I am trying to push the SignUp and Login buttons to the bottom of the sidebar to match the first image. Am I missing a CSS class that would allow me to do so, or would this be a JS configuration? Hope I have not overlooked something basic that would allow me to achieve this state.
Sidebar.js
import React from "react";
import "../App.css";
import { SidebarData } from './SidebarData'
import Logo from './Logo.svg'
import { Login } from './Login'
import { SignUp } from './SignUp'
function Sidebar() {
return (
<div className="Sidebar">
<div className="Header">
<div><img src = {Logo} alt='Logo’ className='Logo’ /></div>
</div>
<div class="line-break" />
<ul className="SidebarList">
{SidebarData.map((val, key) => {
return (
<li
key={key}
className="row"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="icon">{val.icon}</div> <div id="title">{val.title}</div>
</li>
);
})}
</ul>
<div class="line-break" />
<div className="footer">
<ul className= "SidebarList">
{Login.map((val, key) => {
return (
<li
key={key}
className="Login"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="title">{val.title}</div>
</li>
)}
)}
</ul>
<ul className= "SidebarList">
{SignUp.map((val, key) => {
return (
<li
key={key}
className="SignUp"
id={window.location.pathname == val.link ? "active" : ""}
onClick={() => {
window.location.pathname = val.link;
}}
>
<div id="title">{val.title}</div>
</li>
)}
)}
</ul>
</div>
</div>
Here is CSS
.App {
width: 100vw;
height: 100vh;
}
body {
margin: 0;
padding: 0;
}
.Sidebar {
height: 100%;
width: 300px;
background-color: white;
border-right: 1px solid #F0F4FB;
padding-left: 15px;
box-sizing: border-box;
}
.SidebarList {
height: auto;
width: 100%;
padding-left: 15px;
font-size: 18px;
border: 2px #FD954E;
box-sizing: border-box
}
.SidebarList .row {
width: 100%;
height: 50px;
background-color: white;
list-style-type: none;
margin: 0%;
padding-bottom: 15px;
display: flex;
color: #A7ACB6;
justify-content: center;
align-items: center;
font-family: Arial, Helvetica, sans-serif;
}
.SidebarList .row:hover {
cursor: pointer;
background-color: #E7E7E7 ;
}
.SidebarList #active {
background-color: white;
color: #FD954E
}
.SidebarList .Login {
background-color: white;
color: #FD954E;
width: 90%;
height: 5vh;
right: 1596px;
top: 958px;
border: 1px solid #FD954E;
box-sizing: border-box;
border-radius: 19.5px;
text-align: center;
font-family: Arial, Helvetica, sans-serif
}
.SidebarList .SignUp {
width: 90%;
height: 5vh;
right: 1596px;
top: 1011px;
background: #FD954E;
border-radius: 19.5px;
border: none;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
}
.row #icon {
flex: 30%;
display: grid;
place-items: center;
transform: scale(1.2)
}
.row #title {
flex: 70%;
}
.Logo {
padding-left: 25px;
padding-top: 25px;
padding-bottom: 30px;
width: 55%;
}
.line-break {
height: 1px;
width: 100%;
background-color: #F0F4FB;
}
ul.nav {
list-style-type: none;
padding: 20px 0 0 40px;
list-style-type: none;
}
ul.nav li {
margin-bottom: 14px;
list-style-type: none;
}
ul.nav li:last-child {
margin-bottom: 0;
list-style-type: none;
}
.footer {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px 0;
}
.footer button {
padding: 6px 0;
width: 80%;
margin-bottom: 14px;
}
.footer button:last-child {
margin-bottom: 0;
}
.header .Logo {
height: 40px;
width: 200px;
background-color: grey;
margin: 20px;
}
Without seeing the source for the entire page and not just a couple of the buttons, it is impossible to say for sure, but my guess would be the following is causing your problem:
.Sidebar {
height: 100%;
...
}
Setting height: 100% will only tell the sidebar to take up 100% of the space it needs for its content (or 100% of the height of its bounding container, depending on the display properties of both). I would recommend changing it to this to solve your problem:
.Sidebar {
min-height: 100vh;
...
}

How do i make my Navbar overlap the rest of the page?

I want my navbar to be fixed and stay above the rest of the page as i scroll down, but whenever i add the 'position: fixed;' function on the css page it disappears.
Here is the code for the navbar in JS and Css...
import Logo from '../../Images/mmt-white.png';
import './Navbar.css';
const Navbar = props => (
<header className="Navbar">
<nav className="Navbar__navigation">
<div></div>
<div className='Navbar__logo'><img src={Logo}/></div>
<div className='spacer '/>
<div className="Navbar_navigation-items">
<ul>
<li>Home</li>
<li>Servicos</li>
<li>Depoimentos</li>
<li>Começando</li>
<li>Contacte-nos</li>
</ul>
</div>
<div className="Navbar_navigation_items_acessar">
<ul>
<li>Acessar</li>
</ul>
</div>
</nav>
</header>
);
export default Navbar;
And here is my app.js where i import all the pages and the navbar on top off them...
import Navbar from './components/NavBar/Navbar';
import Home from "./components/pages/HomePage/Home";
import Comecando from "./components/pages/Comecando/Comecando";
import Depoimentos from "./components/pages/Depoimentos/Depoimentos";
import Sac from "./components/pages/SAC/Sac";
import Servicos from "./components/pages/Servicos/Servicos";
import './App.css';
function App () {
return(
<div className='App'>
<div>
<Navbar/>
</div>
<Home/>
<Servicos/>
<Comecando/>
<Depoimentos/>
<Sac/>
</div>
);
}
export default App;
and here is the css
.NavbarItems {
background: linear-gradient(90deg,rgb(49,56,64)0%,rgba(49, 56, 64, 1) 100%);
height: 10vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 1,2rem;
left: 0;
position: fixed;
top: 0;
z-index: 1;
position: relative;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.navbar-logo{
position: absolute;
top: 0;
left: 0;
transform: translate(15%, 10%);
}
.fa-react{
margin-left: 0.5rem;
font-size: 1,6rem;
}
.nav-menu {
display: grid;
grid-template-columns: repeat(6, auto);
grid-gap: 10px;
transform: translate(8%, 0%);
list-style: none;
margin-left: 10vh;
text-align: center;
width: 80vw;
justify-content: end;
padding-left: 10vh;
margin-right: 1rem;
font-size: 10px;
}
.nav-links {
color:#edf0f1;
margin-top: 2rem;
padding-right: 2rem;
padding: 0;
text-decoration: none;
font-size: 22px;
font-family: monospace;
text-transform: uppercase;
}
.nav-links:hover{
border-radius: 4px;
transition: all 0.2s ease0;
color: #0088a9;
}
.fa-bars{
color: #ffffff;
}
button{
margin-left: 10vh;
right: 0;
padding: 9px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease 0s;
font-family: "Montserrat", sans-serif;
font-weight: 500;
color: #edf0f1;
font-size: 17px;
text-decoration: none;
}
.menu-icon{
display: none;
}
.nav-links-mobile{
color: transparent;
}
You may want to add the following to your NavBar class in your NavBar.css file to add the positional properties like so:
left: 0;
position: fixed;
top: 0;
z-index: 1; // increase this value if you have other elements at varying levels of elevation
Or you may want to add the following to your NavBar class in your NavBar.css file instead of position: fixed (it depends on the behavior you're looking for):
position: sticky;
top: 0; // vertical position you'd like the element to stick to
z-index: 1; // increase this value if you have other elements at varying levels of elevation

Mobile menu effect expands to desktop view

Question:
How can I have the navigation of the mobile menu not affect desktop? When I click on the hamburger button to hide the menu and resize the browser to desktop the navigation disappears. I want to know what I did wrong to better understand my mistake.
GIF Video
Full Code Below:
class Navigation extends React.Component {
constructor(props) {
super(props);
this.state = {
show: false
}
this.toggleShow = this.toggleShow.bind(this)
this.hide = this.hide.bind(this)
}
toggleShow() {
this.setState({
show: !this.state.show
});
}
hide(e) {
if (e && e.relatedTarget) {
e.relatedTarget.click();
}
}
render() {
return (
<Router>
<div className="FlexContainer NavbarContainer">
<div className="mobilecontainer LeftNav">
<h2 className="BrandName LeftNav mobileboxmenu inline FarRight">Kommonplaces</h2>
<div
className="hamburger inlinev"
onClick={this.toggleShow}
onBlur={this.hide}>
<img alt="menubtn" src={hamburger}></img>
</div>
</div>
{
this.state.show &&
(
<ul className="NavBar">
<Dropdown/>
<li className="RightNav"><Link to="/">Host Your Space</Link></li>
<li className="RightNav"><Link to="/">About Us</Link></li>
<li className="RightNav"><Link to="/">Contact Us</Link></li>
<li className="RightNav"><Link to="/">Sign Up</Link></li>
<li className="RightNav"><Link to="/">Login</Link></li>
</ul>
)
}
</div>
</Router>
);
}
}
export default Navigation;
SCSS Code:
.NavbarContainer {
border-bottom: 1px #E7E7E7 solid;
.mobilecontainer {
margin: 2.1em;
.hamburger {
display: inline;
img {
width: 35px;
cursor: pointer;
float: right;
}
}
}
.NavBar {
// display: none;
.RightNav {
text-align: center;
padding: 27px 0;
border-right: none;
border-left: none;
border-bottom: 1px #E7E7E7 solid;
font-size: large;
a {
color: #0E0E0E;
}
}
}
.Dropdown {
float: none;
overflow: hidden;
.Dropdown-Content {
position: relative;
background-color: white;
z-index: 2;
min-width: 217px;
a {
float: none;
display: block;
text-align: center;
border: 1px #E7E7E7 solid;
padding: 15px 22px;
}
}
}
.dropdown-content {
a {
&:hover {
background-color: #ddd
}
}
}
.dropdown {
&:hover {
.dropdown-content {
display: block;
}
}
}
.LeftNav {
flex-grow: 8.2;
font-weight: bold;
font-size: large;
display: flex;
align-items: center;
}
#media (min-width: 55em) {
display: flex;
flex-direction: row;
align-items: center;
top: 0;
left: 0;
z-index: 9999;
width: 100%;
height: 60px;
background-color: #ffffff;
padding: 3em;
.LeftNav {
flex-grow: 0.2;
font-weight: bold;
font-size: large;
}
.mobilecontainer {
margin: 0;
.hamburger {
img {
display: none
}
}
}
.NavBar {
display: flex;
.RightNav {
padding-left: 15px;
padding-right: 15px;
text-align: initial;
border-bottom: none;
font-size: large;
}
.FarRight {
flex-grow: 1;
}
}
.Dropdown {
float: left;
overflow: hidden;
.Dropdown-Content {
position: absolute;
top: 96px;
background-color: white;
z-index: 2;
min-width: 217px;
a {
text-align: left;
padding: 15px 22px;
}
}
}
}
}
This is SCSS code that I'm using for this project.
this.state.show is responsible just for toggle mobile menu.when show ===false react ignore rendering navBar neither in mobile or desktop.you cant use this way for your goal.My suggestion is to consider using react-bootstrap Navbar or reactstrap Navbar
I hope this will help you.

Resources