SASS SCSS issue with input styles with react - css

Apologies to everyone to this silly question but I am stuck. Maybe because it is late. I have this SCSS file:
.login {
&__base {
height: 400px;
width: 520px;
}
&__container {
#include center;
input {
background-color: get-color(base-div);
border: 1px solid get-color(border-div);
border-radius: 3px;
color: get-color(text-color);
font-size: 18px;
font-weight: 100;
}
}
}
get-color is a function included in utils.scss and it is not relevant. It just give scss vars in code.
I have this jsx:
import React from "react"
import "./login.scss"
import {FormattedMessage} from "react-intl"
function Login({loginhandler}) {
return (
<div className="login__base wm-card">
<div className="login_container">
<h2><FormattedMessage id="SignIn"/></h2>
<input type="email" name="username"/>
</div>
</div>
)
}
export default Login
this boils down to basic CSS. I know. The input does not get styled and if I put the input on the top level it does. I really cannot see what I am doing wrong. Can somebody lend me a hand and call me blind?
Many Thanks.

You have a typo in the class name of the internal div. It should be this.
import React from "react"
import "./login.scss"
import {FormattedMessage} from "react-intl"
function Login({loginhandler}) {
return (
<div className="login__base wm-card">
<div className="login__container"> // <--- double underscore needed here
<h2><FormattedMessage id="SignIn"/></h2>
<input type="email" id="username"/>
</div>
</div>
)
}
export default Login

Related

I a using mdi-react package for Icons but when combining it with scss the "font-size" property dosen't work

I am using mdi-react package and combining it with scss to define some styles but the font-size propert is not working.
Everything else (like color property) is working.
I searched it all over the internet but can't find a solution so finally decided to write my first question on stackoverflow.
And I know I can just use size="8rem" in the icon component itself but I don't want to do that because of some reasons.
Here is my Home.js file:
import React from 'react';
import { Helmet } from 'react-helmet';
import CubeOutlineIcon from 'mdi-react/CubeOutlineIcon';
import { Link } from 'react-router-dom';
const home = () => (
<>
<Helmet><title>Quiz App - Home</title></Helmet>
<div id="home">
<section>
<div>
<CubeOutlineIcon className="cube" />
</div>
<h1>Quiz App</h1>
<div className="play-button-container">
<ul>
<li><Link to="/play/instructions">Play</Link></li>
</ul>
</div>
<div className="auth-container">
<Link to="/login">Login</Link>
<Link to="/register">Register</Link>
</div>
</section>
</div>
</>
);
export default home;
Here is my home.scss file:
#home {
background-image: url('../../assets/img/bg1.jpg');
background-size: cover;
background-position: center;
display: flex;
justify-content: space-around;
height: 100vh;
section {
background-color: rgba($color: #000000, $alpha: 0.7);
padding: $normal $md;
height: 80%;
width: 35%;
}
.cube {
font-size: 8rem; //Not working
color: $orange;
}
}
That's because the .cube is actually assigned to an SVG element and that would require you to use height and width to change it's size. Font ain't gonna work hence.
(I'm assuming that you considered it to be a font-icon or so as the color property got applied to it, but it did so cos fill is set as currentColor, which uses the current text-color.)
According to docs, to change the size of the icon you should use the size property.
Check the following link:
https://github.com/levrik/mdi-react#usage

equal sizing of column height bootstrap

I have created a React Social Card component using Bootstrap. I want all the cards to be the same size. However, the first card is rendering much larger than the other two. I have tried unsuccessfully to manipulate the CSS to fix this problem but unfortunately, I am a novice with Bootstrap. I have also tried exporting this project into Codesandbox from the Github repository I have it stored in to make it easier to help me find the solution. I am getting this error there: Error importing GitHub repository: Could not find package.json.
Anyway, does anyone know the solution to this problem? Below, I will share a screenshot to illustrate the problem as well as the code for the relevant components and CSS file. Here is the link to the Github repository: https://github.com/jevoncochran/React-Social-Card
Here is the Cards component:
import React, { Component } from "react";
import Card from "./CardUI";
import img1 from "../assets/me-telice-pelo.jpg";
import img2 from "../assets/me-pernambues.jpg";
import img3 from "../assets/me-lucas-walking-pernambues.jpg";
class Cards extends Component {
render() {
return (
<div className="container-fluid d-flex justify-content-center">
<div className="row">
<div className="col-md-4">
<Card imgsrc={img1} title="Convergeance" />
</div>
<div className="col-md-4">
<Card imgsrc={img2} title="Continuation" />
</div>
<div className="col-md-4">
<Card imgsrc={img3} title="Conspiracy" />
</div>
</div>
</div>
);
}
}
export default Cards;
Here is the CSS code:
body {
background: radial-gradient(#e5e5e5, #ffff, #e5e5e5);
}
.card {
width: 20rem;
}
.card:hover {
box-shadow: 5px 10px 20px 1px rgba(0,0,0,0.253) !important;
}
.card-body {
padding: 3rem 0 !important;
}
.card-text {
font-size: 0.9rem;
padding: 0.4rem 1.9rem;
}
.container-fluid .row {
padding: 6rem;
}
.overflow {
overflow: hidden;
}
.card-img-top {
transform: scale(1);
transition: transform 0.5s ease;
}
.card-img-top:hover {
transform: scale(1.4);
}
So, I figured out a solution. I'm not sure it's the best solution out there. But I determined that the problem was that the first image is bigger than the other two images. In my CSS, I just set the maximum height of the all images to the height of the last two (211.938px).

React and Emotion: Specify font size

I am using emotion to style and display the equation for compound interest in my React app. My render() returns this:
<div css ={equation}>
<p>
P (1 +</p>
<p css={fraction}>
<span className="num">1</span>
<span className="symbol">/</span>
<span className="bottom">2</span>
</p>
)
<sup>(nt)</sup>
</div>
And outside of my component I have:
const fraction = css`
display: inline-block;
position: relative;
vertical-align: middle;
letter-spacing: 0.0001em;
text-align: center;
.num {
display: block;
padding: 0;
height: 12px;
line-height: 12px;
}
.bottom {
border-top: thin solid black;
}
.symbol {
display: none;
}
`
const equation = css`
font-size: 100%;
.p{
font-size:large !important;
}
`;
The fraction is correctly styled. However, I cannot get the font of the p elements to change. The only way I got it to was by switching the p to h1 elements - but I don't want to do that. I want to be able to specify the font size inside my emotion css styling.
There are a couple of things I noticed as an issue in your code.
You are passing .p { ... inside the equation which is not a class selector but should have been an element selector like p { ...
Your react div has to use a className in order to make that effect applied
Here is the sandbox code changes: https://codesandbox.io/s/emotion-xh53z?fontsize=14
Just copying here for your reference:
import React from "react";
import { render } from "react-dom";
import { css } from "react-emotion";
const fraction = css`
display: inline-block;
position: relative;
vertical-align: middle;
letter-spacing: 0.0001em;
text-align: center;
.num {
display: block;
padding: 0;
height: 30px;
line-height: 12px;
}
.bottom {
border-top: thin solid black;
}
.symbol {
display: none;
}
`;
// Notice the p inside the equation
const equation = css`
p {
font-size: large !important;
}
`;
// Rather than css={}, you should be using className={}
const App = () => (
<div className={equation}>
<p>
P (1 +
<p className={fraction}>
<span className="num">1</span>
<span className="symbol">/</span>
<span className="bottom">2</span>
</p>
)<sup>(nt)</sup>
</p>
</div>
);
render(<App />, document.getElementById("root"));
I also moved the closing </p> tag at the last to ensure it's getting applied as per inline-block
Updated 1:
Here is the latest updated version: https://codesandbox.io/s/emotion-1tjc7
As per their latest blog you should be using:
import styled from '#emotion/styled'
import { css } from 'emotion'
instead of import styled, { css } from 'react-emotion'
Update 2:
In case you cannot use vanilla emotion, then you can consider using the following:
import styled from "#emotion/styled";
/** #jsx jsx */
import { css, jsx } from "#emotion/core";
According to their documentation:
There are 2 ways to get started with the css prop.
Babel Preset (Can't use in Create-React-App or CodeSandbox)
JSX Pragma (This involves to just add the above to lines of code)
I have updated the same codesandbox: https://codesandbox.io/s/emotion-0z3vz

I have two span tags in a button, here the problem is those two span tags are behaving like a block element?

I am working on a Reactjs project, for that I am using the Bootstrap framework for designing. In that I have one div, in that div I have One button, In that button I have two Span tags. In first span tags I have Icon and In Second Span tag I have text. My problem is In output the text is coming under the Icon, But what I am expecting is Icon and text should be side by side. So try to help me to debug this issue.
This is App.js
import React from 'react';
import './App.css';
import Navbar from './Navbar/Navbar';
import FlightsButton from './FlightsButton/FlightsButton';
function App() {
return (
<div className="App">
<FlightsButton></FlightsButton>
</div>
);
}
export default App;
This is App.css
There is no css in App.css
This is FlightsButton.js
import React, { Component } from 'react'
import './FlightsButton.css'
import ReusableButtons from '../ReusableButtons/ReusableButtons';
class FlightsButton extends Component {
render() {
return (
<div className='container-fluid'>
<div className='row'>
<div className='col-12'>
<div className='one mt-3 d-inline-block'>
<button type='button' className='buttonOne rounded-top'>
<span className='flightStyle'>
<i class="fa fa-fighter-jet fa-sm flightLogo"></i>
</span>
<span className='flightContent pl-2'>
Flights
</span>
</button>
</div>
<div className='two mt-3 d-inline-block'>
<ReusableButtons>
<span className='hotelStyle'>
<i class="fa fa-bed fa-sm hotelLogo"></i>
</span>
<span className='hotelContent pl-2'>
Hotels
</span>
</ReusableButtons>
</div>
</div>
</div>
</div>
)
}
}
export default FlightsButton
This is FlightsButton.css
.buttonOne {
background-color: #008ca8;
border: none;
padding: 0.50%;
padding-left: 0.50%;
padding-right: 0.50%;
}
.flightLogo {
color:white;
}
.hotelLogo {
color:white;
}
.hotelContent {
color: white;
font-weight: 700;
font-family: -apple-system,BlinkMacSystemFont,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,Arial,sans-serif;
}
.flightContent {
color: white;
font-weight: 700;
font-family: -apple-system,BlinkMacSystemFont,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,Arial,sans-serif;
}
.one {
margin-right: 1%;
/* display: inline-block; */
}
.two {
/* display: inline-block; */
}
This is ReusableButtons,js
import React, { Component } from 'react';
import './ReusableButtons.css';
class ReusableButtons extends Component {
render() {
return (
<div className='buttonUsage'>
<button type='button' className='customButtonStyle rounded-top'>
{this.props.children}
</button>
</div>
)
}
}
export default ReusableButtons
This is ReusableButtons.css
.customButtonStyle {
background-color: #00b2d6;
border: none;
padding: 0.50%;
padding-left: 0.50%;
padding-right: 0.50%;
}
I am not aware of react but I used only HTML and CSS from your code and checked it. It looks fine.
But still, if you facing the problem, then increase the button width this will help you.

React component is not reading my css file

For some reason, my React Component is not reading my CSS file. This is the code in my React component.
import React, { Component } from 'react';
import './Jumbotron.css';
class Jumbotron extends Component {
render() {
return (
<div className="Jumbotron jumbotron-fluid">
<div className="container">
<h1 className="display-3">{this.props.title}</h1>
<p className="lead">{this.props.subtitle}</p>
<p className="lead">{this.props.name}</p>
</div>
</div>
)
}
}
export default Jumbotron;
Below is my file structure
The .css file has the following code.
.jumbotron {
background-image: url(../images/fog-forest-lake-113727.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: 100% auto;
color: white;
}
Short answer - The classname is lowercase in your css, it should be capital. Longer answer below which might be helpful to you.
I would recommend using `styled components'. Link is here.
For example your component could look like below
import React, { Component } from 'react';
import StyledWrapper from './styles/wrapper';
class Jumbotron extends Component {
render() {
return (
<StyledWrapper>
<div className="container">
<h1 className="display-3">{this.props.title}</h1>
<p className="lead">{this.props.subtitle}</p>
<p className="lead">{this.props.name}</p>
</div>
</StyledWrapper>
)
}
}
export default Jumbotron;
And in my wrapper.js file I would have the following
import styled from 'styled-components';
export default styled.div`
background-image: url(../images/fog-forest-lake-113727.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: 100% auto;
color: white;
`;

Resources