Overlay on a flexbox while keeping responsivness

  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
Click For Summary
The discussion centers on creating a responsive overlay for a progress bar using CSS. The original poster seeks a solution that maintains layout integrity while allowing for dynamic width in the overlay. Suggestions include using position: relative on the outer container and position: absolute on the overlay to prevent layout issues. Participants recommend using CSS class selectors for better organization and clarity. A user created a simplified example on jsFiddle, demonstrating an effective overlay technique. Additionally, there is a suggestion to achieve the desired effect using only CSS, incorporating background gradients and transition delays for a smoother appearance.
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 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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