Having a 3 column layout where only the center content scrolls with the normal scrollbar is my current goal.
I've encountered an issue with the background-attachment: fixed property on the outer images/columns. While it works, I'm struggling to position the background images as desired.
So far, I've managed to get it to work by positioning the left image to the left and the right image to the right, but this is not the effect I'm aiming for. I want the images to remain tight and overflow at their outside edges when the page width is reduced.
I can provide examples to better illustrate my desired outcome.
1.) The first example has a scrolling fixed background image, but as the page widens, instead of staying close to the center content, they move towards the outsides. When they overflow, they do so towards the inside - I'm looking for the opposite behavior.
2.) The second example works perfectly except that the background images are not fixed and scroll along with the content.
The main difference between these examples lies in the background-position and background-attachment properties within the CSS.
The HTML & CSS code for the first example (which is close to working) is as follows:
html, body {
height: 100%;
margin: 0;
background-color: black;
font-family: Verdana;
}
.wrapper {
display: flex;
flex-direction: row;
justify-content: center;
background-color: #000;
height: 100%;
}
.leftTower {
background-attachment: fixed;
background-position: left top;
}
.rightTower {
background-attachment: fixed;
background-position: right top;
}
.side {
min-height: 775px;
flex-grow: 1;
background-repeat: no-repeat;
background-image: url("https://www.plaseebo.net/news/wp-content/uploads/2019/01/moonlight_gnaw_x_c-450x775.jpg");
}
.content {
max-width: 750px;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.mainContent {
background-color: #00ff00;
flex: 1;
}
.img-fluid {
max-width: 100%;
height: auto;
}
.text-center {
text-align: center;
}
@media only screen and (max-width: 750px) {
.side {
display: none;
}
}
<div class="wrapper">
<a href="http://www.example.com" target="_blank" class="side leftTower">
</a>
<div class="content">
<header class="text-center">
<img src="https://i.pinimg.com/originals/57/27/d7/5727d7e809ed08fb9cbda10b1f4a5e48.jpg" class="img-fluid" />
</header>
<main class="mainContent text-center">
This is the content area<br />
<div style="height: 220px;background-color: #0000aa;color: white;margin: 0 15px 0 15px;">
Taking up 220px of vertical space to show stick footer behavior
</div>
</main>
<footer class="text-center">
<img src="https://thecriticalcritics.com/review/wp-content/images/mid-noad.jpg" class="img-fluid" />
</footer>
</div>
<a href="http://www.example.com" target="_blank" class="side rightTower">
</a>
</div>