I'm using react on a project and I'm trying to figure out how to make a combination of two clip path. But they are interacting in some way. if I deactivate the css line (clip) of the parent component the clip-path work fine on the child component but if both work at the same time I get a visual error. The backdrop blur doesn't get the masking and the background color works fine.
// Initial State
// Disabling parent clip-path
// HTML(JSX) parent
import React from 'react'
import ImgSlider from '../config/ImgSlider'
import logoWhite from '../img/logo-white.png'
export default function start() {
return (
<div className="container-inside" >
<div className='container-start'>
<h1 style={{color: 'white'}}>¡Personalizá tu regalo!</h1>
<div className='button-start'>
<svg className='svg'>
<defs>
<clipPath id="starClip" clipPathUnits="objectBoundingBox"><path d="M0.5,0.76 L0.277,1 L0.321,0.672 L0,0.643 L0.278,0.474 L0.099,0.198 L0.401,0.315 L0.5,0 L0.599,0.315 L0.901,0.198 L0.722,0.474 L1,0.643 L0.678,0.671 L0.722,0.999 L0.5,0.76"></path></clipPath>
</defs>
</svg>
<button className="starClip">
<h2>start</h2>
</button>
</div>
<img className='logo' alt="logo"/>
</div>
<ImgSlider />
</div>
);
}
// CSS parent
.clipped {
justify-content: center;
width: 100%;
height: 87vh;
background: #F2E9DB;
background-size: cover;
-webkit-clip-path: url(#my-clip-path);
clip-path: url(#my-clip-path);
z-index: 1;
overflow: hidden;
}
// HTML(JSX) child
import React from 'react'
import ImgSlider from '../config/ImgSlider'
import logoWhite from '../img/logo-white.png'
export default function start() {
return (
<div className="container-inside" >
<div className='container-start'>
<h1 style={{color: 'white'}}>¡Personalizá tu regalo!</h1>
<div className='button-start'>
<svg className='svg'>
<defs>
<clipPath id="starClip" clipPathUnits="objectBoundingBox"><path d="M0.5,0.76 L0.277,1 L0.321,0.672 L0,0.643 L0.278,0.474 L0.099,0.198 L0.401,0.315 L0.5,0 L0.599,0.315 L0.901,0.198 L0.722,0.474 L1,0.643 L0.678,0.671 L0.722,0.999 L0.5,0.76"></path></clipPath>
</defs>
<g className="starClip" clipPath="url(#starClip)">
<button>
<h2>start</h2>
</button>
</g>
</svg>
</div>
<img className='logo' alt="logo"/>
</div>
<ImgSlider />
</div>
);
}
// CSS Child
.container-inside{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
.container-start{
display: flex;
position: absolute;
flex-direction: column;
justify-content: space-around;
align-items: center;
width: 100%;
height: 100%;
z-index: 19;
}
.button-start{
z-index: 10;
position: absolute;
}
.starClip {
background-color: rgba(0, 0, 0, 0.186);
box-shadow: 0.5vh 0.5vh 1.3vh rgba(0, 0, 0, 0.1), inset 0.5vh 0.5vh 2vh rgba(0, 0, 0, 0.1) ;
height: 20vh;
width: 20vh;
-webkit-backdrop-filter: blur(5px);
backdrop-filter: blur(5px);
-webkit-clip-path: url(#starClip);
clip-path: url(#starClip);
z-index: 15;
}
Related
In my React.js project, I'm trying to implement a common layout file for my components.
Here is that file:
import React from "react";
import SideBar from "./SideBar/SideBar";
import Navbar from "./Navbar/Navbar";
import { useSidebarStore } from "/zustand";
import classes from "./CustomUserLayout.module.css";
const CustomUserLayout = ({ children }) => {
const sideBarState = useSidebarStore((state) => state.sideBar);
const toggleSideBar = useSidebarStore((state) => state.toggleSideBar);
return (
<div className={classes.container}>
<SideBar isOpen={!sideBarState} hideSideBar={toggleSideBar} />
<div className={classes.mainWrapper}>
<Navbar isSidebarOpen={sideBarState} toggleSideBar={toggleSideBar} />
<div className={`${sideBarState ? "container" : ""}`}>
<div className={classes.wrapper}>{children}</div>
</div>
</div>
</div>
);
};
export default CustomUserLayout;
And here is its CSS file:
.container {
display: flex;
}
.mainWrapper {
flex: 5;
}
.wrapper {
background-color: #fff;
padding-top: 80px;
padding-bottom: 40px;
}
My Sidebar layout:
const Sidebar = ({isSidebarOpen,toggleSidebar}) => {
return (
<section className={classes.container} hidden={!isSidebarOpen}>
<div className={classes.topSection}></div>
<div className={classes.middleSection}></div>
<div className={classes.bottomSection}>
// contains logout div
</div>
</section>
);
}
export default Sidebar
Important part of my sidebar css:
.container {
flex: 1;
background-color: #fff;
box-shadow: 0px 0px 4px 2px rgba(0, 0, 0, 0.1);
}
Here is the reult:
However I'm getting a couple of bugs:
The first is as i'm trying to scroll down my sidebar overflows, I tried solving this by adding position: sticky; top: 0; overflow-y:hidden; to the sidebar container class but that didn't work. Basically what I'm trying to achieve is have that sidebar completely still kind of like as if it had a position sticky however I don't want to use position sticky.
My 2nd problem is the content on the right side of my navbar its overflowing:
My header component:
import Image from "next/image";
const Navbar = ({ isSidebarOpen, toggleSideBar }) => {
return(
<section className={classes.container}>
<div className={`container ${classes.wrapper}`}>
<div></div>
<div className={classes.profile}>
<Image src={"some-img-src"} alt="alt" layout="fill" />
</div>
</div>
</section>
);
}
export const Navbar;
Navbar css:
.container {
position: fixed;
z-index: 200;
width: 100%;
height: 80px;
background: #ffffff;
box-shadow: 0px 0px 4px 2px rgba(0, 0, 0, 0.1);
}
.wrapper {
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.profile{
position: relative;
cursor: pointer;
width: 23px;
height: 28px;
}
I believe the problem is cause because I have the position of the nabvar container as fixed and I'm giving it a width of 100%, however I don't know how to fix it
[I created a card component which has wrapper div to wrap cards in it, the cards are display fine 1 in a row, however I want to display 3 in a row and unable to do it. I have tried display flex to show 1 in a row.
Cards component
import React from "react";
import "../index.css";
const Card = (props) => {
return (
<>
<div className="cards">
<div className="card">
<img src={props.imgSrc} alt="Dark" className="card-img" />
<div className="card-info">
<span className="card-category">{props.cat}</span>
<h3 className="card-title">{props.title}</h3>
<a href={props.link}>
<button>watch now</button>
</a>
</div>
</div>
</div>
</>
);
};
export { Card };
Index
import react from "react";
import ReactDOM from "react-dom";
import { Whole } from "./Whole";
import { Cards } from "./learningReact/Cards";
ReactDOM.render(
<>
<Cards />
</>,
document.getElementById("root")
);
css
cards {
display: flex;
justify-content: center;
align-content: center;
margin: 100px auto;
}
.card {
width: 250px;
height: 300px;
border: none;
background: rgb(248, 239, 248);
border-radius: 10px;
}
.card img {
width: 250px;
height: 200px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.card:hover {
transform: scale(1.1);
}
you should use flex-basis:33%; for .card div tag and flex-wrap:no-wrap; & justify-content: space-between; for .cards div tag:
.cards {
display: flex;
justify-content: space-between;
align-content: center;
margin: 100px auto;
flex-wrap:nowrap;
}
.card {
flex-basis:33%;
height: 300px;
border: none;
background: rgb(248, 239, 248);
}
<style>
.card-data {
display: flex;
flex-wrap: nowrap;
background-color: #000;
}
.card-data div {
background-color: #f1f1f1;
width: 33%;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
</style>
<div class="card-data">
<div>Hello..</div>
<div>Test...</div>
<div>Content..</div>
</div>
Replace the justify-content: center with justify-content: space-between inside .cards block and it will be displayed in a single row.
output here
I have set up a carousel with a display flex:1 the idea being to make it take up as much height as available to it which works as intended(can be tested by setting a fixed height for the div(.image-iframeContainer) contained in it). but whenever I try and set this div to be 100% of the carousel height instead of the content scaling to fit the size of the carousel, the carousel will instead scale to the 100% of the size of the content(test this by stretching the aspect ratio). how do I fix/stop this happening?
reactjs
<div className="Cards">
<Carousel
showThumbs={false}
infiniteLoop={true}
swipeable={false}
dynamicHeight={false}
>
<div>
<div className="image-iframeContainer">
<img src={IMG} />
</div>
</div>
<div>
<div className="image-iframeContainer">
<img src={IMG} />
</div>
</div>
<div>
<div className="image-iframeContainer">
<img src={IMG} />
</div>
</div>
</Carousel>
<h1>{Projects.workName}</h1>
{Projects.workTech.map((Tech, index) => {
return <p>Technology used: {Tech}</p>;
})}
<p>{Projects.workDescription}</p>
</div>
Sass
.Cards {
position: absolute;
width: 50%;
height: 80%;
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.2);
margin-left: auto;
margin-right: auto;
margin-top: 10%;
left: 0;
right: 0;
border-radius: 7px;
overflow: hidden;
background: #7510f7;
display: flex;
flex-direction: column;
.image-iframeContainer {
display: flex;
width: 100%;
//setting a fixed height for this div allows for flex scaling of the carousel
height: 400px;
//height: 100%;
background: greenyellow;
overflow: hidden;
img {
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
object-fit: cover;
background-repeat: no-repeat;
margin: auto;
}
iframe {
position: absolute;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100px;
border: 0;
}
}
.carousel-root{
flex:1;
}
.carousel {
z-index: 0;
}
.carousel, .slider-wrapper, .slider {
height: 100%;
}
.slide{
display: flex;
justify-content: center;
}
.carousel.carousel-slider {
.control-arrow {
padding: 15%;
opacity: 0%;
}
}
}
sandbox link
https://codesandbox.io/s/sleepy-sunset-jqjst?file=/src/styles.scss:478-500
To avoid confusion these are swipe cards layered on top of each other hence the absolute positioning, in my actual project images are injected dynamically I do not want to crop or stretch images this is why I've picked this implementation with borders the containing div will give back colour to the bezels around the picture.
I have a small css issue in my react app, but I can't find a way to fix it.
The background of my div is always white no matter the color I set (Hex, rgb or rgba). Even the border-radius is not working but width/height and margins are working perfectly fine.
Here's my code :
card.js
import React from "react";
import "../styles/card.css";
export default class Cards extends React.Component {
render() {
return (
<div className="card">
<img src="../images/cards/BR-Customcard-back.png" alt="card" />
<span>Card Name</span>
</div>
);
}
}
card.css :
.card {
background-color: rgba(107, 66, 30, 0.4);
width: 282px;
height: 417px;
margin: 10px auto 10px auto;
text-align: center;
border-radius: 20px;
}
Parent element, cards.js :
import React from "react";
import "../styles/cards.css";
import Card from "./Card";
export default class Cards extends React.Component {
render() {
return (
<div className="cards" style={{ padding: "10px" }}>
<Card />
<Card />
<Card />
</div>
);
}
}
cards.css
.cards {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
rendered css :
.card {
position: relative;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
border: 1px solid rgba(0,0,0,.125);
border-radius: .25rem;
}
.card {
background-color: rgba(107, 66, 30, 0.4);
width: 282px;
height: 417px;
margin: 10px auto 10px auto;
text-align: center;
border-radius: 20px;
}
rendered markup :
<div class="cards">
<div class="card">
<img src="../images/cards/BR-Customcard-back.png" alt="card">
<span>Card Name</span>
</div>
....
</div>
The class name you set on the component is not the same class name as you defined in the CSS file; it should be:
className="card"
Found the issue, I'm using the card class which is already defined in react or bootstrap.
I renamed my class customCard and it's working.
Thanks for the help
<body>
<div class="home">
<div class="title-header">
<div>HEADER</div>
</div>
<div class="main">
<div class="left-pane">
<div class="content">
<!-- SVG overflows the container on resize -->
<svg height="100%" width="100%" viewbox="0 0 200 200" preserveAspectRatio="xMidYMin meet">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>
<!-- Using a Div instead works great!
<div style="width: 100%; height: 100%; background-color: white">
</div> -->
</div>
</div>
<div id="rightpane" class="right-pane">
<button onClick="toggleSize()">Resize</button>
</div>
</div>
</div>
<div class="footer">
<div>FOOTER</div>
</div>
</body>
</html>
.home {
display: flex;
flex-direction: column;
width: 1000px;
height: 800px;
background-color: lightgray;
}
.title-header {
width: 100%;
display: flex;
flex: 0 0 35px;
height: 35px;
background-color: lightblue;
align-items: center;
justify-content: center;
}
.main {
display: flex;
width: 100%;
flex: 1;
background-color: lightgreen;
}
.left-pane {
display: flex;
flex: 1;
flex-direction: column;
background-color: white;
}
.right-pane {
flex: 0 0 350px;
width: 350px;
border-left: 1px solid lightgray;
&.min {
flex: 0 0 100px;
width: 100px;
}
}
.content {
width: 100%;
height: 100%;
background-color: yellow;
}
.footer {
display: flex;
position: absolute;
top: 810px;
left: 0px;
flex: 0 0 35px;
width: 1000px;
height: 35px;
border: 1px solid black;
align-items: center;
justify-items: center;
}
Example is here: https://codepen.io/johnny4111/pen/ZEYNqyq
I have a structure as in the example, it's a container that has a left and right pane. The right pane can be minimized programmatically. The Left pane has an SVG set to take up 100% height and 100% width. The left pane has flex-grow set to 1 so that it takes up 100% of the free height but should not exceed the bounds of it's parent div.
The expectation is when the right pane is minimized and the left pane expands it's width to take up the now available free space the SVG should still constrain itself to the available height (100% height) since the height has not changed, just the width. However, in reality it overflows the div. There is a absolute positioned footer at the bottom so you can see it overflows into that.
Any ideas what the problem is? If I use a regular div set to 100% width, 100% height instead of an SVG it works without any issues. The Div does not overflow it's parent.