CSS Style not loading for the second container in NextJS - css

I have a two basic div containers and I am trying to apply some styles to it. I do import my CSS styles from a separate .module.css file and the first style gets picked up in the className property, when assigned. However, the same thing is not working for the second div. The css property for class 'sales' is not being picked up
dashboard.js
import HomeSalesmanStyles from '../../../styles/SalesmanHome.module.css';
const HomeSalesman = ({name}) => {
return(
<>
<div className={HomeSalesmanStyles.container}>
<h4>
Hello, {name} 👋
</h4>
</div>
<div className={HomeSalesmanStyles.sales}>
Hello
</div>
</>
)
};
export default HomeSalesman;
SalesmanHome.module.css
.container {
display: flex;
justify-content: center;
margin-top: 5%;
};
.sales {
display: flex;
justify-content: center;
width: 100px;
background-color: red;
}
Any ideas where the issue is?
----------- Edit ------------
The issue was wrong css module name import! After correcting to the right file, everything works.

This looks like a syntax error in the CSS: adding a semicolon after a rule is invalid.
.container {
display: flex;
justify-content: center;
margin-top: 5%;
} /* <- no semicolon */
.sales {
display: flex;
justify-content: center;
width: 100px;
background-color: red;
}
<div class="container">
<h4>
Hello, {name} 👋
</h4>
</div>
<div class="sales">
Hello
</div>

Related

React popup display:none to display:block

I have a problem with CSS or somethings
I want to click at the profile to show a popup "logout" but it doesn't show anything.
At first, I thought there is a mistake at my CSS, but I searched many times for this solution but it still doesn't work.
import React,{useRef,useEffect} from 'react'
const profileActionRef = useRef(null)
const toggleProfileActions = () => profileActionRef.current.classList.toggle('show__popup')
<div className='profile'>
<motion.img
whileTap={{scale:1.2}}
src={userlogo}
alt=''
onClick={toggleProfileActions}
/>
<div className="profile__actions"
ref={profileActionRef}
onClick={toggleProfileActions}>
{ currentUser ? (<span onClick={logout} >Logout</span> ):( <div>
<Link to='/signup'>Sigup</Link>
<Link to='/login'>Login</Link>
</div>)
}
</div>
</div>
my CSS
.nav__icons .profile .profile__actions{
position: absolute;
top: 98%;
left: 0;
width: 150px;
z-index: 10;
padding: 15px;
display: flex;
align-items: center;
flex-direction: column;
background: var(--card-bg-01);
line-height: 30px;
cursor: pointer;
display: none;
}
.show__popup{
display: block;
}
I have no idea how to fix this. If you can tell me how to fix this it will helpful.
It's not a react issue, it's a css issue: your first css selector is more precise, it has a weight of 3 (https://specificity.keegan.st/), but the .show__popup has a weight of only 1 since it's only a single class. So it's apply before the first selector and the display is erased.
To fix that you can add more weight to your second selector:
.nav__icons .profile .profile__actions .show__popup

hide span when data is blank using inline css

my name: [$name]
How to make the “my name:” not visible if the "[$name]" is blank? I’m using inline css because this form will be sent to HTML email.
As mentioned in the comments, if you want to use CSS only, it depends on the HTML structure. It is possible though.
.nameContainer {
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
}
.name {
margin-left: 0.5em
}
.name:empty + span {
display: none;
}
<div class="nameContainer">
<span class="name"></span><span>My name:</span>
</div>
<div class="nameContainer">
<span class="name">John Doe</span><span>My name:</span>
</div>

react-bootstrap form margin causing overflow

I just got into react-bootstrap today. I want the form to be in a div with margins on left and right side. My jsx looks like this:
const Settings = () =>{
return(
<div className="content">
<div className="box">
{/* Actual form with course info */}
<Form className="course-info">
<Form.Group as={Row} controlId="formHorizontalEmail">
<Form.Label variant="settingsLabel" column sm={3}>
Course Title
</Form.Label>
<Col sm={5}>
<Form.Control/>
</Col>
</Form.Group>
</Form>
</div>
</div>
);
}
CSS:
/* A big wrapper for everything on this page */
.content{
display: flex;
align-items: center;
justify-content: center;
}
/* The box containing the class settings */
.box {
width: 600px;
height: 600px;
border: 30px solid #A6D1DF;
margin-top:50px;
}
.center-items{
margin-top: 1em;
text-align: center;
}
/* Gives the form left/right margin and sets text color */
.course-info {
padding-left: 20px;
color: #9E7772;
}
Form.Label-settingsLabel {
font-size: 1em;
color: red;
}
And the form content overflows the right-hand side of the box, and removing the margin fixes the problem.
However, I still want that margin for styling purposes. Any suggestions? Thanks

Vertically aligning the button with the TextField in React Material-UI

I am using the Material-UI library for React.
I am trying to make a simple form that looks like:
However, I can't figure out how to align the button with the TextField.
I tried changing the margin-top but it increases the margin of the entire wrapper.
Below is the code sandbox for it.
Any tips on getting this fixed?
https://codesandbox.io/embed/material-demo-y5eg7?fontsize=14&hidenavigation=1&theme=dark
In your styles.css file you can add {position: relative; top: 10px} to the small-button className then adjust the top value until you are happy with the position alternatively you might be able to wrap the row in a div and use {display:flex; flex-direction:row; justify-content:center;} to align them all.
Change the below styles in styles.css
.horizontal-form { /* This is newly added style */
display: flex;
align-items: center;
}
.input-text-wrapper {
/* margin-bottom: 1.2em; */ /* comment these styles */
}
.input-text-wrapper-small {
width: 33%;
/* margin-bottom: 1.2em; */
display: inline-block;
}
.small-button {
width: 10%;
/* display: inline-flex;
align-items: center; */
}
jsx
Remove the small-button div from inside the input-text-wrapper div and Then Enclose the input-text-wrapper div and small-button div inside a newly created horizontal-form div
...
</Typography>
<div className="horizontal-form">
<div className="input-text-wrapper">
<div className="input-text-wrapper-small">
...
</div>
<div className="input-text-wrapper-small">
...
</div>
<div className="input-text-wrapper-small">
...
</div>
</div>
<div className="small-button">
<Button variant="contained" color="primary">
Add
</Button>
</div>
</div>
</CardContent>
....
Just replace this line
<div className="input-text-wrapper">
with
<div className="input-text-wrapper" style={{display:"flex", alignItems:"center"}} >
AND remove margin-bottom from your style.css
.input-text-wrapper-small {
width: 30%;
/*margin-bottom: 1.2em;*/
display: inline-block;
}

CSS class name bracket notation doesn't target inner CSS classes

I import the styles to the component like below. Up: It's a React component with a postcss-loader in Webpack.
import styles from './index.scss';
This is a gist from the component:
<div className={styles['container']}>
<Row type='flex' align='middle' justify='space-between'>
<Col span={24}>
... ...
</Col>
</Row>
</div>
This is the styles:
.container {
margin-left: 24px;
& .ant-row-flex.ant-row-flex-space-between.ant-row-flex-middle {
height: 100%;
display: flex;
& .ant-col-24 {
display: flex;
align-items: center;
}
}
}
Only the .container's margin-left: 24px; gets displayed in the component.
How to get .ant-row-flex.ant-row-flex-space-between.ant-row-flex-middle from Row and .ant-col-24 from Col to display too?

Resources