ReactJS FontAwesome icons rendering different sizes - html

I decided to try my hand at web design for the first time.
I decided to try out React. Then I found that there is a FontAwesome library for React. Cool! However, my icons are rendering at different sizes on my footer and I have no clue why. I've spent a few days on this and I am out of ideas.
I've tried manipulating the icons using the built-in size prop. I've also tried manually sizing and moving the icons using CSS and that hasn't worked for me, either. Lastly, I've tried changing the icon container to some different tags. I've checked around Stack Overflow, React blogs, and read the FontAwesome API docs to try and find out what I am doing wrong, but I have been unable to find a solution.
It seems to be related to the icon's "path" attribute, but I don't know enough about svg icons to figure out why that is. Can someone please take a look at my code? I'm curious if this is a library issue or an implementation issue (I assume its the latter, as I have no clue what I'm doing).
Here is my footer (icon array passed as a prop to the Footer component from App component):
import React from "react";
import { Container, Row, Col } from "react-bootstrap";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
const Footer = props => {
return (
<footer className="footer-container">
<Container fluid="true">
<Row>
<Col sm>
<div className="col-left">
<h5>Contact</h5>
<span className="icon-area">
{props.icons.map((icon, index) => (
<a
href={icon.link}
key={index}
// className={`${icon.name}-svg`}
>
<FontAwesomeIcon
key={index}
icon={icon.icon}
color="white"
fixedWidth //I've tried sizes 2x, 3x instead
// className={`${icon.name}-svg`}
/>
</a>
))}
</span>
</div>
</Col>
<Col sm>
<h6>some more stuff will go here</h6>
</Col>
<Col sm>
<h6>and even more stuff here</h6>
</Col>
</Row>
<Row>
<div className="row2-copyright">
<hr />
<h6>© 2020 Copyright Stuff</h6>
</div>
</Row>
</Container>
</footer>
);
};
export default Footer;
And here is my stylesheet (commented out some different things I've tried):
$font: "Roboto";
.footer-container {
position: relative;
bottom: 0;
left: 0;
right: 0;
font-family: $font;
padding-top: 20px;
background-color: #161515;
.col-left {
text-align: center;
color: #fff;
.icon-area {
align-self: center;
display: inline-flex;
padding: 2px;
font-size: 2rem;
// svg {
// width: 28px;
// height: 28px;
// }
// .discord-svg {
// margin-top: 0.2rem;
// }
// .linkedin-svg {
// margin-top: 0.1rem;
// }
// .envelope-svg {
// margin-top: 0.1rem;
// }
}
h5 {
text-transform: uppercase;
font-size: 1.5rem;
}
}
.row2-copyright {
text-align: center;
width: 100%;
color: #fff;
padding: 0.5rem;
h6 {
margin: 0;
}
hr {
background-color: #fff;
}
}
}
And here is my code sandbox.

The anchor tags that contain the icons do have the same width and height (width 40px, height 48px), as well as the font awesome icons (width: 40px, height 32px) so I guess that your problem is the lack of consistency in the eye, since each font awesome icon has a different shape.
If you want to change the size of the icons, you just need to modify font-size, since font awesome elements are actual fonts.
I have edited your code sandbox below (the selected font sizes are an example, you can change them at your own accordance of course). The only things that I have changed are the following:
Removed the font-size property from the .icon-area
Added vertical alignment (center) at the .icon-area (property: align-items)
Added different font-size for each anchor tag so that the font awesome icons would look somehow similar.
Here's the edited sandbox (changes are concerning only the styles.scss file):

Related

Target a nested div coming from an external component

I am using an imported component which I can't change.
This component has a lot of nested divs.
Somewhere deep in these divs, I need to add a bottom margin to it.
Via Chrome DevTools, I am able to add the margin in one of the divs and achieve the
margin I want. But unable to get it to work when I try to add my css into my scss file.
How can I do this?
const MyComponent = props => {
return (
<div>
{/* This component is not in my control. I can't modify this component*/}
<ImportedComponent/>
</div>
);
};
When I see it in Chrome DevTools, the CSS is something like this.
If I were to add a margin style near the aCssClass or within the block of aCssClass via Chrome,
I get the margin I need. But as said, able to achieve in Chrome DevTools, but not via my scss file.
<div class="my-own-class">
<!-- This is all coming from ImportedComponent, each div has some css class -->
<div>
<div>
<div class="aCssClass anotherClass"> <!-- i want to be able to add my margin here, able to do it but only via Chrome dev tools-->
<div>
<div>
Some data
</div>
</div>
</div>
</div>
</div>
</div>
These are the styles I tried which makes no difference.
.my-own-class {
margin-bottom : 1em;
}
.my-own-class > div:nth-child(3) {
margin-bottom : 22px;
}
.my-own-class body .aCssClass {
margin-bottom: 22px;
}
body .aCssClass {
margin-bottom: 22px;
}
body > .aCssClass {
margin-bottom: 22px;
}
.my-own-class .aCssClass {
margin-bottom: 22px;
}
.my-own-class > .aCssClass {
margin-bottom: 22px;
}
Screenshot
At the highlighted portion, I added margin-bottom 10px under body .sc_marginRight_0 on the right panel which works.
i think it's just a specificity problem, try adding !important and it will work just fine.
.my-own-class .aCssClass {
margin-bottom: 22px !important;
}

How to properly fit an image into a div in HTML and CSS using ReactJS

I am about to finish a small database of images of vessels. As you can see from the screenshot below, the problem I have is that the cards are all different sizes despite I fix the css classes to a specific width. I am trying to have all the card of same width and height. What am I doing wrong?
Below the snippet of code related to this problem:
vessels.js
export default function Vessel({ vessel }) {
const { name, slug, images /* size */ } = vessel;
return (
<div>
<article className="room">
<div className="img-container">
<img src={images[0] || defaultImg} alt="single" />
<Link to={`/vessels/${slug}`} className="btn-primary">
Features
</Link>
</div>
</article>
</div>
);
}
And the related App.css classes:
.room {
display: block;
box-shadow: var(--lightShadow);
transition: var(--mainTransition);
}
.img-container {
position: relative;
}
.img-container img {
width: 100%;
display: block;
transition: var(--mainTransition);
}
What I have done so far:
I have been trying to research and figure out the problem of why that is happening but couldn't understand what I am doing wrong. I consulted this source which seems to be pretty clear. I apply and the result I have is the one on the image I posted.
I tried also to add the height property on the css but that didn't change the problem
.img-container img {
width: 100%;
height: 100%;
display: block;
transition: var(--mainTransition);
}
At a certain point I suspected it was a probelm of visibility but that also didn't change the issue I have. And I think it is not a problem of visibility property.
It seems to me that there is a (probable?) property that could be overwritten? Or maybe that is not the problem.
Thanks for pointing to the right direction on how to solve this issue.
Try using flexbox and styled components for your desired design.
Example:
import React from "react";
import styled from "styled-components";
import "./styles.css";
const BoatContainer = styled.div`
display: flex;
flex-flow: row wrap;
`;
const BoatImg = styled.img`
width: 200px;
margin: 5px;
`;
export default function App() {
return (
<div className="App">
<h1>Behold: boats.</h1>
<BoatContainer>
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Motorboat_at_Kankaria_lake.JPG/1920px-Motorboat_at_Kankaria_lake.JPG" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Boats_at_Bhimili_beach_in_Visakhapatnam.jpg/1280px-Boats_at_Bhimili_beach_in_Visakhapatnam.jpg" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Motorboat_at_Kankaria_lake.JPG/1920px-Motorboat_at_Kankaria_lake.JPG" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Boats_at_Bhimili_beach_in_Visakhapatnam.jpg/1280px-Boats_at_Bhimili_beach_in_Visakhapatnam.jpg" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Motorboat_at_Kankaria_lake.JPG/1920px-Motorboat_at_Kankaria_lake.JPG" />
<BoatImg src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cb/Boats_at_Bhimili_beach_in_Visakhapatnam.jpg/1280px-Boats_at_Bhimili_beach_in_Visakhapatnam.jpg" />
</BoatContainer>
</div>
);
}
Sandbox demo: https://codesandbox.io/s/stack-63731876-boats-e7onm
Here's a handy CSS Tricks guide to flexbox for reference: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

How are themes implemented in CSS

I am currently using variables keeping track of colors for both light and dark themes (e.g. --light-background-color, --dark-background-color). This isn't too hard with two themes but seems a bit manual and if faced with more themes it becomes impractical.
I have seen things like night shift that apply CSS filters which invert the colors on a webpage. How do these filters work? and how would I go about implementing them?
One way to go about this is to have a set of general theme color variables, rather than specific color variables for specific themes like you're trying to do here.
You can define these variables in the body element and override them with the class or a custom attribute of the body.
Use these variables as you would normally for your other HTML elements, and just change the attribute of the body element to apply a different theme.
The important part here is to make sure your theme color variables have corresponding contrasting color variables as well, so that things like white text on a dark background can swap to dark text on a white background.
Here's an example, where primary and secondary theme and contrast colors are defined in the body element, and are overridden when the body has the "dark" class applied to it:
document.querySelector("button").addEventListener("click", () => document.body.classList.toggle("dark"));
body {
--color-primary: #b4e9ce;
--color-primary-contrast: #000000;
--color-secondary: #308d43;
--color-secondary-contrast: #ffffff;
/* Other theme colors... */
}
body.dark {
--color-primary: #202d26;
--color-primary-contrast: #ffffff;
--color-secondary: #8f8f8f;
--color-secondary-contrast: #000000;
/* Other theme colors... */
}
button {
padding: 10px;
margin-bottom: 20px;
}
.wrapper {
padding: 20px;
background-color: var(--color-primary);
border: solid var(--color-secondary) 10px;
}
.wrapper h1 {
font-family: sans-serif;
text-align: center;
color: var(--color-primary-contrast);
}
<body>
<button>Toggle Theme</button>
<div class="wrapper">
<h1>Hello World</h1>
</div>
</body>
Single Line CSS will change Light Theme to Dark:
<style>
body
{
filter: invert(1);
}
</style>

Change size of paper-toggle-button

I am new in Polymer,
I have added paper-toggle-button in my project.I found css classes on official website to change color and transition animation. However I want to reduce it in size especially by some pixels.
I have search through web. But did not successes.
Please help
you can change the size by applying mixins, add the following code to your css styles
paper-toggle-button {
--paper-toggle-button-unchecked-button: {
width: 30px;
height: 30px;
}
--paper-toggle-button-unchecked-bar: {
width: 30px;
height: 30px;
}
}

change color of the same div when on another page

I'm developing a website that will contain two pages for testimonials. The first two testimonials will be displayed on the home page, then the other three testimonials will be displayed on the original testimonial page.
The original testimonial page background-color is different from the home page. I want to change the text color of the testimonials page. I want to know if is it possible to change the style of the same div but in different page using the CSS attributes and selectors?
This is the class that I want to style differently not on home page but on original .testimonial page
.testimonial-author {
color: #14C2E7;
font-family: 'lobster_1.4regular';
font-size: 35pt;
height: auto;
line-height: 0;
position: absolute;
text-shadow: 1px 1px #000000;
width: 850px;
}
I've tried to use the below method:
.other-pages-background, .testimonial-author{
color: red !important;
}
but it changes on all the pages.
thank you
You'd probably be better off wrapping your testimonials on the homepage in another div, so you can use your CSS to target the testimonials on the homepage, without effecting the testimonials page itself.
For example;
on your homepage you could have
<div class="homepage-testimonials">
<div class="testimonials">
<div class="testimonial-author">John Doe</div>
</div>
</div>
Your CSS;
.homepage-testimonials .testimonial-author { color: red; }
Comma means both selectors get the same styling. Try it without the comma to combine them:
.other-pages-background .testimonial-author{
color: red !important;
}
UPDATE:
Since you are using Wordpress, you can use the following with the appropriate page id:
body.page-id-111 {
color: red !important;
}
There are different ways to achieve this.
Include a additional css file say homepage.css in your homepage along with testimonials.css which will contain css to override the default color.
.testimonial-author {
color: $HOMEPAGE_COLOR;
}
Add some class body tag of your Homepage and overwrite the css property like below.
HTML
<body class="homepage">
CSS
/* Will be applied in Testimonial page */
.testimonial-author {
color: #14C2E7;
font-family: 'lobster_1.4regular';
font-size: 35pt;
height: auto;
line-height: 0;
position: absolute;
text-shadow: 1px 1px #000000;
width: 850px;
}
/* Will be applied in Homepage */
.homepage .testimonial-author {
color: #14C2E7;
}
I prefer the later options.
When you load the page ask php to write in the head AFTER the css load
<script>
.testimonial-author {
color: #color;}
</script>