Sibling Selectors not working correctly with Emotion - reactjs

I have the following code:
const CardContainer = styled(Flex)`
flex-direction: column;
padding: 12px;
width: 100%;
max-width: 450px;
height: auto;
border-radius: 32px;
overflow: hidden;
z-index: 1;
background: rgba(218, 228, 242);
box-shadow: 4px 4px 12px 2px rgba(black, 0.6);
transition: 0.2s;
&:not(:first-child) {
background: red;
margin-left: -50px;
}
&:hover,
&:focus-within {
transform: translatey(-1rem);
}
&:hover ~ &,
&:focus-within ~ & {
transform: translatex(50px);
}
`;
But the last statement is not working. The CSS code that I'm trying to copy is:
.card:hover ~ .card,
.card:focus-within ~ .card {
transform: translatex(50px);
}
And here is the original codepen:
https://codepen.io/toddwebdev/pen/yWMgQX?editors=1100

You need to do this instead:
& + ${() => CardContainer} {
transform: translateX(var(--distance));
}
Also your import styled from "#emotion/styled has to be import styled from "#emotion/styled/macro in order to support the above.
Note: changed the styled(Flex) to styled("section") to prevent errors in sandbox
import styled from "#emotion/styled/macro";
import "./styles.css";
const CardContainer = styled("section")`
flex-direction: column;
padding: 12px;
width: 100%;
max-width: 450px;
height: auto;
border-radius: 32px;
overflow: hidden;
z-index: 1;
background: rgba(218, 228, 242);
box-shadow: 4px 4px 12px 2px rgba(black, 0.6);
transition: 0.2s;
&:not(:first-of-type) {
margin-left: -50px;
}
&:hover,
&:focus-within {
transform: translateY(-1rem);
& + ${() => CardContainer} {
transform: translateX(var(--distance));
}
}
`;
export default function App() {
return (
<div className="cards">
<CardContainer>
<div className="card">
<h1>
Title
</h1>
<p>This is an article and this has some content.</p>
</div>
</CardContainer>
<CardContainer>
<div className="card">
<h1>
Title
</h1>
<p>This is an article and this has some content.</p>
</div>
</CardContainer>
<CardContainer>
<div className="card">
<h1>
Title
</h1>
<p>This is an article and this has some content.</p>
</div>
</CardContainer>
<CardContainer>
<div className="card">
<h1>
Title
</h1>
<p>This is an article and this has some content.</p>
</div>
</CardContainer>
<CardContainer>
<div className="card">
<h1>
Title
</h1>
<p>This is an article and this has some content.</p>
</div>
</CardContainer>
</div>
);
}

Related

Reactjs Accordion Bullet

How do I make background color of "-" bullet expand when I active the content.
Image 1 is what I want to do while Image 2 is what I do...
Want to be like tis
[1]
(https://i.stack.imgur.com/5NDOX.png)
My Demo
[2]
(https://i.stack.imgur.com/0ztPK.png)
My Js Code
`
const [isActive, setIsActive] = useState(false);
<div className="support">
<div className='containerFour'>
<h1>FAQ</h1>
<h1>Tell us what you're searching for</h1>
<div className="accordion">
<div className="accordionItem">
<div className="accordionTitle" onClick={() => setIsActive(!isActive)}>
<h1 className='accordionH'>What payment methods are available to complete your purchase?</h1>
<div className='accordionBullet'>{isActive ? <img src={Close} /> : <img src={Open}/>}</div>
</div>
{isActive && <div className="accordionContent">Test</div>}
</div>
</div>
</div>
</div>
`
My Css
.support .accordion {
width: 811px;
margin-left: auto;
margin-right: auto;
}
.support .accordionItem {
margin-bottom: 1.5rem;
}
.support .accordionBullet{
background-color: #205696;;
padding-top: 1rem;
}
.support .accordionTitle {
display: flex;
flex-direction: row;
justify-content: space-between;
cursor: pointer;
background-color: #D9D9D9;;
}
.support .accordionH{
font-family: 'Urbanist';
font-style: normal;
font-weight: 700;
font-size: 24px;
line-height: 29px;
color: #000000;
}
.support .accordionTitle:hover {
background-color: #D9D9D9;;
}
.support .accordionContent {
background-color: #D9D9D9;
}
Currently, the accordionBullet is inside the accordionTitle. Its maximum height = height of the h1 heading only.
Put accordionBullet beside accordionItem so that it can expand with its height.
<div className="accordion">
<div className="accordionItem">
... (Title + Content) ...
</div>
<div className="accordionBullet">
...
</div>
</div>
.accordion {
display: flex;
}

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.

How do I add a font aswesome's className or id in React

I tried to add an className in fontawesome and give a property(width,padding,fontsize, etc)in the sass but it didn't work what I expected.
Is there any syntax give a className or id in the fa react? It works when I give a div+className and using flexbox but you know this is pretty not a good way if we can use className or id. I will leave my code below!
!
or
didn't work...
This is my whole main.js file! I will leave my part of my code(my question part)
import React, { Component } from "react";
import "./Main.scss";
import "./Common.scss";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
import {
faHeart,
faComment,
faPaperPlane,
faBookmark,
faEllipsisH,
} from "#fortawesome/free-solid-svg-icons";
// import { FaRegComment } from "#fortawesome/free-solid-svg-icons";
// how to impport this faRegComment?
class Main extends Component {
render() {
return (
<>
<div class="main-wrapper">
<div class="nav">
<p class="logo"> Westagram </p>
<input
class="search-box"
type="text"
placeholder=" Search"
/>
{/* ,style="font-family:Arial, FontAwesome */}
<div class="icons">
<img
id="compass"
src="https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/explore.png"
/>
<img
id="heart"
src="https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/heart.png"
/>
<img
id="my-page"
src=" https://s3.ap-northeast-2.amazonaws.com/cdn.wecode.co.kr/bearu/profile.png"
/>
</div>
</div>
<div class="main">
<div class="feeds">
<div class="article">
<div class="identi">
<img class="selfi-identi" src="/images/about.png" />
<span class="name"> Jiwan Jeon </span>
{/* <i id="test" class="fa fa-ellipsis-h" aria-hidden="true"></i> */}
<div class="faEllipsisH">
<FontAwesomeIcon icon={faEllipsisH}></FontAwesomeIcon>
</div>
</div>
<div class="pic">
<img id="feed-pic" src="/images/ucscPic.png" />
</div>
<div class="show-box">
<div class="reaction-icons">
<FontAwesomeIcon icon={faHeart}></FontAwesomeIcon>
<FontAwesomeIcon icon={faComment}></FontAwesomeIcon>
<FontAwesomeIcon icon={faPaperPlane}></FontAwesomeIcon>
<FontAwesomeIcon icon={faBookmark}></FontAwesomeIcon>
</div>
<div class="like-counts">
<span>like 4,000</span>
</div>
<div class="check-comments">
<span>
UC Santa Cruz will continue to offer most courses remotely
or online for spring and summer 2021, providing in-person
instruction for a small
</span>
<a id="space" href="">
expanding
</a>
<br />
Check the all comments
<ul class="feed-comments">
<li>test</li>
</ul>
</div>
</div>
<div class="comment">
<i class="fa fa-smile-o"></i>
<input
class="user-input"
type="text"
placeholder="Add Comment..."
/>
<button class="post">Post</button>
</div>
</div>
</div>
</div>
<div class="main-right">
<div class="top">
<img class="selfi" src="/images/about.png" />
<div class="main-right-name">
<span id="eng-name">JiwanJeon94</span>
<br />
<span id="kr-name">전지완</span>
</div>
Transform
</div>
<div class="middle">
<div class="middle-words">
<span id="recommendation">Suggestions For You</span>
<a href="" id="view-all">
view all
</a>
</div>
<div class="recommendation-people">
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
<div id="recommendation-section1">
<img
id="recommendation-people-selfi"
src="/images/about.png"
/>
<span>Recommendation for you</span>
Follow
</div>
</div>
</div>
<div class="footer">
<div class="footer-top">
About
Help
press
API
Jobs
Privacy
Terms
Locations
TopAccounts
Hashtags
Language
<br />
<br />
</div>
<span>2021 INSTAGRAM FROM FACEBOOK</span>
</div>
</div>
</div>
</>
);
}
}
export default Main;
This is my fa icons part
<div class="show-box">
<div class="reaction-icons">
<FontAwesomeIcon icon={faHeart}></FontAwesomeIcon>
<FontAwesomeIcon icon={faComment}></FontAwesomeIcon>
<FontAwesomeIcon icon={faPaperPlane}></FontAwesomeIcon>
<FontAwesomeIcon icon={faBookmark}></FontAwesomeIcon>
</div>
I Will leave sass file just in case
#font-face {
font-family: instagramFont;
src: url("./westagram.ttf") format("opentype");
}
#mixin icon-size() {
width: 30px;
height: 30px;
}
#root {
height: 100vh;
.main-wrapper {
margin: 10px 10px 10px 10px;
height: 100%;
.nav {
position: fixed;
display: flex;
flex-direction: row;
justify-content: space-around;
width: 100%;
padding-top: 20px;
padding-bottom: 10px;
border-bottom: solid 1px #dbdbdb;
z-index: 9999;
.logo {
font-family: instagramFont;
padding-right: 100px;
font-size: 2rem;
}
.search-box {
margin-top: 5px;
width: 250px;
// main css파일이랑 똑같이 세팅 했는데 개발자툴이랑 왜 다른지 -해결-
height: 28px;
}
.icons {
margin-left: 100px;
#compass {
#include icon-size();
//30*30 으로 세팅했는데 개발자툴에서는 왜 53*53인지
}
#heart {
#include icon-size();
}
#my-page {
#include icon-size();
}
}
}
.main {
position: relative;
top: 70px;
left: 8px;
width: 100%;
height: 100%;
.feeds {
position: relative;
top: 40px;
right: 5px;
left: 61px;
width: 60%;
.article {
position: absolute;
display: flex;
flex-direction: column;
width: 614px;
height: 954px;
padding-bottom: 10px;
.identi {
position: relative;
display: flex;
flex-direction: row;
align-items: flex-start;
height: 50px;
.selfi-identi {
width: 30px;
height: 30px;
// padding: 15px 20px 20px 20px;
border-radius: 50%;
}
.name {
margin-top: 10px;
margin-left: 5px;
}
#test {
padding-top: 23px;
padding-left: 410px;
}
.faEllipsisH {
padding-top: 10px;
padding-left: 40px;
// padding-bottom: 20px;
}
}
.pic {
#feed-pic {
position: relative;
padding: 3px 3px 3px 3px;
width: 614px;
height: 614px;
padding: 5px 0px 2px 0px;
}
}
.show-box {
position: relative;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 170px;
padding: 5px 0px 20px 0px;
.reation-icons {
#heartShowBox {
padding-left: 10px;
font-size: 30px;
width: 30px;
}
.fa-comment-o {
padding-left: 10px;
padding-right: 5px;
}
.fa-send-o {
padding-left: 10px;
font-size: 30px;
}
.fa-bookmark-o {
padding-left: 450px;
font-size: 30px;
}
}
.like-counts {
margin-top: 10px;
padding-top: 20px;
}
.check-comments {
.space {
padding-top: 400px;
}
}
}
.comment {
position: relative;
// margin-top: 75px;x
.fa-smile-o {
font-size: 30px;
}
.user-input {
width: 530px;
height: 20px;
}
.post {
height: 25px;
border: solid 1px #d3d3d3;
border-radius: 5px;
background-color: #b2dffc;
font-size: 15px;
cursor: pointer;
}
}
}
}
}
.main-right {
position: fixed;
width: 28%;
height: 98%;
top: 11.9%;
right: 4%;
.top {
position: relative;
display: flex;
flex-direction: row;
padding-bottom: 3px;
.selfi {
width: 50px;
height: 50px;
padding: 15px 20px 20px 20px;
border-radius: 50%;
}
.main-right-name {
position: relative;
padding-top: 25px;
#kr-name {
opacity: 0.3;
}
}
a {
margin-left: 40px;
margin-top: 20px;
}
}
.middle {
height: 30%;
padding-bottom: 100px;
.middle-words {
padding-bottom: 25px;
#recommendation {
margin-left: 23px;
}
#view-all {
margin-left: 70px;
}
}
.recommendation-people {
display: flex;
flex-direction: column;
#recommendation-section1 {
#recommendation-people-selfi {
width: 30px;
height: 30px;
margin-top: 13px;
padding: 5px 5px 5px 5px;
border-radius: 50%;
}
span {
position: relative;
right: 5px;
top: -18px;
}
a {
position: absolute;
right: 3px;
font-size: 14px;
}
}
}
}
.footer {
margin-left: 10px;
.footer-top {
.a {
margin: 0px 0px 0px 5px;
opacity: 0.3;
}
}
}
span {
margin-left: 5px;
opacity: 0.3;
}
}
}
}
For the first, replace all class with className.
className work fine with FontAwesomeIcon:
<FontAwesomeIcon icon={faHeart} className="awesome-custom"></FontAwesomeIcon>;
Chech this example: https://codesandbox.io/s/cold-frost-bv362?file=/src/App.js

Why CSS(sass) calc() method doesn't work in React?

At first look at my codes:
JSX:
import React from "react";
import "./styles.scss";
export default function App() {
return (
<div className="App">
<h1> This is a Portfolio Item </h1>
<div className="item-container">
<div className="img-container">
<img
src="https://tf-react-chester.now.sh/images/portfolio-image-5.jpg"
alt="Portfolio 1"
/>
</div>
<h3>This is the Title of Item </h3>
<h4>
This is the description of Item. This is the description of Item.{" "}
</h4>
</div>
</div>
);
}
And CSS(SASS):
.App {
.item-container {
width: 100%;
height:auto;
.img-container {
position: relative;
$margin: 20px;
&::before{
position: absolute;
content: '';
**width: calc(100%-20px);
height: calc(100%-20px);** /* These two line don't work. */
left: 10px;
top: 10px;
background-color: #fff;
transition: all 0.5s ease-in-out;
transform: scaleX(0);
transform-origin: 0;
}
&:hover {
transform: scaleX(1);
}
img{
max-width: 100%;
}
}
}
}
I am trying to create a ::before animated content over the image. But when I am using calc() method it doesn't work at all.
What's the reason?
Note: I have tried some solution to the same problem from StackOverflow but those don't work for me.
This is the codesandbox link:CodeSandBox
Try with spaces ;)
width: calc(100% - 20px);
height: calc(100% - 20px);

How to make div's inline in particular screen by using media queries

I am working on a react project, I am trying to make this project responsive for mobiles, tablets and laptops. Currently, mobile and tablet screens are responsive, but on a laptop screen of size 1024px, the div's are behaving like a display block. However, I want all divs side by side when there is a laptop screen of size 1024px.
How can I achieve this? Here is my code.
This is App.js
import React from 'react';
import './App.css';
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome'
import { faUser } from '#fortawesome/free-solid-svg-icons'
function App() {
return (
<div className='container-fluid'>
<div className='row'>
<div className='col-12'>
<div className='content text-center'>
<h3 className='one'>One million success stories.
<span className='start'>Start yours today.</span>
</h3>
</div>
<div className='col-12 col-lg-5 main'>
<input type='text' className='inputtagcommonstyle' placeholder='Enter Skills or job title'></input>
</div>
<div className='col-12 col-lg-3 '>
<select className='inputtagcommonstyle removebackgroundcolor'>
<option>Select Categories</option>
<option>Marketing</option>
<option>Teaching & Education</option>
</select>
</div>
<div className='col-12 col-lg-2 '>
<select className='inputtagcommonstyle removebackgroundcolor'>
<option>Select City</option>
<option>New York</option>
<option>San Joes</option>
</select>
</div>
<div className='col-12 col-lg-2 '>
<input type='submit' className='btn' value='Search Job'></input>
</div>
<div className='col-12 getstarted'>
<a href='www.facebook.com'>
<FontAwesomeIcon icon={faUser} /> Get Started Now
</a>
</div>
</div>
</div>
</div>
);
}
export default App;
This is App.css
#import url('https://fonts.googleapis.com/css?family=Roboto&display=swap');
.one {
font-family: 'Roboto', sans-serif;
font-weight: 600;
font-size: 36px;
}
.start {
display: block;
}
.inputtagcommonstyle {
height: 50px;
border-radius: 0;
padding: 13px 15px;
font-size: 18px;
width: 100%;
color: #555;
}
.removebackgroundcolor {
background-color: white;
}
#media only screen and (max-width: 768px) {
.inputtagcommonstyle {
margin-bottom: 15px;
}
}
#media only screen and (min-width:768px) and (max-width:1024px) {
}
.btn {
width: 100%;
background-color: #263bd6 !important;
border-radius: 0 !important;
color: #fff !important;
border: none;
font-size: 16px;
text-transform: uppercase;
font-weight: 700 !important;
padding: 14px 20px !important;
font-family: 'Roboto', sans-serif;
}
.getstarted {
text-align: center;
margin-top: 50px;
font-family: 'Roboto', sans-serif !important;
}
.getstarted a {
border: 3px solid #263bd6;
padding: 12px 25px;
color: red;
font-size: 18px !important;
font-weight: 700;
font-family: 'Roboto', sans-serif !important;
display: inline-block;
}
a {
transition: 0.3s ease-in-out;
transition-property: all;
transition-duration: 0.3s;
transition-timing-function: ease-in-out;
transition-delay: 0s;
}
If anything is unclear or extra informations is needed please comment
#media only screen and (min-width:768px) and (max-width:1024px) {
.yourParentDivClass: { //parent class of divs which you want side by side
display: flex
}
}

Resources