Tips for applying CSS3 box-shadow on two sides of a div?

Could you please review this code snippet:

http://jsfiddle.net/kerp3/

The inner box currently has a shadow on all four sides. I am looking to modify it so that the shadow appears only on the left and bottom sides.

Any suggestions on how to make this adjustment?

box-shadow: inset 0 0 9px 0 #000;

Answer №1

Is this solution helpful? It should function effectively across different web browsers.

.shadow {
    -moz-box-shadow: 3px 3px 4px #000;
    -webkit-box-shadow: 3px 3px 4px #000;
    box-shadow: 3px 3px 4px #000;
    /* For IE 8 */
    -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
    /* For IE 5.5 - 7 */
    filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}

The original source of this technique can be found here:

Answer №2

.shadow {
  -moz-box-shadow: 5px 5px 5px #ccc;
  -webkit-box-shadow: 5px 5px 5px #ccc;
  box-shadow: 5px 5px 5px #ccc;
}

Visit this site for more information on creating shadow effects in CSS: http://css-tricks.com/snippets/css/css-box-shadow/

Answer №3

By making small adjustments to the color and offsets, the solution becomes quite straightforward:

div { width: 300px; height: 300px; 

   box-shadow: inset 5px 5px 5px -3px #666;

}

Check out the jsFiddle link for a demo.

Answer №4

My recommendation would be to experiment with negative values in this scenario:

div { width: 300px; height: 300px;
    /* Give this a try. */
    box-shadow: inset 4px -4px 7px -4px #000; 
}

The first 4px adjustment moves the shadow box to the left by 4px, concealing what would typically appear on the right side if kept at 0.

The second -4px value shifts the shadow downwards vertically, effectively hiding the top part of the shadow.

While the 7px blur value may seem excessive, adding a spread of -4px will clip that extra blur, resulting in a soft grey shadow edge rather than the usual harsh black one.

Take a look at my demonstration here: http://jsfiddle.net/khalifah/vVUB5/

Answer №5

Applying a shadow only to select sides of a <div> may not be possible, but you can tweak the X and Y offsets to make sure the shadow is cropped on the undesired sides.

I achieved the desired effect in Safari with this code:

box-shadow: 7px -7px 9px #000 inset;

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

custard stealth style of jquery's mobile CSS

Is there a way to switch the jquery mobile CSS to a desktop-friendly CSS when a user is not on a mobile device? I am looking for a platform or existing CSS that can accomplish this. ...

Exploring the capabilities of storing and retrieving nested objects within a React database

I'm having trouble retrieving nested items from my database. This is how my database is structured: GET /dwelling/room/ [ { "room_id": 1, "room_name": "Living Room", "room_data": [ { "id": 1, ...

increase the font weight of the tooltip to make it stand out

Here is the code I have: $ToolTip = "test"; <td class="<?php echo BP_TBL_NUMBER_DATA_CLASS; ?>" Title="<?php echo $ToolTip;?>" ><?php echo $TotalStudentsCount; ?></td> ...

Retrieve the content of the 'div' element, but exclude certain text

I have a task to copy the content from a div into a textarea, allow for editing within the textarea, and ensure that any changes made are saved back to the original div. I also need to filter out an attribute, such as data-bind: "some stuff;", set for the ...

Leveraging the power of dual CSS classes for a single element

Can you help me troubleshoot this? I have a .social div, and I want zero padding on the top for the first one, and no bottom border for the second one. I tried creating classes for the first and last scenarios, but it seems like something is off: .socia ...

What is the best way to add color to a Table Header?

I'm working on a HTML/CSS table and I want the header row to have a specific background color. Below is my code: <table class="contentTable"> <tr class="contentTableHeader"> <th>No.< ...

Develop a JavaScript function to create a DIV element and retrieve the text content using a JavaScript constant

Seeking assistance with creating a JavaScript function to add a dynamic DIV with specific configuration. Current setup: <div class="tooltip" > <font class="textStyleInfo"><b>( ...

blurred image effect on bootstrap card hover

My attempt to create a blurred image effect on a bootstrap card hover is not working as expected. The blur effect works fine without the hover. Here is the code I have been using: .card-img { transition: all 1s ease; -webkit-filter: blur(0px); ...

What is the most effective way to determine which radio button is currently selected in a group with the same name using JQuery?

<form class="responses"> <input type="radio" name="option" value="0">False</input> <input type="radio" name="option" value="1">True</input> </form> Just tested: $('[name="option"]').is(':checked ...

A versatile Material UI paper that adjusts its dimensions dynamically

Utilizing Material-UI's Paper component (https://mui.com/components/paper/), I've encountered a scenario where the content within the Paper element needs to be dynamic. <Paper className="modal" elevation={3}> ...Content </Paper ...

Maximizing image size with dynamic height and automatic width using the NextJS Image Component

I am trying to set my images to have a fixed pixel height and automatic width using object-fit: contain. How can I achieve this with the NextJS Image Component without using layout="fill" so that the intrinsic width of the image (width: auto) is ...

Ways to extract JSON data from multiple JSON arrays

Within the snippet below, I am attempting to extract the value of women. Right now, I can successfully retrieve 1. Personal care appliances and 2. Jewelry. However, if I try to check any checkbox after that, I encounter an error stating "Uncaught TypeError ...

Switch to display only when selected

When I click on the details link, it will show all information. However, what I actually want is for it to toggle only the specific detail that I clicked on. Check out this example fiddle Here is the JavaScript code: $('.listt ul').hide(); $( ...

Using JQuery to determine the height of a div element

I'm currently working on a full-screen fluid XHTML/CSS website. One particular challenge I have encountered involves loading content into a div element via AJAX that may exceed the visible area of the page, disrupting the full-screen layout. To addres ...

Tips for transitioning from custom CSS to Material UI's CSS in JS

I came across a project where someone implemented components with custom CSS. One interesting thing I noticed was a wrapper component, similar to Material UI's Container or just a simple div with applied styles. export const Container = styled.div` ...

Is there a way to partially conceal the H2 text using CSS?

Is there a way to partially hide H2 text using CSS? I have the following code: HTML: <div class="twocol-box1 superflex-content-6-12"> <h2 data-content="My - Text&amp;nbsp;<span style=&quot;float:right;&quot;>M ...

Deleting a particular tag with regular expressions: a step-by-step guide

I'm attempting to remove a ul tag along with any nested tags inside it. <ul class="related"> <li><a href="/related-1.html" target="_blank">Related article</a></li> <li><a href="/related-2.html" target="_blank"&g ...

Explain the inner workings of the setTimeout() function in JavaScript

My goal is to create a line in my code by placing points according to the line equation and adding a 100 millisecond delay before each point is displayed. However, when I try to run the code, it seems to wait for some time and then displays all the points ...

"Learn the simple trick to quickly deactivate an anchor tag in just one easy

I have a navigation bar with items listed in an unordered list: <ul id="mainN" class="nanGroup" ng-show="lCntr.only == 'mainNav'"> <li > <a class="btn btn-small btn-revert" ng-click="lCntr.profile()"></a> &l ...

My custom Material UI table is being hindered by unnecessary div tags that are interfering with my CSS styling

View the generated code The rendered table demonstrates that when scrolling past the maximum width, the data does not appear <div> <table (not going to display all the markup for this. this table contains the headers of each column and appear ...