Ways to establish the gradient

Here is the code snippet I am currently working with.

.imgcol1 {
  background-image: url(https://picsum.photos/200/300);
  background-repeat: no-repeat;
  background-size: cover;
  height: 190px;
  width: 520px;
}

.col1 {
  margin: 75px;
}

.grad {
  background: linear-gradient(to right, rgba(102, 126, 234, 0.7), rgba(245, 245, 245, 0.7))
}
<div class="row vh-100 mt-5 d-flex justify-content-center">
  <div class="col-6 imgcol1 col1 text-white">
    <p>California</p>
    <h2>Sacramento</h2>
    <p>Esplora <i class="fa-solid fa-arrow-right"></i></p>
    <div class="row grad">

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

I am trying to achieve a linear gradient effect as depicted in the image.

My initial approach was to create a row within the column and apply the gradient to that row, but it didn't yield the desired results.

If anyone has suggestions on how to properly implement this gradient effect, please share your insights. Thank you!

Answer №1

Upon closer inspection, it is evident that the gradient functions as an overlay rather than a background element. This means that it sits atop the image instead of being positioned behind it.

HTML

.imgcol1 {
  background-image: url(https://picsum.photos/200/300);
  background-repeat: no-repeat;
  background-size: cover;
  height: 190px;
  width: 520px;
  /*  filter: drop-shadow(-30px -10px 4px #4444dd); */
}

.col1 {
  margin: 75px;
}

.grad {
  background: linear-gradient(to right, rgba(102, 126, 234, 0.7), rgba(245, 245, 245, 0.7))
}

.myGrad {
  z-index: 999;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(to right, rgba(102, 126, 234, 0.5), rgba(245, 245, 245, 0.0), rgba(245, 245, 245, 0.0));
  transform: translate(-11%, -95%);
}
<div class="row vh-100 mt-5 d-flex justify-content-center">
  <div class="col-6 imgcol1 col1 text-white">
    <p>California</p>
    <h2>Sacramento</h2>
    <p>Esplora <i class="fa-solid fa-arrow-right"></i></p>
    <div class="row myGrad">

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

To achieve the desired appearance for the box and gradient, you can adjust the values within the ".myGrad" class. A working example can be found on this CodePen link.

Answer №2

Within the CSS, I have added some comments for clarity. The layout has been adjusted slightly to incorporate two columns: one containing text and an image, and the other featuring a gradient effect.

An issue arises with the gradient's transform property extending beyond its container. Uncommenting the border lines can provide a visual representation of this discrepancy.

It is important to note that Bootstrap has been included in this example to set the text color to white.

.outer-container {
  /* border: solid 1px lime; */
}

.outer-row {
  /* border: solid 1px blue;*/
}

.image-column {
  background-image: url(https://picsum.photos/200/300);
  background-repeat: no-repeat;
  background-size: cover;
  height: 190px;
  width: 100%;
}

.column-text {
  /*  border: solid 1px yellow; */
}

.gradient-column {
  /* force layout - this or &nbsp; in the html */
  border 1px solid transparent;
  background: linear-gradient(to right, rgba(127, 156, 179, 0.9), rgba(245, 245, 245, 0.0));
  /* move this a bit left and up */
  transform: translate(-8%, -115%);
  height: 190px;
  /* force this behind */
  z-index: -999;
  /* border: 1px solid #444488; */
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98faf7f7ecebeceaf9e8d8adb6a9b6ab">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b2d24253f2a3c2e3824262e662d392e2e0b7e657a7e657f">[email protected]</a>/css/fontawesome.min.css" integrity="sha384-jLKHWM3JRmfMU0A5x5AkjWkw/EYfGUAGagvnfryNV3F9VqM98XiIH7VBGVoxVSc7" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="197b76766d6a6d6b7869592c3728372a">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>

<div class="container outer-container">
  <div class="row outer-row">
    <div class=" col-12 mt-5 d-flex ">
      <div class="col col-12 image-column column-text text-white">
        <p>California</p>
        <h2>Sacramento</h2>
        <p>Esplora <i class="fa fa-solid fa-arrow-right"></i></p>
      </div>
    </div>
    <div class="col col-12 gradient-column"></div>
  </div>
</div>

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

What is the best way to arrange my crimson blocks to sit next to each other?

Is there a way to align the red boxes side by side with some space in between them for separation, and how can I ensure that the signin/signup button appears against the blue background of the header? I attempted using float but encountered issues. The d ...

Swapping out LinkButtons using jQuery

[EXPLANATION] (apologies for the length) In my gridview, users have the option to add a new entry or edit an existing one. When they click on either 'Add' or 'Edit', a popup window appears for them to input the information for the new ...

Header misalignment occurs when the user scrolls up too quickly causing it to display

One interesting feature on my website is that the header disappears as users scroll down the page, but reappears when they start scrolling back up, even if they are halfway down. However, if a user quickly scrolls up and down, there seems to be an issue wi ...

Customize the appearance of the bootstrap nav-bar by assigning unique background colors to each dropdown menu

I'm looking to set unique background colors for each dropdown in a Bootstrap nav-bar using CSS. .mynavbar .dropdown ul.dropdown-menu:nth-child(1) { background-color: #59b057; } .mynavbar .dropdown ul.dropdown-menu:nth-child(2) { background-col ...

Tips on maintaining the original text hues that were established using setForeground() when a QTableWidgetItem is picked

Issue at Hand: Currently, when the first row is selected as shown in Figure 2 below, all text colors are changed to black, instead of maintaining their original style displayed in Figure 1. Is there a way to retain the original colors when a row is selec ...

What is the most effective method to arrange absolute divs generated randomly in a grid-like formation?

Hey there! I'm facing an intriguing challenge with my app. It's designed to generate a variable number of divs which are always in absolute positioning. Unfortunately, making them relative is not an option due to some other factors within the app ...

CSS: Continuous Automated Slide Transitions

What CSS code do I need to incorporate into my code to create a continuous Slider Animation? I want the pictures to slide automatically one by one, with a specified time interval between each slide when not on hover. The hover function is already included ...

Locate the class ID and refine the search results by another class

I am currently working on a task that involves extracting the first <li> element's id where it has the class name my_class, and checking if the <span> with the class Time contains a ":" using jquery. Below is the sample HTML structure: & ...

Can an action be activated when the mouse comes to a halt?

Currently, I am having trouble triggering an event when a user stops moving their mouse over a div element. The current event is set up to show and follow another element along with the mouse movement, but I want it to only display when the mouse stops mov ...

Step by step guide on how to connect a stylesheet in CSS

Hey there, I recently attempted to link a style sheet in my HTML for the first time. Unfortunately, I encountered an issue where it didn't work. Here's the code I used: <link href="css/StyleSheet.css" rel="stylesheet" type="text/css" /> W ...

What is the best way to ensure input text fills the entire grid?

Take a look at this code snippet: <div class="form-group col-md-6"> <label class="col-md-4">Last Updated (Real Time)</label> <input class="form-control col-md-8" type="text" ng-model="status.lastUpdated" ng-readonly="true"/ ...

Failure to display masonry arrangement

I am working on creating a stunning masonry layout for my webpage using some beautiful images. Take a look at the code snippet below: CSS <style> .masonryImage{float:left;} </style> JavaScript <script src="ht ...

Ways to make ionic slides adhere to column width

I've been immersing myself in learning the latest versions of AngularJS and Ionic through practical application. I am currently working on a page that uses ionic rows and columns to display JSON data. The layout includes a 50/50 column setup, with a t ...

The alignment and sizing issues with stacking icons using fontawesome are still unresolved

I have been exploring the use of stacked icons with fontawesome, following a helpful blog post by Dave Gandy. Although stacking is working well, I am facing an issue aligning a stacked icon with a non-stacked icon (which is fa-5x). It's challenging t ...

Reposition various div elements within a static container

Struggling to align div boxes like the image below was exhausting: I attempted fixing it with the code provided in this JSBIN link. How can I resolve the issue and adjust the layout as desired? Any help would be greatly appreciated. Thank you in advance ...

Having trouble with the scrolling feature on a read-only text area within a form

My form allows users to input their data, but once submitted, the form becomes read-only. However, I'm facing an issue where the data in the text area is not scrollable even though it should be. I need assistance in figuring out why the content in th ...

Varied elevations dependent on specific screen dimensions

There seems to be a minor issue with the height of the portfolio container divs at specific window widths. The problematic widths range from 1025 to 1041 and from 768 to 784. To visualize this, try resizing your browser window to these dimensions on the fo ...

completing data tables and presenting them to clients

I am currently working on a website for a Nutrition specialist who requires a monthly diet regimen table with five meals daily. The doctor will be responsible for completing these tables, which will then be presented to clients. It's important that th ...

Creating a dropdown menu with a blur effect using CSS

I attempted to match the opacity and blur effect of my dropdown menu with that of my navbar. While the opacity adjustment worked correctly, the blur effect did not apply as expected. I've heard that I need to utilize a pseudo-class to achieve this, b ...

Resizing the elements within an iframe: Troubleshooting problems with embedding Bandcamp players

My goal is to embed a Bandcamp music player on my WordPress blog page, but I'm facing a challenge. The maximum width of the current player is 700px and I need it to be 900px. After consulting with someone at Bandcamp, they directed me to the old versi ...