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;
}
Related
<header>
<div class="max-width">
<h1>
<a href="./">
<img src="./assets/Logo.svg" alt="My Blog" />
</a>
</h1>
<ul>
<li class="profile-img">
<a href="#">
<img src="./assets/profile.jpg" alt="My Page" />
</a>
</li>
<li>
<a href="#" class="button">
<img src="./assets/icon-modify-white.svg" alt="" />
<span>Write</span>
</a>
</li>
<li>
<button class="button white">
<img src="./assets/icon-logout.svg" alt="" />
<span>Logout</span>
</button>
</li>
<li>
<a href="#" class="button gray">
<img src="./assets/icon-login.svg" alt="" />
<span>Login</span>
</a>
</li>
</div>
</header>
header {
background: var(--white-color);
}
header .max-width {
display: flex;
align-items: center;
justify-content: space-between;
gap: 4rem;
padding: 1rem 0;
}
header h1 {
font-size: 3rem;
}
header h1 a {
display: block;
padding: 0.4rem;
margin-left: -0.4rem;
}
header h1 a img {
display: block;
}
header ul {
display: flex;
align-items: center;
gap: 1rem;
}
.profile-img a {
width: 4.4rem;
height: 4.4rem;
display: block;
border-radius: 50%;
}
.profile-img img {
width: 100%;
height: 100%;
object-fit: cover;
}
header .button {
text-transform: none;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.8rem;
height: 4rem;
padding: 0.2rem 1.2em 0;
border: 0;
border-radius: var(--border-radius);
background: var(--main-color);
color: var(--white-color);
text-transform: uppercase;
font-weight: bold;
line-height: 1;
}
.button img {
height: 1.2em;
margin-top: -0.2rem;
vertical-align: middle;
}
.button.gray {
background: var(--gray-background);
color: var(--black-color);
}
.button.white {
padding: 0.2rem 0.8em 0;
background: var(--white-color);
color: var(--black-color);
}
.button.white img {
height: 1.4em;
}
I'm trying to switch the HTML, CSS codes above to React Components with styled-components.
Developing into React components, I've had a Button component which is either a button or an a element and has the same className button
I have the similar issue with Styled Components - two different elements with the same styles and tried with the answer on it but didn't work so I posted a question.
Below is what I switched with the answer.
Header.jsx
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';
import {
HeaderContainer,
MaxWidth,
H1,
NavMyBlog,
Ul,
ProfileImg,
} from './Header.element'
import {
Button,
BtnGrey,
BtnWhite,
} from '../Button/Button'
export default function Header() {
return (
<HeaderContainer>
<MaxWidth>
<H1>
<NavMyBlog to="./">
<img src={require("../../assets/Logo.svg").default} alt="My Blog" />
</NavMyBlog>
</H1>
<Ul>
{/* <!-- 로그인 --> */}
<ProfileImg>
<Link to="#">
<img src={require("../../assets/profile.jpg").default} alt="My Page" />
</Link>
</ProfileImg>
<li>
<Link to="#" className="button">
<img src={require("../../assets/icon-modify-white.svg").default} alt="" />
<span>Write</span>
</Link>
</li>
<li>
<BtnWhite className="button white">
<img src={require("../../assets/icon-logout.svg").default} alt="" />
<span>Logout</span>
</BtnWhite>
</li>
{/* <!-- //로그인 --> */}
{/* <!-- 로그아웃 --> */}
<li>
<BtnGrey to="#" className="button gray">
<img src={require("../../assets/icon-login.svg").default} alt="" />
<span>Login</span>
</BtnGrey>
</li>
<li class="only-pc">
<a href="#" className="button gray">
<img src={require("../../assets/icon-register.svg").default} alt="" />
<span>Register</span>
</a>
</li>
{/* <!--// 로그아웃 --> */}
</Ul>
</MaxWidth>
</HeaderContainer>
)
}
Header.element.jsx
import styled from 'styled-components'
import { Link } from 'react-router-dom';
export const HeaderContainer = styled.header`
background: var(--white-color);
&.button {
text-transform: none;
}
`
export const MaxWidth = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
gap: 4rem;
padding: 1rem 0;
`
export const H1 = styled.h1`
font-size: 3rem;
`
export const NavMyBlog = styled(Link)`
display: block;
padding: 0.4rem;
margin-left: -0.4rem;
img{
display: block;
}
`
export const Ul = styled.ul`
display: flex;
align-items: center;
gap: 1rem;
`
export const ProfileImg = styled.li`
Link{
width: 4.4rem;
height: 4.4rem;
display: block;
border-radius: 50%;
}
img{
width: 100%;
height: 100%;
object-fit: cover;
}
`
Button.jsx
import styled, { css } from 'styled-components'
import { Link } from 'react-router-dom';
export const Button = css`
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.8rem;
height: 4rem;
padding: 0.2rem 1.2em 0;
border: 0;
border-radius: var(--border-radius);
background: var(--main-color);
color: var(--white-color);
text-transform: uppercase;
font-weight: bold;
line-height: 1;
img {
height: 1.2em;
margin-top: -0.2rem;
vertical-align: middle;
}
`
export const BtnGrey = styled(Link)`
background: var(--gray-background);
color: var(--black-color);
`
export const BtnWhite = styled.button`
${Button}
padding: 0.2rem 0.8em 0;
background: var(--white-color);
color: var(--black-color);
img {
height: 1.4em;
}
`
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
I am trying to set the 2 columns for tablet view but for some reason the albums dont flex in row direction. I am using react an.
Can someone help me see the issue?
I leave these links for full code:
https://music-release-site-by-maria-and-daniela.netlify.app/
https://github.com/dannuzak/project-music-releases
Mobile view CSS
* {
box-sizing: border-box;
margin: 0;
text-decoration: none;
}
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #111418;
}
.header {
margin: 40px;
padding-bottom: 10px;
font-size: 0.8rem;
border-bottom: #353a45 solid 1px;
color: #fff;
}
.albums-container {
display: flex;
flex-direction: column;
align-content: center;
margin: 10%;
}
.album-card {
margin-bottom: 10%;
height: 360px;
margin-bottom: 20%;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.album-cover {
/* height: 300px;
width: 100%; */
position: relative;
}
.cover {
width: 100%;
}
#media all and (min-width: 768px) {
.albums-container {
display: flex;
width: 95%;
margin: 0;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
}
.album-card {
width: 40%;
display: flex;
flex-direction: column;
flex-wrap: wrap; // I have removed this //
}
}
---- Header component--
import React from 'react'
const Header = () => {
return (
<header className="header">
<h1>New albums & singles</h1>
</header>
);
}
--------- Album component
<>
<div className="album-card">
<div className = "album-cover">
<div className="icon-container">
<img className="icon heart" src="/icons/heart.svg" alt="heart icon"/>
<img className="icon play" src="/icons/play.svg" alt="play button icon"/>
<img className="icon dots" src="/icons/dots.svg" alt="dots icon"/>
</div>
<a href={props.urlAlbum} target= "_blank" rel="noopener noreferrer">
<img className="cover" src={props.image} alt="Album cover"/>
</a>
</div>
<div>
<a href={props.urlAlbum} target= "_blank" rel="noopener noreferrer">
<h2 className="album-name">{props.name}</h2>
</a>
</div>
<div className="album-artist">
<a href={props.urlArtist} target= "_blank" rel="noopener noreferrer">
<h2>{props.artists}</h2>
</a>
</div>
</div>
</>
export default Header;
Goal: Align items centrally in div
See picture here (notice every watch is shifted to the left):
I'm trying to render each item in productcard centrally.
Currenty, each productCard__container renders to left.
Here is my ProductCard.js code:
return (
<div className="productcard">
<button onClick={(e) => history.push(`/product/${id}`)}>
<div className="productCard__container">
<img src={image} />
<h1>{brand}</h1>
<h2>{name}</h2>
<p>${price}</p>
</div>
</button>
</div>
...and the CSS code:
.productcard {
margin: 10px;
border-radius: 12px;
background-color: black;
}
.productCard__container {
align-items: center;
}
You can use css flex box
.productcard {
display: flex;
justify-content: center;
}
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
}
}