Skip to content

Instantly share code, notes, and snippets.

View marekrozmus's full-sized avatar
👻

Marek Rozmus marekrozmus

👻
View GitHub Profile
@marekrozmus
marekrozmus / responsive-image-react.jsx
Last active February 18, 2024 19:01
Responsive image React
<p className="pt-4">The responsive image</p>
<picture>
<source
media="(min-width: 1024px)"
srcSet={desktopBackground}
/>
<source
media="(min-width: 640px)"
srcSet={tabletBackground}
/>
@marekrozmus
marekrozmus / responsive-bg-usage.jsx
Created February 18, 2024 17:23
Responsive background react component usage
const mainDivRef = React.useRef<HTMLDivElement>(null);
...
<div
ref={mainDivRef}
className="
bg-no-repeat
bg-contain
bg-center
@marekrozmus
marekrozmus / responsive-bg-react.jsx
Created February 18, 2024 17:20
React component for responsive background
...
React.useEffect(() => {
if (parentRef && parentRef.current) {
parentRef.current.style.setProperty("--bg-mobile", mobileFileUrl);
parentRef.current.style.setProperty("--bg-tablet", tabletFileUrl);
parentRef.current.style.setProperty("--bg-desktop", desktopFileUrl);
parentRef.current.classList.add("bg-background-set");
}
@marekrozmus
marekrozmus / set-css-variables-with-ref.js
Created February 18, 2024 01:22
Setting CSS variables with ref
parentRef.current.style.setProperty("--bg-mobile", mobileFileUrl);
parentRef.current.style.setProperty("--bg-tablet", tabletFileUrl);
parentRef.current.style.setProperty("--bg-desktop", desktopFileUrl);
@marekrozmus
marekrozmus / bg-variables.css
Created February 18, 2024 00:44
Backgrounds CSS with variables
:root {
--bg-mobile: none;
--bg-tablet: none;
--bg-desktop: none;
}
.bg-background-set {
background-image: var(--bg-mobile);
}
@marekrozmus
marekrozmus / bg-images-in-css.css
Last active February 18, 2024 00:45
Background images in CSS
.bg-simple-set {
background-image: url('../assets/mobile.jpg');
}
@media screen and (min-width: 640px) {
.bg-simple-set {
background-image: url('../assets/tablet.jpg');
}
}
@marekrozmus
marekrozmus / bg-tailwind-dynamic.jsx
Created February 18, 2024 00:33
Background tailwind concatenate class name
<div
className={`
bg-no-repeat
bg-contain
bg-center
bg-[url('${mobileBackground}')]
sm:bg-[url('${tabletBackground}')]
lg:bg-[url('${desktopBackground}')]
h-48 w-96`}
/>
@marekrozmus
marekrozmus / bg-inline.jsx
Created February 18, 2024 00:11
Background inline styles
<div
className="
bg-no-repeat
bg-contain
bg-center
h-48 w-96"
style={{
backgroundImage: `url('${mobileBackground}')`,
}}
/>
@marekrozmus
marekrozmus / tailwin-bg.html
Created February 18, 2024 00:00
tailwind background
<div className="
bg-no-repeat
bg-contain
bg-center
bg-[url('./assets/mobile.jpg')]
sm:bg-[url('./assets/tablet.jpg')]
lg:bg-[url('./assets/desktop.jpg')]
h-48 w-96" />
@marekrozmus
marekrozmus / script_main_param.js
Created December 6, 2023 15:03
script that is run only if some param exists
function main() {
...
}
// to run only if specific param ('run') is added to package.json script
if (process.argv.includes('run')) {
main();
}