Mix blend mode in reversing colors - html

I have got the following code where when black segment overlap black points I want to change black points color to white and also when the rectangle when you hoover one of the points will change the color partially if overlaps the segment. I tried to do this with mix-blend-mode but no luck. What I was trying was to set a mix blend mode: difference to black segment and a isolation to the line. I tried a similar thing with the dosts.
https://jsfiddle.net/xm87keqh/9/
.month-subsection-news {
height: 62vh;
//background-color: blue;
position: relative;
}
.month-name-news {
font-size: 36vh;
position: absolute;
height: 100px;
width: 100px;
top: 5vh;
//margin-top: ;
font-family: GothamMedium;
color: #ededed;
}
.line-timeline {
width: 100%;
position: absolute;
height: 0.1vh;
top: 54%;
z-index: 3;
background-color: black;
// mix-blend-mode: exclusion;
}
.arrow-left-timeline {
position: absolute;
//#at-root: 2vh;
//width: 2vh;
left: 10vh;
top: 47%;
//background-color:blue
}
.arrow-right-timeline {
position: absolute;
//height: 2vh;
// width: 2vh;
right: 10vh;
top: 47%;
//background-color:blue
}
.dots {
position: absolute;
height: 1vh;
width: 1vh;
//left: 20vh;
top: -0.5vh;
background-color: black;
z-index: 999;
border-radius: 100px;
}
.dots1 {
left: 30vw;
}
.dots2 {
left: 50vw;
}
.dots3 {
left: 70vw;
}
.dots4 {
left: 60vw;
}
.dots5 {
left: 55vw;
}
// News cards
.news-card {
font-size: 30px;
width: 500px;
margin: 50px;
}
.top-photo-name {
border-top: 8.7px solid black;
//width: 75%;
}
.title-news-card {
margin: 40px 0px 20px 0px;
font-family: RobotoBold;
// width: 75%;
}
//End of news apge
.left-nav {
height: 100vh;
}
.news-page-api {
min-height: 100vh;
// height: 100vh;
//background-color: ;
}
.second-nav-news {
background-color: white !important;
border: 5px solid black;
top: 68.6px;
}
.column-icons-news {
width: fit-content;
border: 5px solid black;
}
.font-roboto-medium {
font-family: robotoMedium;
}
.number-of-news {
font-size: 311px;
top: 20vh;
font-family: robotoMEdium;
}
.margin-article {
margin-top: 10vh;
}
.news-title-in {
font-size: 59px;
font-family: RobotoBold;
}
.news-article-in {
font-size: 29px;
font-family: RobotoLight;
width: 80%;
}
.z-index {
z-index: 9999;
}
// .date-news{
// width: 75%;
// }
.img-news img {
width: 375px;
}
// .img-news{
// width: 75%;
// }
.news-card {
width: 375px;
}
.news-cards-section {
margin-top: 10vh;
}
// .news-page-section{ overflow-x: scroll;
// }
.dots5 a span {
display: none;
position: absolute;
color: #fff;
background: #000;
padding: 48px;
height: 11vh;
width: 40vh;
left: -30vh;
}
.dots5 a {
position: relative;
}
.hover-me:hover span {
display: block;
text-align: center;
clip-path: polygon(50% 0, 100% 41%, 100% 100%, 0 100%, 0 43%);
}
.black-segment {
height: 7vh;
width: 30vh;
position: absolute;
top: -1.5vh;
left: 80vh;
background-color: black;
}
<div class="month-subsection-news">
<div class="line-timeline">
<div class="black-segment"></div>
<div class="dots dots1"></div>
<div class="dots dots2"></div>
<div class="dots dots3"></div>
<div class="dots dots4"></div>
<div class="dots dots5"> <a class="hover-me" href="#"> a<span >Hello, World!</span></a></div>
</div>
Desired result

mix-blend-mode doesn't works well with black.
Instead you should prefer to use white as the default color, and then apply an invert filter over the whole result.
This also means that you have to manually invert all the defined colors inside the container element.
And the easiest is probably to make your rectangle the mixing element, however, for it to not mix with the horizontal line, you'd need a new wrapper that will define the isolation.
Here is a simplified example:
.line-timeline {
width: 100%;
position: absolute;
height: 5px;
top: 50px;
z-index: 3;
background-color: black;
}
.isolator {
isolation: isolate;
filter: invert(100%);
}
.dot {
width: 10px;
height: 10px;
background: white;
border-radius: 50%;
position: absolute;
top: -2.5px;
}
.dot.in {
left: 50px;
}
.dot.out {
left: 175px;
}
.dots5 a span {
position: absolute;
color: #000;
background: white;
padding: 48px;
height: 50px;
width: 150px;
display: block;
text-align: center;
clip-path: polygon(50% 0, 100% 41%, 100% 100%, 0 100%, 0 43%);
}
.dots5 a {
position: relative;
}
.black-segment {
height: 60px;
width: 150px;
position: absolute;
top: -15px;
background-color: white;
pointer-events: none;
mix-blend-mode: difference;
z-index: 10;
}
<div class="line-timeline">
<div class="isolator">
<!-- we use an isolator to not let our black rectangle mix with the horizontal line -->
<div class="black-segment"></div>
<div class="dot in"></div>
<div class="dot out"></div>
<div class="dots dots5"> <a class="hover-me" href="#"> a<span >Hello, World!</span></a></div>
</div>
</div>

Related

Why is my <Div> disappearing when I add Class to my <span> within it?

I'm trying to take a variable and display it on my html page via CSS for a Graphical display in OBS streaming software.
Every time I add the class .wrappers to the span id p1Name (as well as p2Name) the text disappears from the html output in OBS.
What is causing the text to disappear? As otherwise it perfectly is displayed when I don't include the class .wrappers
I've tried modifying overall page settings, the class specifications and moving the object itself but the text just seems to have disappeared.
Edit Changing the opacity within wrappers does not affect the visibility of the object
//Time stuff
let time = document.getElementById("current-time");
setInterval(() => {
let d = new Date();
time.innerHTML = d.toLocaleTimeString(navigator.language, {
hourCycle: 'h23',
hour: '2-digit',
minute: '2-digit'
});
}, 1000);
#font-face {
font-family: "Futura";
src: url('Resources/Fonts/Brandon_bld.otf');
}
* {
margin: 0;
padding: 0;
font-family: "Futura";
box-sizing: border-box;
overflow: hidden;
white-space: nowrap;
}
.graphicBox {
position: absolute;
width: 1800px;
height: 105px;
background: rgb(51, 116, 182);
background: linear-gradient(90deg, rgba(51, 116, 182, 0.75) 0%, rgba(110, 83, 180, 0.75) 70%);
border-radius: 15px;
bottom: 40px;
left: 50px;
filter: drop-shadow(-2px 2px 4px black);
}
.statusBox {
position: absolute;
font-family: "Futura";
font-weight: bold;
padding-top: 8px;
font-size: 40px;
width: 130px;
height: 70px;
background: rgb(231, 231, 231);
border-radius: 15px;
text-align: center;
bottom: 125px;
left: 100px;
filter: drop-shadow(-2px 2px 4px black);
}
.timeDisplay {
width: 140px;
height: 30px;
display: flex;
align-items: left;
justify-content: center;
position: absolute;
font-size: 14px;
color: white;
bottom: 58px;
left: 771px;
}
.timeZone {
width: 60px;
height: 20px;
display: flex;
align-items: left;
justify-content: space-between;
position: absolute;
font-size: 15px;
color: white;
bottom: 40px;
left: 812px;
}
.scoreboardP1 {
position: absolute;
left: 150px;
bottom: 60px;
width: 300px;
}
.scoreboardP2 {
position: absolute;
left: 450px;
bottom: 60px;
width: 300px;
}
.wrappers {
position: absolute;
width: 340px;
height: 100px;
line-height: 54px;
top: 356px;
opacity: 0;
color: black;
}
#p1Wrapper {
bottom: 540x;
left: 300px;
color: white;
}
#p2Wrapper {
width: 300px;
bottom: 20px;
left: 100px;
color: white;
}
.scoreDisplay {
position: absolute;
color: white;
width: 60px;
height: 60px;
align: center;
font-family: "Avant";
}
#p1Format {
top: 30px;
left: 1160px;
}
#p2Format {
top: 30px;
left: 1450px;
}
.scoreBox {
position: absolute;
width: 45px;
height: 45px;
background: white;
border-radius: 10px;
align: center;
}
#p1Box {
top: 28px;
left: 1150px;
}
#p2Box {
top: 28px;
left: 1440px;
}
<div class="graphicBox">
</div>
<div class="statusBox">
<p>NEXT</p>
</div>
<div class="timeDisplay">
<h1 id="current-time"></h1>
</div>
<div class="timeZone">
<p>EST</p>
</div>
<div id="overlayP1" class="scoreboardP1">
<span id="p1Wrapper" class="wrappers">
<span id="p1Name" class="names"></span>
</span>
</div>
<div class="scoreboardP2">
<span id="p2Wrapper">
<span id="p2Name" class="names"></span>
</span>
</div>
The problem seem to be two things in the CSS class .wrappers.
Because .wrappers has the property position: absolute, the element was disappearing out of the screen.
Also, with the propriety opacity: 0 the item is invisible.
So, by commenting out these elements in the CSS:
.wrappers {
/* position: absolute; */
width: 340px;
height: 100px;
line-height: 54px;
top: 356px;
/* opacity: 0; */
color: black;
}
I can now see both p1Name and p2Name when the parent span p1Wrapper and p2Wrapper have the wrappers class added to them, like this:
<span id="p1Wrapper" class="wrappers">
Also, just some quick notes:
align: center is not a valid CSS property.
While testing I added inside the p1Name span some words "testp2" so I could see the changes after formatting: <span id="p2Name" class="names">testp2</span>

css mix-blend-mode screen bug getting border radius from parent widget

So i have this widget and as you can see in the top right and left of each of the sections that has mix-blend-mode: screen active but it's getting a border-radius from a div which is set about in the main div.
HTML:
<div class="widget-box top-earners-widget">
<div class="box-header">
<h3 class="text-accent-2">Top Earners (<a class="dropdown-trigger" data-target='data-switcher-{{ #instance-guid }}'
id="switcher_type"></a>)</h3>
</div>
<div class="top-earners" foreach="data" foreach-limit="5">
<div class="earner">
<img src="{{ item.image }}" class="user-image">
<div class="white-bg"></div>
<div class="black-bg"></div>
<div class="marked-bg"></div>
<div class="marked-bg-2"></div>
<span class="name">{{ item.name }}</span>
<span class="total" amount="{{ item.value }}">£{{ item.value }}</span>
</div>
</div>
</div>
SASS:
.widget-box {
border-radius: 0.4em;
box-sizing: border-box;
border: 1px solid $stroke;
background: $background;
height: 100%;
position: relative;
overflow: hidden;
&.top-earners-widget,
&.top-taskers-widget {
.top-earners,
.top-taskers {
width: 100%;
height: 15em;
min-height: 15em;
.earner,
.tasker {
width: 100%;
height: 3em;
display: flex;
flex-direction: row;
align-items: center;
position: relative;
.user-image {
height: 1.5em;
width: 1.5em;
z-index: 5;
position: absolute;
margin-left: 0.5em;
}
.name {
color: white;
padding-left: 2.5em;
position: absolute;
mix-blend-mode: difference;
z-index: 3;
}
.total {
z-index: 3;
margin-left: auto;
padding-right: 10px;
color: white;
mix-blend-mode: difference;
}
.white-bg {
background: $background;
background: white;
width: 100%;
z-index: 1;
height: 100%;
position: absolute;
}
.black-bg {
background: black;
width: 0;
z-index: 2;
height: 100%;
position: absolute;
}
.marked-bg {
background-color: $accent;
mix-blend-mode: screen;
width: 100%;
z-index: 4;
height: 100%;
position: absolute;
left: 0;
}
.marked-bg-2 {
background-color: $top-earners;
mix-blend-mode: screen;
width: 100%;
z-index: 4;
height: 100%;
position: absolute;
right: 0;
}
&:nth-child(2) .marked-bg {
background-color: lighten($accent, 10%);
}
&:nth-child(3) .marked-bg {
background-color: lighten($accent, 20%);
}
&:nth-child(4) .marked-bg {
background-color: lighten($accent, 30%);
}
&:nth-child(5) .marked-bg {
background-color: lighten($accent, 35%);
}
}
}
}
}
I found the problem was to do with the position of the parent object. So i added position: inherit; to the sub parent of the div.
So its looks like this now.
&.top-earners-widget,
&.top-taskers-widget {
position: inherit;
...
}

Pure CSS Bulb - Two shapes change color on click

I made a bulb in pure CSS and I want the bulb to change color on click. But my bulb shape consists of two shapes, so I cannot hover over both. Is there a way to solve this without using JavaScript, sticking to CSS only? Is there maybe a way to create this yellow shape without the need to combine two? Or any other way I could have the hover effect working.
.box {
position: relative;
margin: auto;
display: block;
margin-top: 8%;
width: 600px;
height: 600px;
background: white;
}
#circle {
position: absolute;
width: 40%;
height: 40%;
background: yellow;
top: 20%;
left: 30%;
margin: 0 auto;
border-radius: 50%;
}
#trapezoid {
position: absolute;
background: yellow;
height: 30%;
width: 40%;
left: 30%;
top: 42%;
-webkit-clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
}
#bottom1 {
position: absolute;
height: 5%;
width: 25%;
background: grey;
top: 72%;
left: 37.5%;
z-index: 1;
}
#bottom1:before {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
left: -8%;
}
#bottom1:after {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
right: -8%;
}
#bottom2 {
position: absolute;
height: 5%;
width: 22%;
background: grey;
top: 78%;
left: 39%;
}
#bottom2:before {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
left: -8%;
}
#bottom2:after {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
right: -8%;
}
#bottom3 {
position: absolute;
height: 5%;
width: 18%;
background: grey;
top: 84%;
left: 41%;
z-index: 1;
}
#bottom3:before {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
left: -8%;
}
#bottom3:after {
content: "";
height: 100%;
width: 20%;
background: grey;
display: block;
position: absolute;
border-radius: 50%;
right: -8%;
}
#shine {
width: 20%;
height: 20%;
background: white;
border-radius: 50%;
top: 20%;
position: absolute;
left: 18%;
}
.halfCircle {
height: 100px;
width: 100px;
border-radius: 0 0 90px 90px;
}
#halfCircle {
height: 45px;
width: 90px;
border-radius: 0 0 90px 90px;
background: black;
margin: 0 auto;
top: 88%;
position: relative;
}
.drop {
width: 5%;
height: 5%;
position: absolute;
border: 15px solid orange;
}
#left {
left: 38%;
top: 45%;
border-radius: 50% 50% 0 50%;
}
#left:after {
content: "";
height: 110px;
width: 24px;
border: 15px solid orange;
display: block;
position: absolute;
left: 100%;
top: 100%;
}
#right {
right: 38%;
top: 45%;
border-radius: 50% 50% 50% 0;
}
#circle:hover {
background: red;
}
#trapezoid:hover {
background: red;
}
<div class='box'>
<div id='circle'>
<div id='shine'></div>
</div>
<div id='trapezoid'></div>
<div id='bottom1'></div>
<div id='bottom2'></div>
<div id='bottom3'></div>
<div id='halfCircle'></div>
<div class='drop' id='left'></div>
<div class='drop' id='right'></div>
<div id='wire'></div>
</div>
You don't have to apply the :hover directly to the element that you want to change. You can hoist it to a wrapping element and apply it there.
Considering your example, your selectors would likely be something along the lines of:
.box:hover #circle {
background: red;
}
.box:hover #trapezoid {
background: red;
}
Consider this concrete example. Hovering either of the nested <div> cause the sibling <div> to also change color because #container is being :hovered.
#foo,
#bar {
height: 20px;
background-color: green;
border: 1px solid white;
}
#foo:hover,
#bar:hover {
background-color: blue;
border: 1px dashed yellow;
}
#container:hover #foo,
#container:hover #bar {
background-color: red;
}
<div id="container">
<div id="foo">foo</div>
<div id="bar">bar</div>
</div>

How to adapt my custom multimedia video controls - HTML5/CSS3?

I am creating a design of controls to personalize the reproduction of videos, having some errors in the design there is a disorder in the design and even more when it comes to visualizing in different type of responsive screen.
In the design of the Speed as I can order them with a drop-down menu as shown in the following example image:
How can I give the correct style to the progress bar similar to the following image:
And carry an adaptive order similar to it.
My code complete:
.seeker {
position: relative;
width: 54%;
margin: 0 1%;
display: inline-block;
margin-right: 5px;
margin: 0 10px;
}
.trackbar {
position: absolute;
width: 100%;
height: 1px;
top: 12px;
z-index: -2;
background: rgba(255,255,255,0.7);
}
.progressbar {
position: absolute;
left: 0;
top: 12px;
width: 0;
height: 1px;
border: 0;
background-color: red;
color: red;
z-index: 0;
pointer-events: none;
}
.content-video-player {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 40px;
/*background: -webkit-linear-gradient(left,rgba(0,0,0,.7) 0px,rgba(0,0,0,.7) 95px,transparent 95px,transparent 98px,rgba(0,0,0,.7) 98px);*/
background: rgba(0,0,0,.7);
-webkit-transition: bottom .4s ease-in;
}
.content-video-player div.btn {
width: 95px;
text-align: center;
float: left;
}
.btnPlay::after {
content: "";
background-image: url(http://svgshare.com/i/3um.svg);
width: 50px;
height: 50px;
display: inline-block;
background-size: cover;
position: relative;
top: -7px;
}
.btnStop::after {
content: "";
background-image: url(http://svgshare.com/i/3vz.svg);
width: 65px;
height: 65px;
display: inline-block;
background-size: cover;
position: relative;
top: -7px;
}
.video-time-player {
float: right;
color: #ccc;
text-align: center;
width: 15%;
}
.volume {
position: relative;
cursor: pointer;
width: 70px;
height: 10px;
float: right;
margin-top: 10px;
margin-right: 10px;
}
.volumeBar {
display: block;
height: 30%;
position: absolute;
top: 0;
left: 0;
background-color: #a4c9ec;
z-index: 10;
}
.sound, .btnFS {
border: none;
float: right;
}
.sound::after {
content: "";
background-image: url(http://svgshare.com/i/3v6.svg);
width: 45px;
height: 40px;
display: inline-block;
background-size: cover;
position: relative;
top: -4px;
}
.btnFS::after {
content: "";
background-image: url(http://svgshare.com/i/3u5.svg);
width: 25px;
height: 25px;
display: inline-block;
background-size: cover;
position: relative;
top: 6px;
}
<!-- Container of the controls vidio players -->
<div class="content-video-player">
<div class="btnPlay btn" title="Play/Pause video"></div>
<div class="btnStop btn" title="Stop video"></div>
<div class="spdText btn">Speed: </div>
<div class="btnx1 btn text selected" title="Normal speed">x1</div>
<div class="btnx3 btn text" title="Fast forward x3">x3</div>
<div id="seeker" class="seeker">
<div class="trackbar"></div>
<div id="progressbar" class="progressbar" style="width: 114.7px;">
<span class="bufferBar"></span>
<span class="timeBar"></span>
</div>
<div class="video-time-player">
<span class="current">00:03</span> /
<span class="duration">00:03</span>
</div>
</div>
<div class="btnFS" title="Switch to full screen"></div>
<div class="volume" title="Set volume">
<span class="volumeBar" style="width: 84.2857%;"></span>
</div>
<div class="sound sound2" title="Mute/Unmute sound"></div>
</div>
The player layout is mainly 3 components (display: inline-table) within .content-video-player (display:table):
.playbackComponent | .timeComponent | .modComponent
▶ ] [ ⏸ ] [ X ] |_____ 07:22/15:01 | 🔉||||||| ⛶
The controls in each of the components have display:table-cell for a stable linear layout and position:absolute for finer grain adjustments. Included is a menu to adjust playbackRate, just hover over the 3rd button from the left X
Demo
*,
*::after,
*::before {
margin: 0;
padding: 0;
border: 0 none rgba(0, 0, 0, 0);
}
body {
overflow-y: scroll;
}
.content-video-player>* {
display: inline-table;
}
.content-video-player {
position: relative;
transform: translateY(68vh);
left: 0;
width: 100%;
height: 40px !important;
background: rgba(0, 0, 0, .7);
transition: bottom .4s ease-in;
display: table;
table-layout: fixed;
}
.seeker {
position: absolute;
width: 30%;
display: table-cell;
margin: 0 5px;
top: calc(50% - 6px);
left: 100px;
}
.trackbar {
position: absolute;
width: 100%;
height: 1px;
top: 12px;
z-index: -2;
background: rgba(255, 255, 255, 0.7);
}
.progressbar {
position: absolute;
left: 0;
top: 12px;
width: 0;
height: 1px;
border: 0;
background-color: red;
color: red;
z-index: 0;
pointer-events: none;
}
.content-video-player button.btn {
width: 48px;
text-align: center;
background-color: rgba(0, 0, 0, 0);
display: table-cell;
}
.btnPlay::after {
content: "";
background-image: url(http://svgshare.com/i/3um.svg);
width: 48px;
height: 48px;
display: table-cell;
background-size: cover;
position: absolute;
top: -4px;
}
.btnStop::after {
content: "";
background-image: url(http://svgshare.com/i/3vz.svg);
width: 56px;
height: 56px;
display: table-cell;
background-size: cover;
position: absolute;
left: 25px;
top: calc(50% - 28px);
}
.btnSpd {
transform: translateX(-35px);
height: 48px;
width: 48px;
font-size: 24px;
top: calc(50% - 24px);
}
.video-time-player {
position: absolute;
color: #ccc;
text-align: center;
left: 11.5em;
font-size: .3em;
width: auto;
min-width: 90px;
}
.video-time-player>* {
display: inline-block;
}
.volume {
position: relative;
cursor: pointer;
width: 80px;
height: 10px;
right: -5em;
top: 17px;
}
.volumeBar {
display: block;
height: 30%;
position: absolute;
background-color: #a4c9ec;
z-index: 10;
}
.sound,
.btnFS {
border: none;
}
.sound::after {
content: "";
background-image: url(http://svgshare.com/i/3v6.svg);
width: 45px;
height: 40px;
display: table-cell;
background-size: cover;
position: absolute;
top: 4px;
left: 25.5em;
}
.btnFS::after {
content: "";
background-image: url(http://svgshare.com/i/3u5.svg);
width: 25px;
height: 25px;
right: 5px;
display: table-cell;
background-size: cover;
position: absolute;
top: 12px;
}
.speed {
display: none;
position: absolute;
max-height: 0;
transition: max-height 1s;
}
.speed:hover,
.btnSpd:hover .speed {
display: inline-table;
list-style: none;
max-height: 300px;
transition: max-height 1s;
top: -170px;
}
.cmp {
width: 30%
}
<!-- Container of the controls vidio players -->
<main class='content-video-player'>
<section class="cmp playbackComponent" style='display:inline-table'>
<button class="btnPlay btn" title="Play/Pause video"></button>
<button class="btnStop btn" title="Stop video"></button>
<button class="btnSpd btn">X
<ul class='speed'>
<li>x3.0</li>
<li>x2.5</li>
<li>x2.0</li>
<li>x1.5</li>
<li>x1.0</li>
<li>x0.5</li>
</ul>
</button>
</section>
<section class='cmp timeComponent' style='display:inline-table'>
<div id="seeker" class="seeker">
<div class="trackbar"></div>
<div id="progressbar" class="progressbar" style="width: 114.7px;">
<span class="bufferBar"></span>
<span class="timeBar"></span>
</div>
<time class="video-time-player">
<b class="current">00:03</b> /
<b class="duration">00:03</b>
</time>
</div>
</section>
<section id='cmp ModComponent' style='display:inline-table'>
<div class="volume" title="Set volume">
<span class="volumeBar" style="width: 84.2857%;"></span>
</div>
<button class="btn sound sound2" title="Mute/Unmute sound"></button>
<button class="btn btnFS" title="Switch to full screen"></button>
</section>
</main>

How to move a child element above another child element of a parent element that is above it's own parent element?

I have two parent elements (a black and red divs). Each of them contain a child element. The black one contains a gray div. The red one contains a pink div.
Following constraints:
I can not change the relationship between child to it's own parent element, i.e. I can not move a child element outside of it's own parent element.
The red div has to remain underneath the black div
Is it possible to move the pink div above the gray div?
.parent-black {
width: 100%;
height: 50px;
background-color: rgba(0, 0, 0, .9);
color: white
}
.child-gray {
width: 250px;
height: 90px;
background-color: gray;
position: absolute;
right: 137px;
top: 20px;
z-index: 0;
color: white;
}
.parent-red {
width: 100%;
height: 40px;
background-color: red;
position: absolute;
top: 40px;
z-index: -999;
}
.child-pink {
width: 95%;
height: 80px;
background-color: pink;
top: 30px;
left: 20px;
position: absolute;
z-index: 9999;
}
<div class="parent-red">
2
<div class="child-pink">2.1</div>
</div>
<div class="parent-black">
1
<div class="child-gray">1.1</div>
</div>
Using jQuery below
$(document).ready(function() {
$('.child-gray').insertBefore($('.child-pink'));
})
.parent-black {
width: 100%;
height: 50px;
background-color: rgba(0, 0, 0, .9);
color: white
}
.child-gray {
width: 250px;
height: 90px;
background-color: gray;
position: absolute;
right: 137px;
top: 20px;
z-index: 0;
color: white;
}
.parent-red {
width: 100%;
height: 40px;
background-color: red;
position: absolute;
top: 40px;
z-index: -999;
}
.child-pink {
width: 95%;
height: 80px;
background-color: pink;
top: 30px;
left: 20px;
position: absolute;
z-index: 9999;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent-red">
2
<div class="child-pink">2.1</div>
</div>
<div class="parent-black">
1
<div class="child-gray">1.1</div>
</div>
Honestly, I don't get the real problem here... I guess this follows your constraints:
.parent-black {
width: 100%;
height: 50px;
background-color: rgba(0, 0, 0, .9);
color: white;
position: relative;
}
.child-gray {
width: 250px;
height: 90px;
background-color: gray;
position: absolute;
right: 137px;
top: 20px;
z-index: 0;
color: white;
}
.parent-red {
width: 100%;
height: 40px;
background-color: red;
margin-top: -20px;
}
.child-pink {
width: 95%;
height: 80px;
background-color: pink;
top: 70px;
left: 20px;
position: absolute;
z-index: 9999;
}
<div class="parent-black">
1
<div class="child-gray">1.1</div>
</div>
<div class="parent-red">
2
<div class="child-pink">2.1</div>
</div>