Ways to soften the edges of a picture by utilizing CSS

I am trying to achieve a feathered effect on the edges of an image within an unordered list that contains 3 list items. Each list item has an image and 3 text-containing divs. I am looking for a CSS-only solution to achieve this effect.

Currently, my website located here has a feathered effect using the provided HTML for the image. However, the effect covers the entire image rather than just the edges. I am looking to have a strong feathered effect on the very edges of the image that fades out towards the center, spanning approximately 50px on all sides.

Here is the HTML code:

<p class="vignette"><img src="http://upload.wikimedia.org/wikipedia/commons/f/f8/Ellen_H._Swallow_Richards_House_Boston_MA_01.jpg" alt="" /></p>

And the CSS code:

p.vignette {
  position: relative;
}

p.vignette img {
  display: block;
  width:80%;
  margin-left:auto;
  margin-right:auto;
  margin-top:6%;
}

p.vignette:after {
  -moz-box-shadow: inset 0 0 180px #defeec;
  -webkit-box-shadow: inset 0 0 180px #defeec;
  box-shadow: inset 0 0 180px #defeec;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  content: "";
}

I have tried using an inset box shadow of 50px, but it is barely noticeable, and 180px feathers the entire image. How can I achieve a strong feathered effect on the edges that fades towards the center?

Thank you!

Answer №1

To make this work, you'll need to make some adjustments. Start by removing the inline-block property from the <a class='divLink'> tag. Then, try the CSS code below:

.vignette {
    width: 80%;
    margin: 1em auto;
    box-shadow: 50px 50px 113px #defeec inset,-50px -50px 110px #defeec inset;
    height: 150px;
    background-size: contain;
    background-repeat: no-repeat;
}

Next, use the following HTML code (and remove the <img> tag):

<p class="vignette" style="background-image: url(http://upload.wikimedia.org/wikipedia/commons/f/f8/Ellen_H._Swallow_Richards_House_Boston_MA_01.jpg);"></p>

Alternatively, you can include the background-image property within the CSS block. However, in some cases, defining the background image inline may be more practical, especially when dealing with multiple images or similar elements.

Answer №2

Within the vignette element, create a new div called fade to add a fading effect before the img appears.

.fade {
        height: 100%;
        width: 100%;
        position:absolute;
        background: -webkit-linear-gradient(left, 
                    rgba(0,0,0,0.65) 0%, 
                    rgba(0,0,0,0) 20%,
                    rgba(0,0,0,0) 80%,
                    rgba(0,0,0,0.65) 100%
        );
    }
<p class="vignette">
        <div class="fade"></div>
        <img src="http://upload.wikimedia.org/wikipedia/commons/f/f8/Ellen_H._Swallow_Richards_House_Boston_MA_01.jpg" alt="" />
    </p>

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

Can AJAX be used when submitting an HTML form with a select input field?

I have been working on an Ajax search suggest input and have successfully implemented it. However, I would like to tweak the script so that when a suggestion is selected, the form auto-submits. Below is my JavaScript code: <script> function suggest ...

Alternative solution to avoid conflicts with variable names in JavaScript, besides using an iframe

I am currently using the Classy library for object-oriented programming in JavaScript. In my code, I have implemented a class that handles canvas operations on a specific DIV element. However, due to some difficulties in certain parts of the code, I had t ...

The site is visually appealing in Firefox, but has a few issues on Chrome

I've encountered a common issue where my website displays perfectly in Firefox but looks terrible in Dreamweaver and Chrome. To fix it, I made live CSS edits in Firefox then copied them to Dreamweaver resulting in a mess. Here's how it should lo ...

Crafting CSS for styling input type file elements

My attempts to style the input type file with CSS have been unsuccessful. In my current code, the "choose file" button is displaying above my styled button. How can I use CSS to remove this? I am aiming to only display a blue colored button for uploading ...

Make the image take up the entire screen in HTML

My goal is to display an image that fills the entire screen. Here's how my HTML code looks: <!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8" /> <title></title> </head> ...

What could be causing the malfunction of BS4 Scrollspy?

I'm having trouble with implementing Bootstrap 4's Scrollspy feature. Despite going through the BS4 documentation and watching a Scrollspy tutorial on YouTube, I still can't seem to get it to work properly. Currently, I am using a CDN for BS ...

"Pros and Cons of Using Extended URLs vs Concise URLs in SEO

Currently, I'm developing a website and I find myself uncertain about which link structure would be most beneficial for SEO purposes. Which format is more likely to receive a higher ranking from Google? Should I go with domain.com/users/username or d ...

Choosing a class using CSS

Can someone please help me with editing this HTML code using CSS? I'm trying to target the coupon divs using #coupon but it doesn't seem to be working. Any assistance would be greatly appreciated. <div class="coupon"> <h1>Classic ...

Adjust the size of the embedded iframe to match the dimensions of the containing div

Is there a method to resize the iframe embed code for a vine so that it fits within the boundaries of the enclosing div? The supplied embed code already includes sizing information as shown below: <iframe src="https://vine.co/v/iMJzrThFhDL/embed/simp ...

Struggling to target specific elements in CSS that are dynamically generated through JavaScript

After using JavaScript to generate some divs, I ended up with the following code: const container = document.querySelector('#container'); for(let i = 1; i < 17; i++) { var row = document.createElement('div'); row.id = 'r ...

Do AngularJS routes allow the use of special characters in URLs?

Issue at hand: Every time I enter http://localhost:53379 in the browser, it redirects me to http://localhost:53379/#/. Why is the /#/ being added? angular .module('app', ['ngRoute', 'ngStorage']) .config([&apo ...

Revamp the appearance of angular material inputs

I have been working on customizing the style of an Angular Material input. So far, I successfully altered the background-color with the following code: md-input-container { padding-bottom: 5px; background-color: #222; } I also changed the placeh ...

How can I align a button right next to the table row data in HTML using Bootstrap?

Is there a way to add a button next to the table data in each row without a border? I attempted to create a new column for the button, but the border interferes with the design. I am using Bootstrap 4 for this project. Here is the HTML code: <div cl ...

The alignment of an image within a bootstrap table cell may not appear centered

I am struggling to center an image in a table cell that is wider than the image itself. I have tried using the text-center and align-middle classes in Bootstrap, but the image remains on the left side of the cell. Since I am new to Bootstrap, I am not fa ...

Ensure that the form is submitted when a checkbox is clicked, while also maintaining the native browser

My form contains a text input field and a checkbox. The text input must not be left empty when the form is submitted, which is why the required attribute is used. I want the form to be submitted every time the checkbox is clicked, while still maintaining ...

My website is currently being hosted on Github, but I am experiencing issues with the CSS. I keep getting an error message saying "Failed to load resource: the server responded

view image here I recently uploaded my website on Github and am facing an issue with the CSS file not working properly. Can someone please help me troubleshoot this problem? website link Github repository I have reviewed the links connecting the HTML t ...

tips for personalizing your jQuery image preview script

Currently, I have implemented a jQuery script that allows me to preview multiple images before uploading them. Although the functionality works well, I am facing difficulties customizing it to meet my specific requirements. <script> $(document).r ...

What could be preventing the background color from changing when attempting to use style.backgroundColor?

My objective is to store the current tab background color in a variable and then use that variable to change the body color. However, for some reason it is not working as expected. Can you help me figure out why? const tabName = 'someId'; var ...

Interactive email with a dynamic dropdown feature

I am currently working on creating an HTML email that can display data depending on the selection made from a dropdown menu within the email itself. Despite my research, I have not come across a suitable solution for this specific scenario. My current app ...

Guide to removing selected value from a combobox in Angular

I am working on a simple HTML file that consists of one combobox and one clear button. I want the clear button to remove the selected value from the combobox when clicked. Below is my code: mat-card-content fxLayout="row wrap" fxLayoutAlign="left" fxLayou ...