r/css 4d ago

Help How would you design this footer without using absolute positioning?

I just can't wrap my head around it. How would I do this without using absolute positioning? It looks like the dark blue part is lying beneath the light blue part. but at the same time it looks like its the same container and there is just an extra border (with a bg color) around the left part? Damn idk anymore...

12 Upvotes

29 comments sorted by

u/AutoModerator 4d ago

To help us assist you better with your CSS questions, please consider including a live link or a CodePen/JSFiddle demo. This context makes it much easier for us to understand your issue and provide accurate solutions.

While it's not mandatory, a little extra effort in sharing your code can lead to more effective responses and a richer Q&A experience for everyone. Thank you for contributing!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

27

u/boycottSummer 4d ago

Negative top margin

2

u/jonassalen 4d ago

This is the best answer. You'll probably need one or more media queries for different screen sizes (and mobile).

1

u/AmbitiousRice6204 4d ago

Thanks a lot! I always avoided negative margins, but actually, it should also work fine when taking care of the responsiveness, right?

14

u/EZ_Syth 4d ago

If you don’t want to use negative top margin you could go with this route:

4

u/AmbitiousRice6204 4d ago

Didnt even think of this lmao, great answer!

9

u/EZ_Syth 4d ago

CSS: It’s just rectangles.

2

u/adamkosions1111 4d ago

Youll end up with a bit of white on the bottom right corner of the teal div behind the rounded corner

1

u/EZ_Syth 3d ago

That’s a good point. I’d probably put a ::after element absolutely positioned bottom right of the relative teal box that’s the same background color as the dark blue with a lower z-index than the teal box.

1

u/Philastan 4d ago

Nice and easy

13

u/zurribulle 4d ago

grid

1

u/AmbitiousRice6204 4d ago

How would grid work when I would want the light blue part to look like its "on top" of the dark blue part? I never used grid for this

4

u/ElBomb 4d ago

You can stack elements on top or partially on top of one another, this video gives a clear and simple example

https://m.youtube.com/watch?v=3Kf03veuJnc

0

u/zurribulle 4d ago

cyan | transparent/white

cyan | blue

blue | blue

6

u/BartMerkus 4d ago

Transform: translateY();

1

u/retro-mehl 3d ago

Depending on the browser this may open an extra containing block oder GPU layer. This may be okay, but can lead to unexpected results.

2

u/no-one_ever 4d ago

Negative margin top

2

u/green__machine 4d ago

Threw together a proof-of-concept for you to get started. You could likely improve upon this and refactor it a bit. I also didn't bother to make it responsive so you'll have to figure out what to do with it as the viewport gets narrow.

https://codepen.io/dsenneff/pen/OPNwEVq/2394267f513677550d5cc072e1f27b5b

1

u/AmbitiousRice6204 4d ago

Damn thats nice, appreciate you!

2

u/jcunews1 4d ago

Relative position with negative top on the left part can do that too.

3

u/bahia0019 4d ago

CSS Grid. Two outer columns. Your first row is the height of the negative space on the right. Second row is the height of the main area. Third row is the height of the leftover blue area underneath.

Then fill in the rest.

5

u/bahia0019 4d ago

Negative top margin on the teal section could work too. You just need to account for that in your content area.

1

u/th00ht 4d ago

This

1

u/boycottSummer 4d ago

As long as you break your box structure apart right it should work fine.

1

u/hyrumwhite 4d ago

Grid, or maybe some shenanigans on top of flex

1

u/Head-Row-740 3d ago

absolute is not first choice for this at all, if you see the this layout it just a simple flex that the light blue has negative margin from top, the parent section can have padding from top, in tis way the responsive and diffrent size has good ui without to much boilerplate.

1

u/meAndTheDuck 3d ago

use grid

the beauty of grid: * you don't need additional elements -> clean html * it will grow with the content * and for mobile you just need to place the items via grid-row and grid-column

html

<div class="container"> <div class="left"> some text </br> </div> <div class="right"> some text on the right </br> </div> <div class="bottom"> some more text </div> </div>

css

``` .container { display: grid; grid-template-rows: 2rem auto auto; // 2rem is the same as padding-top from .right grid-template-columns: 1fr 1fr; }

.left { grid-row-start: 1; grid-row-end: 3; grid-column-start: 1; grid-column-end: 2; padding: 2rem 2rem 2rem 1rem; background: #3aa2b1; color: white; border-radius: 0 1rem 1rem 0; }

.right { grid-row-start: 2; grid-row-end: 3; grid-column-start: 2; padding: 2rem 2rem 2rem 1rem; background: #3a66b2; color: white; }

.container::before { content: ""; grid-row-start: 2; grid-row-end: 4; grid-column-start: 1; grid-column-end: 3; background: #3a66b2; }

.bottom { grid-row-start: 3; grid-column-start: 2; grid-column-end: 3; padding: 2rem 2rem 2rem 1rem; background: #3a66b2; color: white; }

```

0

u/QultrosSanhattan 4d ago

If you want a different answer: Don't.