Overlay on a flexbox while keeping responsivness

  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around creating a responsive overlay for a progress bar using flexbox. Participants explore methods to implement the overlay without disrupting the layout, particularly focusing on the use of CSS positioning.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant expresses the challenge of maintaining responsiveness while using absolute or fixed positioning for an overlay.
  • Another participant suggests using position: relative on the outer div and position: absolute on the overlay to potentially resolve layout issues.
  • A further reply emphasizes the importance of using CSS class selectors consistently instead of mixing different selector types.
  • One participant shares a link to a jsfiddle demonstrating a working example of the overlay, noting that they implemented it as an underlay for a better visual effect.
  • Another participant proposes that the overlay effect could be achieved purely with CSS, suggesting the use of background gradients and transition delays.

Areas of Agreement / Disagreement

Participants generally agree on the utility of using position properties to manage the overlay, but there is no consensus on the best approach or whether JavaScript is necessary.

Contextual Notes

Some limitations include the reliance on specific CSS properties and the potential for varying interpretations of "breaking the layout." The effectiveness of the proposed solutions may depend on the specific context of use.

Superposed_Cat
Messages
388
Reaction score
5
With the below code, I am trying to make an overlay for a "progress bar" with text, I need the flex to make it responsive,
BUT the only way I know to make an overlay is to use things like fixed or absolute position, which breaks the layout, is there a way to keep it responsive and have an overlay with dynamic width (for displaying progress).

HTML:
.master{
  display: flex;
}
.item{
    border-right: 1px solid black;
    padding-right: 5px;
    display: inline-block;
    text-align: center;
    padding: 15px 0;
    flex-grow: 1;
    flex-basis: 0;
}
<div style='border:1px solid black;margin: 0 auto;'>
  <div class='master'>
    <span class="item">a</span>
    <span class="item">b</span>
    <span class="item">c</span>
  </div>
  <div id='overlay' style='background-color:red;opacity:0.7;width:100%;height:100%;'></div>
</div>
 
Technology news on Phys.org
Not sure what you mean by 'breaking the layout'? Have you tried position: relative; on the outer div and position: absolute; top: 0; on the #overlay div? It will be easier to work out what is going on if you use CSS class selectors for all elements rather than the mix of id selectors, class selectors and inline CSS you currently have.
 
  • Like
Likes   Reactions: DaveC426913
Yep. position relative on the container div

If you put a bare-bones example in jsfiddle or plunkr we could see what's happening.
 
DaveC426913 said:
If you put a bare-bones example in jsfiddle or plunkr we could see what's happening.
Actually I had some time free on the train so did exactly that, fixed and tidied up a bit. I also implemented the "overlay" as an underlay which I think gives a better effect - see it all at https://jsfiddle.net/pbinuk/py3L92z0
 
Very nice.

If you are of-a-mind, I suspect you could skip the JavaScript and do this in CSS only, using a combination of a background-gradient and a transition delay.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K