My CSS doesn't work with my React project, it only changes body (I changed the background color from white to black), the rest from .info isn't working at all. What am I doing wrong?
import React from 'react';
import styled from 'styled-components';
import styles from 'assets/css/CSS.module.css';
const Offer = () => (
<div>
<div className={'info'}>
<h1 className={'info__title'}>Pick a pricing plan</h1>
<p className={'info__description'}>
We did our best to meet your expectations.
Please feel free to pick the right plan for your needs.
Remember that in any moment you can switch your pricing plan.
</p>
</div>
<div className={'container'}>
<div className={'box'}>
<h2 className={'box__title'}>Basic</h2>
<p className={"box__description"}>
Everything you need. For a reasonable price.
</p>
<p className={"box__price"}>$29</p>
<button className={"box__button"}>choose</button>
</div>
<div className={"box box--featured"}>
<h2 className={"box__title"}>Pro</h2>
<p className={"box__description"}>
More than anyone can give – for less than anywhere else.
</p>
<p className={"box__price"}>$99</p>
<button className={"box__button"}>choose</button>
</div>
<div className={"box"}>
<h2 className={"box__title"}>VIP</h2>
<p className={"box__description"}>
Ok, we get it. You’re the boss now. Just tell us what you need.
</p>
<p className={"box__price"}>$429</p>
<button className={"box__button"}>choose</button>
</div>
</div>
</div>
);
const HomePage = () => (
<>
<div>
<Offer/>
</div>
</>
);
export default HomePage;
$dark: #171717;
$light: #ffffff;
$font-stack: 'Fira Code', sans-serif;
html {
box-sizing: border-box;
}
*, *::before, *::after {
box-sizing: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font-family: $font-stack;
background-color: $dark;
color: $light;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
padding: 50px 0 0;
}
.info {
text-align: center;
max-width: 700px;
margin-bottom: 60px;
&__title {
font-size: 45px;
}
&__description {
font-size: 18px;
}
}
.container {
display: grid;
max-width: 1000px;
align-items: center;
#media (min-width: 800px) {
grid-template-columns: repeat(3, 1fr);
}
}
.box {
min-height: 500px;
border: 5px solid $light;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
padding: 0 15%;
position: relative;
&:first-of-type {
right: -5px;
}
&:last-of-type {
left: -5px;
}
&__title,
&__price {
font-size: 45px;
font-weight: bold;
}
&__title {
margin: 0 0 20px;
}
&__price {
margin: 30px 0;
}
&__description {
font-size: 14px;
}
&__button {
background-color: $light;
padding: 8px 25px;
font-family: $font-stack;
font-weight: bold;
border: none;
}
&--featured {
background-color: $light;
color: $dark;
min-height: 550px;
box-shadow:
-20px 0 25px -15px rgba(255,255,255, .3),
20px 0 25px -15px rgba(255,255,255, .3);
&::before {
width: 95%;
height: 97%;
content: '';
position: absolute;
border: 5px solid $dark;
}
&::after {
top: 1.5%;
width: 40%;
min-width: 45px;
height: 30px;
content: 'most popular';
font-size: 12px;
display: flex;
justify-content: center;
align-items: center;
color: $light;
background-color: $dark;
position: absolute;
}
.box__title,
.box__price {
font-size: 60px;
}
.box__description {
font-size: 16px;
}
.box__button {
position: relative;
z-index: 10;
background-color: $dark;
color: $light;
font-size: 20px;
padding: 12px 28px;
}
}
}
I added the correct code, before that i started writing something else, but that doesnt matter now. details, details, details , details - just wrote this so i could edit.
I've changed css. to scss, imported scss. and installed sass, but the only thing that change is the body background to black
Use a relative path. Assuming HomePage.js is in components, the import should be import '../assets/css/CSS.module.css'
There are several problems in your original post.
1) jsx className syntax
Your JSX should look like this:
const Offer = () => (
<div className={'info'}>text</div>
...
See codeburst.io/styling-in-react.
2) Specify the correct import
Your path / filename for the stylesheet should be something like:
import '../../assets/css/CSS.module.css';
3) Add Sass to your project
Node-sass is a library that provides binding for Node. js to LibSass, the C version of the popular stylesheet preprocessor, Sass. It allows you to natively compile . scss files to css
Here you can read more about node-sass.
Once you fixed your path, you need to make sure that sass is correctly interpreted. To make your css (sass syntax) work you need to do two things as css is not scss:
1) Rename your .css file to .scss (yarn will show an error then)
2) Run npm install node-sass (to install sass)
npm install node-sass and add it to your project by adding --save to the command.
Related
I have this simple html and css code
#import url('https://fonts.googleapis.com/css?family=Open+Sans:400italic');
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
position: absolute; top: 50%; left: 50%; background: #121212; color: #fff;
transform: translate(-50%, -50%); font-family: "Open Sans";
}
.container {
max-width: 500px;
font-style: italic;
background: #353535;
padding: 2em; line-height: 1.5em;
border-left: 8px solid #00aeff;
}
.container span {
display: block;
color: #00aeff;
font-style: normal;
font-weight: bold;
margin-top: 1em;
}
<body>
<div class="container">
Creativity is just connecting things. When you ask creative people how they did something,
they feel a little guilty because they didn't really do it, they just saw something.
It seemed obvious to them after a while. That's because they were able to connect experiences
they've had and synthesize new things.
<span>Steve Jobs</span>
</div>
</body>
But when i view this on a mobile devices, there is some unused space left
Here in this image above there is some space left on left and right how do i make it so that only 50px is left ?
Change Body CSS Use Flex
body {
background: #121212;
color: #fff;
font-family: "Open Sans";
display: flex;
align-items: center;
justify-content: center;
min-height:100vh;
}
#import url('https://fonts.googleapis.com/css?family=Open+Sans:400italic');
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: #121212;
color: #fff;
font-family: "Open Sans";
display: flex;
align-items: center;
justify-content: center;
min-height:100vh;
}
.container {
max-width: 500px;
font-style: italic;
background: #353535;
padding: 2em; line-height: 1.5em;
border-left: 8px solid #00aeff;
}
.container span {
display: block;
color: #00aeff;
font-style: normal;
font-weight: bold;
margin-top: 1em;
}
<body>
<div class="container">
Creativity is just connecting things. When you ask creative people how they did something,
they feel a little guilty because they didn't really do it, they just saw something.
It seemed obvious to them after a while. That's because they were able to connect experiences
they've had and synthesize new things.
<span>Steve Jobs</span>
</div>
</body>
I'm building a movies site using an api.
Whe I link the css styles nothing appears to be working. Not even background color. Also i'm trying to add flex also that one is not working. Is there some problem in the linking?
It's my first question on this site and i'm still learning html and css.
#import url('https://googleapis.com/css2?family=Poppins:wght#200;400&display=swap');
:root {
--primary-color;
#22254b;
--secondary-color;
#373b69;
}
* {
box-sizing: border-box;
}
body {
background-color: purple;
font-family: 'Poppins', sans-serif;
margin: 0;
}
header {
padding: 1rem;
display: flex;
justify-content: flex-end;
}
.search {
background-color: transparent;
border: 2px solid;
border-radius: 50px;
font-family: inherit;
font-size: 1rem;
padding: 0.5rem 1rem;
color: #fff;
}
.search :placeholder {
color: #7378c5;
}
.search :focus {
outline: none;
}
main {
display: flex;
flex-wrap: wrap;
}
.movie {
width: 300px;
margin: 1rem;
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.2);
position: relative;
overflow: hidden;
border-radius: 3px;
}
.movie img {
width: 100%;
}
There are two ways to include a stylesheet:
Approach 1, using #import:
<style>
#import url("./path/to/styles.css")
</style>
If you are using #import make sure that it's at the top of the style block.
Approach 2, using <link />:
<head>
<link href="./path/to/styles.css" rel="stylesheet"/>
</head>
I've created a bit of custom code, as my friends wanted a cool hovering effect on their homepage. Since I'm quite the newbie, I was really proud I could create this flexbox-based container from scratch (granted, with a bit of help from a youtube tutorial). Now I'm struggling to integrate this in the existing blockstructure of my theme. I'm running neve as a theme, and want to replace the uppermost block (which is now simply holding a background image) with my custom HTML, styled with my custom CSS. I'm certain this should be possible, and am convinced that it's something rather simple that I'm just not getting at the moment. Please haelp a brother out. For reference, this is the site i'm trying to customize: www.thenewport.org (it's just about the frontpage picture I'm trying to replace, the one with the 5 buildings).
Here's the element I made myself: https://codepen.io/janstanna/pen/VwmKNNJ
html:
<div class ="box-zeeland" > Zeeland </div>
<div class ="box-normandie" > Normandy </div>
<div class ="box-roffa" > Rotterdam </div>
<div class ="box-Valencia" > Valencia </div>
<div class ="box-Adam" > Amsterdam </div>
<div class ="overlay" > </div>
</div> </span>
CSS:
*{
padding: 0px;
margin: 0px;
box-sizing:border-box;
}
.container{
width: 100%;
height: 1066px;
padding: 0px;
margin-top: 100px auto;
display: flex;
background; #ddd;
font-family: Helvetica;
color: white;
vertical-align: bottom;
justify-content: bottom;
align-self: flex-end;
}
.overlay {
border: 2px #ddd;
z-index: 10;
font-size: 90px;
position: absolute;
left: 300; top: 300; right: 300; bottom: 300;
/* top: 0; left: 0; */
/* width: 100%; height: 100%; */
/* display: -webkit-flex; */
/* flex-align: center; flex-pack: center; */
/* display: block; */
/* clear: both; */
background: rgba(0,0,0,0.0);
text-align: center;
color: white;
font-family: Helvetica;
font-weight: 600px;
}
.box-zeeland {
height: 100%;
padding: 0px;
background-image: url(https://elnuevopuerto.org/wp-content/uploads/2021/01/Zeeland_header_The_New_Port_Verdonkerd.jpg);
border: 3px solid #ddd;
font-size: 30px;
flex:1;
transition: 1s;
text-align: center;
align-self: flex-end;
order: 3;
}
.box-zeeland:hover{
flex:3;
background-image: url(https://elnuevopuerto.org/wp-content/uploads/2021/01/Zeeland_648x1066_DARK.jpg);
order: 3;
}
.box-normandie {
height: 100%;
padding: 0px;
background-image: url(https://elnuevopuerto.org/wp-content/uploads/2021/01/LNP_648_DARK.jpg);
border: 3px solid #ddd;
font-size: 30px;
flex:1;
transition: 1s;
text-align: center;
align-self: flex-end;
order: 1;
}
.box-normandie:hover{
flex:2;
background-image: url(https://lenouveauport.org/wp-content/uploads/2021/02/IMG_0037.jpg)
order: 1;
}
.box-roffa{
height: 100%;
padding: 0px;
background-image:url(https://elnuevopuerto.org/wp-content/uploads/2021/01/rotterdam_Website_warmer_324_Verdonkerd.jpg);
border: 3px solid #ddd;
font-size: 30px;
flex:1;
transition: 1s;
text-align: center;
order:2;
}
.box-roffa:hover {
flex:3;
background-image: url(https://elnuevopuerto.org/wp-content/uploads/2021/01/rotterdam_Website_warmer_648_DARK.jpg);
order: 2;
}
.box-Valencia{
height: 100%;
padding: 0px;
background-image: url(https://elnuevopuerto.org/wp-content/uploads/2021/01/ElNuveopuerto_Header_Valencia_324_Verdonkerd.jpg);
border: 3px solid #ddd;
font-size: 30px;
flex:1;
transition: 1s;
text-align: center;
order: 4;
}
.box-Valencia:hover {
flex:3;
background-image: url(https://elnuevopuerto.org/wp-content/uploads/2021/01/ElNuveopuerto_Header_Valencia_648_DARK.jpg);
order: 4;
}
.box-Adam{
height: 100%;
padding: 0px;
background-image:url(https://elnuevopuerto.org/wp-content/uploads/2021/01/DNPAMS001_324x1066_header_Verdonkerd.jpg);
border: 3px solid #ddd;
font-size: 30px;
flex:1;
transition: 1s;
text-align: center;
order: 5;
}
.box-Adam:hover{
flex:3;
background-image: url(https://elnuevopuerto.org/wp-content/uploads/2021/01/DNPAMS001_648_Header_DARK.jpg);
order: 5;
}
</style>```
I hope someone can help me, I've been stuck for a couple of days now! Thank in advance!
I have just tried running your code on a fresh WordPress install with the Neve theme installed.
Its all working correctly, except do not use .container as a class for the flex box, instead use something like .container-flex.
.container is already assigned to some HTML in the Neve theme.
I was unable to gain access to the site you want to use this on. But if you just need to add this onto a page, use the Custom HTML block, paste in your HTML code and save the page.
<span> <div class ="container-flex">
<div class ="box-zeeland" > Zeeland </div>
<div class ="box-normandie" > Normandy </div>
<div class ="box-roffa" > Rotterdam </div>
<div class ="box-Valencia" > Valencia </div>
<div class ="box-Adam" > Amsterdam </div>
<div class ="overlay" > </div>
</div> </span>
Then click on Customize > Additional CSS, and paste your CSS code in there and click Publish. Then your code should work as intended.
I'm trying to target the weather-location-container and location to change the text design / colour in CSS.
All my other CSS seems to be working fine. I'm not sure why it isn't working?
Thanks
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.app {
text-align: center;
background-image: url("./assets/376.png");
min-height: 100vh;
display: flex;
flex-direction: column;
}
main {
min-height: 100vh;
padding: 50px;
margin: 75px;
}
.search {
width: 100%;
}
.search .postcode-search-bar {
display: block;
width: 100%;
padding: 15px;
border: none;
background-color: rgba(255, 255, 255, 0.671);
border-radius: 16px 16px 16px 16px;
box-shadow: 3px 3px rgba(0, 0, 0, 0.2);
font-size: 1rem;
text-align: center;
transition: 0.4s ease;
}
.search .postcode-search-bar:focus {
background-color: rgba(255, 255, 255, 0.89);
}
h1::before {
content: "\01F31E";
padding: 10px;
}
h1::after {
content: "\01F30D";
padding: 10px;
}
h1 {
color: rgb(1, 55, 102);
padding: 30px;
}
/* Why isn't the below working? */
.weather-location-container .location {
color: red;
font-size: 3rem;
font-weight: 500;
text-align: center;
}
React
import "./App.css";
function App() {
let date = new Date().toDateString();
date = date.slice(3, 15);
return (
<div className="app">
<main>
<div className="search">
<h1>Local Weather</h1>
<input
type="text"
className="postcode-search-bar"
placeholder="Enter your postcode..."
/>
</div>
<div className="weather-location-container">
<div className="location">London</div>
<div className="date">{date}</div>
</div>
<div className="weather-container">
<div className="temp">8°c</div>
<div className="weather">Cloudy</div>
</div>
</main>
</div>
);
}
export default App;
try to be more specific
main .weather-location-container .location {
color: red;
font-size: 3rem;
font-weight: 500;
text-align: center;
}
The code works. After using the dev tools to inspect the div it showed the London text being in a container that was named something different.
It turns out I didn't save the app.js file - Still learning :)
It all works now.
Thanks to the comments for the tips on how to debug this
Edit: here is a CodePen with CSS / HTML
I spend the weekend creating a CSS card for a website, only to realize that it's not responsive, at all. I'm not very well versed in CSS or responsive design, so I am hoping someone with more experience can help me out. So far, I've tried playing around with the #media tag, but I have not had any success. This is the relevant CSS:
#import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
background: #ffffff;
font-family: 'Muli', sans-serif;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
.courses-container {
}
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
display: flex;
max-width: 100%;
margin: 20px;
overflow: hidden;
width: 1300px;
}
.course h6 {
opacity: 0.6;
margin: 0;
letter-spacing: 1px;
text-transform: uppercase;
}
.course h2 {
letter-spacing: 1px;
margin: 10px 0;
}
.course-preview {
background-color: #2a265f;
color: #fff;
padding: 30px;
max-width: 250px;
}
.course-preview a {
color: #fff;
display: inline-block;
font-size: 12px;
opacity: 0.6;
margin-top: 30px;
text-decoration: none;
}
.course-info {
padding: 30px;
position: relative;
width: 100%;
}
.right-container {
padding: 30px;
background-color: #fff;
width: 30%;
line-height: 200%;
}
.progress-container {
position: absolute;
top: 30px;
right: 30px;
text-align: right;
width: 150px;
}
.progress {
background-color: #ddd;
border-radius: 3px;
height: 5px;
width: 100%;
}
.progress::after {
border-radius: 3px;
background-color: #2a265f;
content: '';
position: absolute;
top: 0;
left: 0;
height: 5px;
width: 10%;
}
.progress-text {
font-size: 10px;
opacity: 0.6;
letter-spacing: 1px;
}
This is a simple suggestion, using CSS Grid. It's a two column card (as yours): the left column width-fixed (300px), the right column width-fluid. I've applied a little gap between them just to make my example clearer.
.card {
max-width: 1000px;
display: grid;
grid-template: "left right" / 300px 1fr;
background-color: #fed330;
border-radius: 10px;
height: 300px;
}
.card>* {
padding: 20px;
}
.left {
grid-area: left;
}
.right {
grid-area: right;
}
#media screen and (max-width: 700px) {
.card {
grid-template: "left" "right" / 100%;
}
}
<div class="card">
<div class="left">
Lorem ipsum....
</div>
<div class="right">
Lorem ipsum...
</div>
</div>
It could be a useful starting point.
#gaston
A good way to test and learn about CSS is to use the browser's "Inspect" feature, with which you can test the css behavior in real time.
Activating, Deactivating features, changing values, and adding new ones.
You see the result in real time.
Then just adjust your code according to your tests.
Just right-click on the area you want to inspect. and then Inspect.
You will see an area with HTML and another with CSS.
Click on the areas in HTML and see the corresponding css.
***** Then just test to find the desired result.
That's how I found the solution in your code:
In the ".course" class of your css you added the "width" property twice.
"max-width: 100%;"
"width: 1000px;"
However, the last property entered has priority over the previous ones.
"width: 1000px;" is defining that your card will ALWAYS have 1000px.
SOLUTION:
Just remove: "max-width: 100%;"
And Modify "width: 1000px;" for "max-width: 1000px;"
So your card will have a maximum of 1000px, the minimum will be defined according to the width of the window
It will look like this:
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba (0, 0, 0, 0.2);
display: flex;
margin: 20px;
overflow: hidden;
max-width: 1000px;
}
The #media function will set the css when the screen is adjusted to a minimum or maximum width chosen by you.
What is defined within #media will have priority over other css. but only when the window meets the width you set.
You can use this to change the shape of your card completely to very small screens, placing the purple part on top of the card for example.
If you've solved your problem, mark the right answer to help others.
Good luck.