So I have an issue and despite spending on research a while now I still cannot figure out what I am doing wrong.
Consider the following:
/* Main row */
.main-row {
width: 100%;
display: inline-flex;
z-index: -1;
position: relative;
}
.spacer {
width: 100%;
background-color: #0a0826;
height: 250px;
background-image: url("../img/purple-wave.png");
background-position: 0px 17%;
z-index: 10;
position: relative;
}
and HTML
<div class="main-row">
<div class="main-row left-pane">
<h1 class="main-row title">Changing The Way</h1>
<p class="main-row subtitle">We understand <a>intelligent</a>telecommunication</p>
</div>
<div class="main-row right-pane">
<img src="<?php echo base_url("assets/vid/ai_brain.gif");?>" />
</div>
</div>
<div class="spacer"></div>
I am expecting to see the spacer (with some fancy graphics) to overlay the main row but this isn't happening. The position is specified, the z index is set correctly, the two divs are independent of each other. Whatever I do the graphic still is displayed below the main-row div
I think you're confusing background-position and element positioning. Background positioning changes the position of your background relative to wherever the element is on the screen. The background is still contained by the element, and otherwise does not affect the element's size or position on the screen.
Everything will overlap if you adjust the actual position of the spacer, like so:
.spacer {
top: -200px; /* This */
width: 100%;
background-color: #0a0826;
height: 250px;
background-image: url("../img/purple-wave.png");
background-position: 0px 17%;
z-index: 10;
position: relative;
}
Related
This is what I currently have:
<div class="container">
<img src="example.jpg">
<div class="overlay">
</div>
</div>
.container {
position: relative;
}
img {
width: 100vw;
height: 100vh;
object-fit: contain;
}
.overlay {
position: absolute;
border: 2px solid red;
top: 10%;
bottom: 10%;
left: 20%;
right: 20%;
}
What I would like to happen is that the overlay element stays relative to the size of the image regardless of the scaling, i.e. the top of the overlay is 10% below the top of the image and so on. However the current behaviour is that the overlay is instead relative to the container, i.e. the top is 10% below the top of the container etc. How can I fix this?
How could we use CSS mix-blend-mode, if the background image/video is not the parent of the element which gets the mix-blend-mode?
For example
<div class="has-video-background">
<video></video>
</div>
<div class="caption-above-video">
<h1>This div should have a colored background with a mix-blend mode multiply</h1>
</div>
The div with the class .caption-above-video should have a colored background with a mix-blend-mode. But the effect not appears. When using mix-blend-modes somewhere, the element with the blend-mode is the direct child of the parent with the background image, but in this example this is not possible because of a full with and height background video. Also I cannot manipulate the DOM output, because its coming from a page builder.
How could we use CSS mix-blend-mode effects when the containers are siblings?
Mix-blend-mode does not work with siblings.
The mix-blend-mode CSS property sets how an element's content should blend with the content of the element's parent and the element's background.
https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode#effect_of_different_mix-blend-mode_values
I actually can't see what the problem is.
If you overlay the video with another element (by giving that element position absolute and the same size as the video for example - but there are lots of ways of doing this) and they are siblings (i.e have the same parent) then the mix-blend-mode seems to work perfectly well.
.parent {
width: 80vmin;
position: relative;
}
video {
position: relative;
width: 100%;
}
.caption-above-video {
background: red;
mix-blend-mode: multiply;
position: absolute;
pointer-events: none;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div class="parent">
<div class="has-video-background">
<video src="https://www.w3schools.com/HTML/movie.mp4" controls autoplay></video>
</div>
<div class="caption-above-video">
<h1>This div should have a colored background with a mix-blend mode multiply</h1>
</div>
The only thing I did 'extra' was to make the overlaying element have pointer events of none so that I could use the controls on the video. If you need pointer events on the overlay then you'll need to implement the video controls yourself e.g. with JS.
As far as I know, it comes down to which div is on top. So by using position: absolute; and a z-index for example, you add mix-blend-mode to the div that is "on top" of the other div.
I added a code snipped so you can see what I've done to accomplish this.
-I did add a container around the two divs for styling purposes for this example.
-Added an extra div in the .caption-above-video that has the background-color and mix-blend-mode. This is important if you don't want the h1 to be affected by the mix-blend-mode, because that affects all children too.
Also added an background-image to the .has-video-background so you can see the result better. This is for demonstration purposes only and as soon as you add the actual video, the result will be the same.
.container{
display: flex;
justify-content: center;
align-items: center;
position: relative;
width: 400px;
height: 300px;
}
.has-video-background{
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-image: url('https://cdn.pixabay.com/photo/2022/08/09/16/19/sea-7375377_960_720.jpg');
background-size: cover;
background-repeat: no-repeat;
background-color: lightblue;
}
.caption-above-video{
position: absolute;
width: 200px;
height: 150px;
}
h1{
position: relative;
z-index: 2;
color: white;
}
.background-div{
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
mix-blend-mode: multiply;
background-color: green;
}
<div class="container">
<div class="has-video-background">
<video></video>
</div>
<div class="caption-above-video">
<h1>Caption</h1>
<div class="background-div"></div>
</div>
</div>
I am trying to create a landing page where I am planning to position some fixed background image as a slideshow fixed at top and then another div with where it goes what the website is about. However the current HTML and CSS code puts the two divs on top of each other.
Upon checking with the existing code and working with the position property and setting the parent div as relative position with the child divs as relative doesn't work either
.crossfade>figure {
animation: imageAnimation 30s linear infinite 0s;
backface-visibility: hidden;
background-size: cover;
background-position: center;
color: transparent;
height: 100%;
left: 0px;
opacity: 0;
position: absolute;
top: 0px;
bottom: 0;
width: 100%;
z-index: -1;
min-height: 700px;
background-attachment: fixed;
background-repeat: no-repeat;
background-size: cover;
}
#landing {
position: absolute;
top: 500px;
}
<div className="main">
<div class="crossfade">
<figure></figure>
<figure></figure>
</div>
<div id="landing">
<div className="container">
<img />
</div>
<p> Hello </p>
</div>
</div>
The expected css should be placing the two divs one after another while preserving the top background image slideshow and then showing the second div.
I assume the first part of your CSS is for your <div class="crossfade">. If so, your crossfade and landing <div>'s both have position: absolute, which is most likely causing them to stack on top of each other.
If you want your crossfade and landing side-by-side / top-to-bottom, I would recommend wrapping both inside an outer <div> and use Flexbox.
.outer-container {
display: flex;
width: 100%;
text-align: center;
justify-content: center;
align-items: center;
/* Enable this if you want them to be top to bottom. */
/* flex-direction: column; */
}
.crossfade, #landing {
/* You might have to tweak the width based off of
margin, padding, and other dimensions. */
width: 45%;
height: 100px;
border: 1px solid black;
}
<div class="outer-container">
<div class="crossfade">Crossfade</div>
<div id="landing">Landing</div>
</div>
Also, I could you clarify/provide an example for this:
while preserving the top background image slideshow and then showing the second div
I am trying to get my child div section to all the way to the top and bottom of the parent div section. Go to the bottom of this Example URL (where the Canadian Flag Stand Up Paddle Boarders are): https://www.lakeshoresup.com/product/pathfinder/
Basically if I set the width larger than 41% I get a small area that doesn't go to the top and bottom of the section.
Code:
<div class="hero__container container">
<div class="hero__content-wrapper" style="background-color: rgba(0,0,0,0.2); flex: 60% ; max-width: 60%;">
<h1 class="hero__title hero__title--big">
Adrift in the Canadian Rockies</h1>
<p class="hero__content hero__content--medium">
Jake and Lyndsay embark on a Lakeshore adventure with their inflatable paddleboards. </p>
<div class="primary-link">
<a href="https://www.lakeshoresup.com/2015/07/28/adrift-in-the-canadian-rockies-with-jake-lyndsay-part-1/" class="hero__primary-link btn" target="_blank">
Read Their Story </a>
</div>
</div>
</div>
CSS
.hero--right .container {
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
}
.hero__content-wrapper {
padding-left: 20px;
padding-right: 20px;
display: table-cell;
vertical-align: top;
}
I have tried to add min-height:760px to the css which worked but isn't dynamic. When the site goes to mobile or if the slider boxes are different sizes it breaks the image.
Is there a dynamic way to make the child box (.hero__content-wrapper) always extend to the top of the parent box (.hero__container)?
Is this something that I can use the CSS below and have it function across all browsers or is there a better way to do it?
height: -moz-available;
height: -webkit-fill-available;
height: fill-available;
I think found a solution to your issue.
.hero__content-wrapper {
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 100%;
}
Also to remove the max-width as it will take the width of the parent. You could also add position:relative to the .hero__container class. Does that solve your problem?
Matt -
Let's dilute the example for readability, but essentially create the same thing:
<div class="container">
<div class="box"></div>
</div>
CSS:
.container {
position: relative;
height: 100px;
width: 100px;
border: 1px solid red;
}
.box {
background: blue;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
Here, we just use CSS Position to set the element's reference to the container's dimensions. Then we target the edges of the boundaries with the top:0, etc - That gives us a blue box with unspecified dimensions, filling its parent container.
I am using bootstrap, I wanted one div behind the other div, so used z-index en position: absolute and relative.
When doing this, every div under the div with z-index: 1 goes behind this div, while I want it to stay under it.
The div also becomes wider than the max-width when using 100%
<div class="row" id="MENUROW">
<div class="col-md-12" id="MENUCOLUMN"><h1>SHOP</h1></div>
</div>
<div class="row" id="MAINROW"> <!-- this has the background-image -->
<div class="col-md-12" id="MAINCOLUMN">
</div>
</div>
CSS:
#MENUROW
{
position: relative;
height: 80px;
background-color: transparent;
z-index: 2;
}
#MAINROW
{
position: absolute;
z-index: 1;
top: 60px; /*because there is 1 div above the menu div, this div needs to be just under that div, behind the menu div */
width: 100%;
background-image: url(../images/background.jpg);
background-size: cover;
}
when doing this the background image goes wider (to the right) than the width of the parent div.
https://jsfiddle.net/2cs60vrr/3/ example, just made the background red to show how wide it should be, the background image goes much wider
Point 1
You didn't used .container class in your HTML. Bootstrap has a structure to get it's maximum feature. You must need to use .container. Bootstrap structure is below:
<div class="container">
<div class="row">
<div class="col-*-*">
Your Content
</div>
</div>
</div>
Make your html as above to solve this issue.
Point 2
If you want not change your html, then use this code below to any .row to solve this issue.
margin-left:0;
margin-right:0;
I am sorry if we are unsure what you are looking for but is that what you want?
.grid {
margin: 0 auto;
max-width: 100%;
width: 100%;
background-color: #fff;
}
.row {
width: 100%;
margin-bottom: 0px;
display: flex;
}
#MENUROW {
position: absolute;
height: 80px;
background-color: red;
z-index: 2;
}
#MAINROW {
position: absolute;
z-index: 1;
top: 0;
width: 100%;
max-width: 1400px;
background-image: url(https://upload.wikimedia.org/wikipedia/commons/e/ed/Palais_Garnier.jpg);
background-size: cover;
}
https://jsfiddle.net/norcaljohnny/xt9c9d2r/2/
You should put the wrapper around the whole thing to position:relative;
And both rows to position:absolute;
That's it.
When using position:absolute; the block goes to the absolute top left corner of the closest parent html tag that has a position:relative;. If there is no parent with position:relative; your absolute positioned items go to the upper left corner of your screen.
(the first row is not a parent of the second, but they are siblings. The wrapper "grid" is the parent of the 2 rows)
<div class="grid">
<div class="row" id="MENUROW">
<div class="col-md-12" id="MENUCOLUMN">
<h1>SHOP</h1>
</div>
</div>
<div class="row" id="MAINROW">
<div class="col-md-12" id="MAINCOLUMN">
text
</div>
</div>
</div>
And CSS
.grid {
position: relative;
}
.row {
width: 100%;
}
#MENUROW {
position: absolute;
background-color: red;
z-index: 1;
}
#MAINROW {
position: absolute;
z-index: 2;
background-image: url(https://upload.wikimedia.org/wikipedia/commons/e/ed/Palais_Garnier.jpg);
background-size: cover;
}
Here is your updated example:
https://jsfiddle.net/2cs60vrr/6/