Positioning a card outside of the header container using CSS

I have been trying to position a card on top of a gradient background without it getting cut off at the end. I attempted using margins to push the card down, but it didn't work as expected. Z-index and position: absolute were also unsuccessful in fixing this issue. How can I ensure that the card sits perfectly over the gradient background? Here is the code snippet I am working with:

.content-container-header {
  overflow: hidden;
  height: 800px;
  -webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  background: linear-gradient(#f5fafd, #E8F3F9);
}

.flex-display {
  display: flex;
}
// More CSS code here
<div class='content-container-header flex-display justify-center margin-bottom-96'>
  <div class="container-1200 header-content-posts">
    <div class="flex-display flex-display-col justify-center align-center margin-top-128">
      <h1 class="text-dark-blue heading-48 margin-top-disabled margin-bottom-20">
        Placement Header
      </h1>

    </div>
    <div>
      <div class="flex-display align-center featured-post-ct margin-top-300">
        <div class="div-50 margin-r-32 ">
          <img alt="" height="308px" width="472px" src="https://media.istockphoto.com/photos/modern-skyscrapers-in-business-district-picture-id1137991385?k=20&m=1137991385&s=612x612&w=0&h=dcSq5oF99RjNW0kQo-LtkUg-Wf15ofZRg87pBOVWLkk=" />
        </div>
        
        <div class="div-50">
          <div> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eget mi in rhoncus. Praesent dignissim libero a purus facilisis, eu blandit tortor mollis. Maecenas vitae justo ac tortor rhoncus congue.</div>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

When a parent element is masked, the child elements within it are not visible.

To work around this issue, you can reposition your background using CSS alone by utilizing the :before pseudo-element.

/* The previous code is now obsolete */
/* .content-container-header {
  height: 800px;
  -webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  background: linear-gradient(#f5fafd, #E8F3F9);
  clip-path: ellipse(100% 95% at top);
  background: radial-gradient(100% 95% at top, #000 100%, #0000);
} */

/* Use a pseudo element for the cropped background */
.content-container-header:before {
  content: "";
  display: block;
  height: 800px;
  width: 100%;
  position: absolute;
  z-index: -1;
  -webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  background: linear-gradient(#f5fafd, #E8F3F9);
}

.flex-display {
  display: flex;
}

.justify-center {
  justify-content: center;
}

.margin-bottom-96 {
  margin-bottom: 96px;
}

.header-content-posts {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.container-1200 {
  margin: 0 auto;
  max-width: 1200px;
}

.margin-top-128 {
  margin-top: 128px;
}

.margin-top-300 {
  margin-top: 300px;
}

.align-center {
  align-items: center;
}

.flex-display-col {
  flex-direction: column;
}

.featured-post-ct {
  width: 978px;
  height: 308px;
  background: #FFFFFF;
  -webkit-box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
  box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
  border-radius: 8px;
}

.div-50 {
  width: 50%;
}

.margin-r-32 {
  margin-right: 32px;
}

.margin-bottom-8 {
  margin-bottom: 8px;
}
<div class='content-container-header flex-display justify-center margin-bottom-96'>
  <div class="container-1200 header-content-posts">
<div class="flex-display flex-display-col justify-center align-center margin-top-128">
  <h1 class="text-dark-blue heading-48 margin-top-disabled margin-bottom-20">
    Placement Header
  </h1>

</div>
<div>
  <div class="flex-display align-center featured-post-ct margin-top-300">
    <div class="div-50 margin-r-32 ">
      <img alt="" height="308px" width="472px" src="https://media.istockphoto.com/photos/modern-skyscrapers-in-business-district-picture-id1137991385?k=20&m=1137991385&s=612x612&w=0&h=dcSq5oF99RjNW0kQo-LtkUg-Wf15ofZRg87pBOVWLkk=" />
    </div>
    
    <div class="div-50">
      <div> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eget mi in rhoncus. Praesent dignissim libero a purus facilisis, eu blandit tortor mollis. Maecenas vitae justo ac tortor rhoncus congue.</div>
    </div>
  </div>
</div>
  </div>
</div>

Answer №2

If you're trying to work around the mask on the main element, it might be best to place that information outside of it.

.content-container-header {
  overflow: hidden;
  height: 800px;
  -webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  background: linear-gradient(#f5fafd, #E8F3F9);
}

.flex-display {
  display: flex;
}

.justify-center {
  justify-content: center;
}

.margin-bottom-96 {
  margin-bottom: 96px;
}

.header-content-posts {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.container-1200 {
  margin: 0 auto;
  max-width: 1200px;
}

.margin-top-128 {
  margin-top: 128px;
}

.margin-top-300 {
  /* margin-top: 300px; */
}

.align-center {
  align-items: center;
}

.flex-display-col {
  flex-direction: column;
}

.featured-post-ct {
  width: 978px;
  height: 308px;
  background: #FFFFFF;
  box-shadow: 0px 8px 24px -4px rgb(150 166 198 / 18%), 0px 2px 6px -1px rgb(150 166 198 / 16%);
  border-radius: 8px;
}

.div-50 {
  width: 50%;
}

.margin-r-32 {
  margin-right: 32px;
}

.margin-bottom-8 {
  margin-bottom: 8px;
}

.margin-top-neg-a-bunch {
  margin-top: -240px;
}

.position-relative {
  position: relative;
}
<div class='content-container-header flex-display justify-center margin-bottom-96'>
  <div class="container-1200 header-content-posts">
    <div class="flex-display flex-display-col justify-center align-center margin-top-128">
      <h1 class="text-dark-blue heading-48 margin-top-disabled margin-bottom-20">
        Placement Header
      </h1>

    </div>
  </div>
</div>

<div class="margin-top-neg-a-bunch position-relative">
  <div class="flex-display align-center featured-post-ct margin-top-300">
    <div class="div-50 margin-r-32 position-relative">
      <img alt="" height="308px" width="472px" src="https://via.placeholder.com/400" />
    </div>

    <div class="div-50">
      <div> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eget mi in rhoncus. Praesent dignissim libero a purus facilisis, eu blandit tortor mollis. Maecenas vitae justo ac tortor rhoncus congue.</div>
    </div>
  </div>
</div>

Answer №3

The card is being cut off due to the overflow property being set to hidden on the .content-container-header element.

To fix this issue, update the CSS to:

.content-container-header {
  overflow: visible;
  height: 800px;
  -webkit-mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  mask: radial-gradient(100% 95% at top, #000 100%, #0000);
  background: linear-gradient(#f5fafd, #E8F3F9);
}

By making this change, the problem should be resolved.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on replacing the character "&" in PHP with ease

I am encountering an issue where some output on the page contains a space character written as "&nbsp;". I need to replace it back with a regular space. I attempted using str_replace("&nbsp"," ",$mystr) and even preg_replace("/(&nbsp;)/", " ", ...

Executing a JavaScript function at a specified interval

I am a beginner in the world of programming and javascript. What I aim to accomplish : Executing a JavaScript function on page load, specifically showVideo(). I would like this function to run for approximately 10 seconds before moving on to the next func ...

Is your evo-calendar plagued by date-covering dots?

Can the evo calendar limit the dots displayed by the dates to two or arrange them in a way that they do not cover the date? (div.type-bullet) Also, please critique my code and help me improve. Thank you for your assistance - SimonI mean this: P.S. most of ...

Tips for limiting a website to load exclusively within an iframe

I am managing two different websites: https://exampleiframe.com (a third-party website), https://example.com (my own website) My goal is to limit the loading of https://example.com so that it only opens within an iframe on https://exampleiframe.com To a ...

Creating a circular price display using CSS:

Below is the code snippet that I am working with: .special-price { text-align: center; background-color: #2e566e; } .special-price .offer { border-radius: 50%; background-color: #56c243; color: #fff; font-weight: 700; font-size: 18px; h ...

What causes Chrome to crash when dealing with lengthy tail files?

My objective is to display a log file in real-time using a websocket connection. However, I am facing performance issues with Chrome when the paragraph ('p') element in the HTML becomes large (about 450 lines). This is the current implementation ...

Switching back and forth between classes prevents the animation from playing continuously, causing it to jump straight to the end

Currently, I am in the process of animating a hamburger menu with a unique twist. The idea is to have the top and bottom lines smoothly translate to the middle and then elegantly rotate into an X shape when clicked. My approach involves toggling between tw ...

Guide on using timestamps in PHP

I am struggling to incorporate the current date and time of the SO-NUMBER that the user is entering. The issue I'm encountering lies within the IF..ELSE loop, it only updates one column in the database, which is the "samplerecived" column even if I ...

Ways to align pictures in the center vertically when placed side by side

Can someone help me make the transition between tall and short images on my website smoother? I am not familiar with coding terminology, so please bear with me. The attached image provides a visual representation of the changes I am looking for: click he ...

Experience the sleek transparency when black hues grace the interface on iOS 14 and above

When implementing the code snippet below, .packages > .ulWrapper::after { background: linear-gradient( to left, var(--edge-color) 5%, rgba(0, 0, 0, 0) 95% ); /* option 1 - red */ background: linear-gradient( to left, var(--edg ...

When exporting data to PDF with DomPDF in Laravel, the second column appears elongated

I am utilizing DomPDF within a Laravel project. While it prints correctly, the second column image is being stretched. My goal is for both columns to evenly occupy half of the available space. I will now provide my code below. CSS Files: header { posi ...

Navigating CSS Files in CodeIgniter Views: A Simplified Guide

I am encountering an issue where I am unable to load my .css and .js files on views other than the default_controller's index() function. It seems that only this specific view has access to these files. The destination folder itself is not the problem ...

"Restricting the height of a DIV container based on the size

Struggling with CSS as I try to get my #wrapper DIV to adjust its size based on its contents. I've experimented with 100% height and min-height, but nothing seems to work. Could it be related to relative versus absolute positioning? Here's a snip ...

I am facing an issue where Chrome is causing my image set with max-width to stretch

I am currently facing an issue with adjusting the max-width of images in the CMS I am working with. When I set a max-width in Chrome (haven't tested in other browsers yet), the height of the image ends up getting stretched - you can view the problem h ...

Retrieve content from the pushState state object

$(function(){ $('button').click(function(e){ e.preventDefault(); var nextUrl = 'page1.html'; var previousUrl = window.location.href; $.get(nextUrl, function(data){ $('body').ht ...

What is the best way to enable drag-and-drop functionality for all child elements with the

I am looking for a way to make all contenteditable child elements draggable using jQuery, without the use of external plugins. I came across this helpful code snippet on How do I make an element draggable in jQuery?. function draggable(e){ window.my_ ...

Showing a JavaScript array within an HTML table

I've been working on an HTML page where I'm retrieving data from a database. The array is functioning properly, and I've successfully filtered it using a for loop to access the objects in an el function. While the console log works correctly ...

What is the best way to set a default value for a password form input field?

I'm currently working on creating a form with input fields similar to those found on Twitter. I want to set default values for the input fields, which I have successfully done. However, when it comes to the password field, the default value is present ...

Does each HTML element have a one-to-one correspondence with a DOM element at all times?

Can an element be present in the DOM without appearing in the HTML code? And can it also be the other way around? ...

How can we prevent the restoration of size effects in jQuery UI versions 1.9 and above?

After implementing jQuery UI 1.9 or newer, I noticed that the size effect returns to its original state. Below is a snippet of my code: http://jsfiddle.net/mQCxY/ $(function () { $('.circle').click(function () { $(this).effect("size ...