Overlap image with another image - html

First image is going as a background with its multiply blend mode and its color (100% x 1172px).
At the very bottom of this container is a block (50% x 520px) with same background, but without blending mode.
What exactly I'm trying to reach.
-- The idea is to keep these two image as a single one at least to >= 920px width of breakpoint.
HTML&CSS markup
.main-container {
display: flex;
height: 1172px;
width: 100%;
position: relative;
}
.main__fluid {
display: flex;
flex: 1;
}
.main__fluid--image {
background: url(https://i.imgur.com/eRnGawp.jpg);
background-size: cover;
background-repeat: no-repeat;
position: relative;
}
.main__inner-block {
display: flex;
align-items: flex-end;
position: relative;
height: 520px;
width: 50%;
margin-top: auto;
margin-left: auto;
margin-right: auto;
margin-bottom: 3rem;
border-radius: 10px;
box-shadow: 1px 2px 4px 0px rgba(0, 0, 0, 0.28);
z-index: 9;
}
.main__inner-block--image-mask {
overflow: hidden;
}
.image {
position: absolute;
width: 100%;
height: 100%;
left: 0;
bottom: 0;
background: url(https://i.imgur.com/Piu55zF.jpg);
background-repeat: no-repeat;
background-position: top -36rem center;
max-width: 100%:
}
.main__navigation {
height: 80px;
width: 100%;
background-color: #5ec8c3;
position: relative;
}
.footer {
background-color: #1f5c71;
height: 91px;
position: relative;
top: -5rem;
}
<div class="main-container">
<div class="main__fluid main__fluid--image">
<div class="main__inner-block main__inner-block--image-mask">
<div class="image"></div>
</div>
</div>
</div>
Currently have this one:
jsfiddle
jsfiddle (UPD)
UPD: found somewhat partial solution
I will assign parent for big image (which is with blending mode)
and child for smaller image (which is without blending mode)
Actually I just deleted property background-size from parent or/and add background-size: auto auto to its style, the idea is to, of course, prevent resizing on Y axis. Then did tweaks for child to fit it relative parent through background-position and the last one, aligned them centered with background-position: center. Updated jsfiddle with these changes.

Try this css block. It will align both images into same position.
.main-container {
display: flex;
height: 1172px;
width: 100%;
position: relative;
}
.main__fluid {
display: flex;
flex: 1;
}
.main__fluid--image {
background: url(https://i.imgur.com/Piu55zF.jpg);
background-size: cover;
position: relative;
background-color: #51c8c4;
background-blend-mode: multiply;
background-repeat: no-repeat;
background-position: top -27rem center;
}
.main__inner-block {
position: relative;
height: 45%;
width: 80%;
margin-top: 20.5%;
margin-left: auto;
margin-right: auto;
border-radius: 10px;
box-shadow: 1px 2px 1px 0px rgba(0, 0, 0, 0.28)
}
.main__inner-block--image-mask {
overflow: hidden;
}
.image {
position: relative;
width: 100%;
height: 100%;
background: url(https://i.imgur.com/Piu55zF.jpg);
background-repeat: no-repeat;
background-position: top -45rem center;
}

Related

background position not centering while background-attachment fixed applied?

This is what my background currently looks like with the following CSS and background attachement fixed applied
/* APPLY SECTION */
section.apply {
height: 55rem;
width: 100%;
background: url("../img/apply.jpg") no-repeat;
background-attachment: fixed;
background-position: center center;
background-size: cover;
position: relative;
}
.apply::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.3);
}
.apply * {
position: relative;
z-index: 10;
}
.apply .apply-content {
height: 100%;
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
}
.apply .apply-content h2 {
max-width: 30rem;
font-size: 3.2rem;
color: #fff;
font-weight: 300;
text-align: center;
}
This is with background-attachement fixed removed
How do I add background attachment fixed and be able to center the background using background-position, size, and repeat?
section.apply {
height: 55rem;
width: 100%;
background: url("../img/apply.jpg") no-repeat;
background-attachment: fixed;
background-position: center center;
background-size: cover;
position: relative;
background-position-y:10px
}
try using this

parallax scrolling pages arranged oddly

I want the about div to show up BELOW the
full screen home card
I'm having troubles getting it to show like it should.
my html code has both divs in the "right" order and when i look it up online, i couldn't find any solutions.
<body>
<div class="homeCard">
<div class="homeCardTitle">
<h1>Robin Riezebos</h1>
</div>
</div>
<div class="aboutCard">
<div class="aboutCardText">
<h2>About</h2>
</div>
</div>
</body>
my css is either missing something or I did something completely wrong but I can't seem to find out what it is so please help...
index.css
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
height: 100%;
width: 100%;
position: fixed;
float: left;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
position: fixed;
width: 100%;
height: 320px;
top: 50%;
margin-top: -160px;
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
background-color: #1F1F1F;
color: white;
height: 500px;
}
Please change your css like below, i think the problem was with position fixed, if you want to get your background image rendered fully please respective pixels of height.
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
width: 100%;
position: relative;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
background-color: #1F1F1F;
color: white;
height: 500px;
}
I have found a solution by bugging around in my css.
Turns out in stead of position: fixed; I should have used background-attachment: fixed; and remove position all-together.
this is my own fixed code:
.homeCard {
background-image: url("images/helicopter-in-sky-2.jpg");
height: 100%;
width: 100%;
background-attachment: fixed;
float: left;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 0;
}
.homeCardTitle {
position: relative;
width: 100%;
height: 0px;
top: 50%;
margin-top: -90px;
color: white;
text-shadow: 0 0 10px black;
}
.aboutCard {
width: 100%;
background-color: #1F1F1F;
color: white;
height: 320px;
float: left;
text-align: center;
}

img scale to viewport inside div

I'm building an image lightbox with a close button. The Image should scale to it's default size until it hits a maximum of 90% page width/height.
This works fine with smaller images than the maximum, anything above will overflow the container div.
Here is my codepen example:
https://codepen.io/gempir/pen/eMYmyx
How do I force the image to scale?
Setting
img {
max-height: 100%;
max-width: 100%;
}
Does not help because the parent div has no fixed width. Any idea how to handle this situation correctly, besides using JS to calculate on the fly.
.image-overlay {
display: flex;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.25);
text-align: center;
user-select: none;
justify-content: center;
align-items: center;
}
.image-overlay .image-container {
display: inline-block;
position: relative;
max-width: 90% !important;
max-height: 90% !important;
background: blue;
}
.image-overlay .image-container .close {
position: absolute;
top: 5px;
right: 5px;
color: white;
background: rgba(0, 0, 0, 0.5);
padding: 5px;
}
.image-overlay .image-container img {
display: block;
max-height: 100%;
max-width: 100%;
}
<div class="image-overlay">
<div class="image-container">
<img src="https://picsum.photos/g/1800/1800">
<div class="close">close</div>
</div>
</div>
Use viewport units instead:
.image-overlay {
display: flex;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .25);
text-align: center;
user-select: none;
justify-content: center;
align-items: center;
}
.image-overlay .image-container {
display: inline-block;
position: relative;
max-width: 90% !important;
max-height: 90% !important;
background: blue;
}
.image-overlay .image-container .close {
position: absolute;
top: 5px;
right: 5px;
color: white;
background: rgba(0, 0, 0, 0.5);
padding: 5px;
}
.image-overlay .image-container img {
display: block;
max-height: 90vh;
max-width: 90vw;
}
<div class="image-overlay">
<div class="image-container">
<img src="https://picsum.photos/g/1800/1800">
<div class="close">close</div>
</div>
</div>
This will restrict your image based on the actual viewport available, instead of the container, your image is in.
Codepen example
You can use vmin and vmax to deal with this if you want to change behaviour depending on the viewport.
.image-overlay {
display: flex;
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 100%;
background: rgba(0,0,0, .25);
text-align: center;
user-select: none;
justify-content: center;
align-items: center;
}
.image-container {
display: block;
position: relative;
background: blue;
}
.close {
position: absolute;
top: 5px;
right: 5px;
color: white;
background: rgba(0,0,0,0.5);
padding: 5px;
}
img {
display: block;
max-width: 90vmin;
max-height: 90vmin;
}
<div class="image-overlay">
<div class="image-container">
<img src="https://picsum.photos/g/1800/1800">
<div class="close">close</div>
</div>
</div>
Explanation:
vmin = 1%of min viewport size (width or height, equals to vh or vw depending on which one is the smaller)
vmax = the opposite of vmin.
what can vmin and vmax do?
you can use vh and vw (or % depending on the situation) to resize images, but sometimes they look too small on smartphones, so you can use:
.images{
max-width: 90vmin;
max-height: 90vmin;
}
#media(max-width:600px){
.images{
max-width: 90vmax;
max-height: 90vmax;
}
}
they'll fit well on computer viewports (or even smart TV etc) and will be a bit bigger on smartphones.

How can I have a transparent overlay and center with flex box?

I have a block element with a background image. I am attempting to:
Add a transparent gradient overlay on top of a background image
Center another block element using flexbox,
I have already achieved both of these independently of each other, see the CodePen as well as the images and code below.
Using the transparent overlay (with the child block HTML removed):
Centering the child block (with the overlay CSS removed):
However when I try and combine the effects, the flexbox stops working and the overlay is missing around the child block
Here is my HTML
<div class="container">
<p>title goes here</p>
</div>
Here is my CSS:
.container {
background: url("http://msue.anr.msu.edu/uploads/images/forest.jpg");
height: 400px;
width: 100%;
box-shadow: inset 0px -4px 14px 0px rgba(50, 50, 50, 0.71);
background-size: 100% auto;
z-index: 0;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.container p {
display: block;
color: red;
text-align: center;
font-size: 24pt;
background-color: blue;
z-index: 2;
}
.container:after {
content: '';
background: linear-gradient(135deg, #dc4225, #292484);
width: 100%;
height: 100%;
opacity: 0.5;
top: 0;
left: 0;
display: block;
z-index: 1;
position: relative;
}
How can I get the semitransparent overlay overlay and the flexbox happening at the same time?
For .container:after, change position: relative to position: absolute.
Live, working example:
.container {
background: url("http://msue.anr.msu.edu/uploads/images/forest.jpg");
height: 400px;
width: 100%;
box-shadow: inset 0px -4px 14px 0px rgba(50, 50, 50, 0.71);
background-size: 100% auto;
z-index: 0;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.container p {
display: block;
color: red;
text-align: center;
font-size: 24pt;
background-color: blue;
z-index: 2;
}
.container:after {
content: '';
background: linear-gradient(135deg, #dc4225, #292484);
width: 100%;
height: 100%;
opacity: 0.5;
top: 0;
left: 0;
display: block;
z-index: 1;
position: absolute;
}
<div class="container">
<p>title goes here</p>
</div>
Codepen Version: http://codepen.io/anon/pen/gpqxoo
In case folks need to set position of the container to absolute like I do:
.container {
#include inline-flex;
#include flex-direction(column);
#include align-items(center);
#include justify-content(center);
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
font-size: 16px;
height: 100%;
width: 100%;
position: absolute;
white-space: normal;
z-index: 1;
}
.container::after {
content: ' ';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0,0,0,.8);
z-index: -1;
}
The importance pieces here are rgba, and z-index. Background image of the container is set dynamically in code, but that isn't relevant here.

Why Does Safari's CSS Positioning Break At Smaller Screen Widths

On my site, www.azletconsulting.com, when the site drops below 950px safari breaks the positioning of the Register to Vote, Join the Campaign etc menu positioning. At the larger sizes everything is aligned properly but as soon as it drops to one of the smaller css media queries the menu buttons break alignment. The code is the same between all the media queries and I have no issue in Chrome/Firefox.
.main_footer_menu {
left: 0;
bottom: 0;
top: 319px;
position: absolute;
width: 100%;
height: 80px;
background-color: rgba(93, 93, 93, 1);
z-index: 10;
box-sizing: border-box;
}
ul#menu-bottom-menu {
margin: 0;
padding: 0;
height: 80px;
}
li#menu-item-28 a {
left: -200px;
position: relative;
display: inline-block;
width: 200px;
height: 80.5px;
background-image: url("images/buttons/medium/rov.png");
background-size: 200px 80.5px;
background-repeat: no-repeat;
background-position: center;
text-indent: -99999999px;
overflow: hidden;
}
li#menu-item-29 a {
top: -90px;
position: relative;
display: inline-block;
width: 200px;
height: 80.5px;
background-image: url("images/buttons/medium/join.png");
background-size: 200px 80.5px;
background-repeat: no-repeat;
background-position: center;
text-indent: -99999999px;
overflow: hidden;
}
li#menu-item-30 a {
top: -175px;
left: 200px;
position: relative;
display: inline-block;
width: 200px;
height: 80.5px;
background-image: url("images/buttons/medium/contribute.png");
background-size: 200px 80.5px;
background-repeat: no-repeat;
background-position: center;
text-indent: -99999999px;
overflow: hidden
}
Try this:
.main_footer_menu {
left: 0;
bottom: 0;
top: 319px;
position: absolute;
width: 100%;
height: 80px;
background-color: rgba(93, 93, 93, 1);
z-index: 10;
box-sizing: border-box;
}
ul#menu-bottom-menu {
margin: 0;
padding: 0;
height: 80px;
}
li#menu-item-28, li#menu-item-29, li#menu-item-30 {
display: inline-block;
}
li#menu-item-28 a, li#menu-item-29 a, li#menu-item-30 a {
display: inline-block;
width: 200px;
height: 80.5px;
background-size: 200px 80.5px;
background-repeat: no-repeat;
background-position: center;
text-indent: -99999999px;
overflow: hidden;
}
li#menu-item-28 a {
background-image: url("images/buttons/medium/rov.png");
}
li#menu-item-29 a {
background-image: url("images/buttons/medium/join.png");
}
li#menu-item-30 a {
background-image: url("images/buttons/medium/contribute.png");
}