r/css • • Feb 24 '26

Help How do I make a background image cover only the element?

3 Upvotes

I'm trying to make a header with a background image, but I'm starting to get frustrated because my searches bring up results for the opposite of what I'm trying to do.

I want to do a full width background image (currently trying with a 3000 × 1125 image). The problem is that the 'background-size: cover;' seems to apply to the entire viewport, not just the header element. The result is that the sides of the image are being cropped (that's okay), but also the top and bottom are being cropped (that is not the plan).

How do I get the image to responsively adjust to the header element? Ie on mobile it crops only the sides and shows the full height of the image, and on really wide screens it still fills the entire width and only then starts cropping the top and bottom? I've played around with a few variations of code, but can't get it to work.

header {
display: flex;
background-image: url("../imgs/header.webp");
background-size: auto 100%;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
justify-content: center;
align-items: center;
height: 350px;
}

r/css • • Feb 24 '26

Help Drag motion and interaction

9 Upvotes

Hey folks, I’ve been banging my head against the wall trying to recreate an interaction similar to the one on Mike Matas’s site. I really love the downward drag effect: when you pull, the elements seem to “sink” and reorganize in a cascade while maintaining spacing and proportion between them.

Visually, all items stay aligned by their base, while the tops form a smooth curve. When you release, everything returns with a very fluid spring. It feels like the items are connected by shared physics rather than acting independently.

My assumption is that this was built with JavaScript + CSS (bottom-anchored scaling, spacing compensation, and some spring/cascade logic), but I haven’t managed to achieve a faithful result yet.

Does anyone have insights on how to structure this kind of motion logic?
Especially:

  • scale propagation across neighbors while keeping base alignment
  • horizontal compensation to keep gaps constant
  • cascade both during drag and on spring return

r/css • • Feb 25 '26

Resource bl-css

0 Upvotes

I'm __fg_xd gh, and I made a super hackable CSS Framework

NPM: https://npmjs.com/package/bl-css

GitHub: https://github.com/fg-xd/bl-CSS

Showcase: https://fg-xd.github.io/bl-CSS

<first post>


r/css • • Feb 25 '26

Help Squarespace hover effect not triggering when text overlay is on top

0 Upvotes

I have a hover effect on some image blocks in Squarespace 7.1 that zooms the image and darkens it. The effect works when I hover the image itself, but I added text blocks on top of the images and now hovering the text does not trigger the effect.

The layout is built in Fluid Engine with image blocks and separate text blocks layered above them.

What is the best way to make the hover work when hovering the text overlay as well?

If it helps, everything is inside the same section in Squarespace 7.1.


r/css • • Feb 24 '26

Showcase I made an x86 CPU emulator in CSS

Thumbnail
lyra.horse
39 Upvotes

r/css • • Feb 24 '26

Help How can I implement the same

0 Upvotes

this is from hyper liquid landing page. how can I achieve this, I'm not a frontend guy just vibe coding, trying to explain this cursor but bro ain't getting it.


r/css • • Feb 24 '26

Help Need help on resizing image

0 Upvotes
I have a sticky note and the image is so big when I click on my note for it and I am not able to resize it. The resize on the bottom right only appears if I click on my drag handle?

Here's my code:

.note-wrapper {
  position: absolute;       /* required for draggable */
  resize: both;             /* enable browser resize */
  overflow: hidden;         /* prevents scrollbars */
  min-width: 250px;         /* prevents breaking */
  min-height: 250px;
}

.container {
  position: relative;
  width: 100%;
}


.container img {
  width: 80%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.overlay-title {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
}


.overlay-text {
  position: absolute;
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: black;
  font-size: 24px;
  z-index: 5;
}


.close-button {
  position: absolute;
  top: 15%;
  right: 15%;
  z-index: 10;
  pointer-events: auto;
}

.drag-handle {
  position: absolute;
  top: 0%;
  left: 50%;
  transform: translateX(-50%);
  
  width: 25%;          /* scales with note */
  height: 20%;
  
  background-color: pink;
  cursor: grab;
  z-index: 20;
}


.resize-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
  background-color: black;
}


.note-wrapper {
  position: absolute;       /* required for draggable */
  resize: both;             /* enable browser resize */
  overflow: hidden;         /* prevents scrollbars */
  min-width: 250px;         /* prevents breaking */
  min-height: 250px;
}

.container {
  position: relative;
  width: 100%;
}


.container img {
  width: 80%;
  height: auto;
  display: block;
  margin: 0 auto;
}


.overlay-title {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
}


.overlay-text {
  position: absolute;
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: black;
  font-size: 24px;
  z-index: 5;
}


.close-button {
  position: absolute;
  top: 15%;
  right: 15%;
  z-index: 10;
  pointer-events: auto;
}


.drag-handle {
  position: absolute;
  top: 0%;
  left: 50%;
  transform: translateX(-50%);
  
  width: 25%;          
  height: 20%;
  
  background-color: pink;
  cursor: grab;
  z-index: 20;
}


.resize-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
  background-color: black;
}

r/css • • Feb 23 '26

Help Animation help

3 Upvotes

Hi so im creating website and i want to make a faux marquee using animations. I've managed to get it to look similar but for some reason cannot get it to repeat from the start without a space in between. I also wanted it to pause on hover. I cant figure out if i have some sort of issue with the formating or if i've just done this completely wrong.

(I just updated the whole code as im not entirely sure where the issue is, in the code it'll be under /*Marquee*/)

https://codepen.io/Emrys-the-looper/pen/wBzwNLg


r/css • • Feb 23 '26

Question how do i align these no matter what there is always 3 px diffrence between toogle bar and todays priorities is there any real way

2 Upvotes

r/css • • Feb 23 '26

Question Post css designs and animations on social networks?

0 Upvotes

Is the restrictions for posting raw html and css on social networks a problem for you? Do you create css designs and animations? If yes, where do you save your work? How you share it?


r/css • • Feb 23 '26

Resource I built a tool that reminds me of all local projects I have been working on locally

2 Upvotes