Is it possible for the box-shadow CSS property to include padding?

Can a red outline like this be created around a shape using the box-shadow property but at a certain distance?

Answer №1

Indeed, it is possible to add two shadows, with the inner one matching the background color. Personally, I find using border and outline a more preferable approach.

div {
  margin: 50px;
  width: 300px;
  height: 100px;
  background-color: aquamarine;
  box-shadow: 0px 0px 0px 8px #FFFFFF, 0px 0px 0px 17px #CCC7CA;
}
<div></div>

Here is an alternative method without using box-shadow:

#background {
  background-color: darkblue;
  display: block;
  height: 100vh;
  padding: 50px;
}

#box {
  width: 300px;
  height: 100px;
  background: aquamarine padding-box;
  border: 8px transparent solid;
  outline: 9px #CCC7CA solid;
}
<div id="background">
  <div id="box"></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

Creating a grid layout similar to Tumblr using HTML and CSS

Struggling all day to figure out how to create a Tumblr-style grid for my website, I'm reaching out here for some assistance. Here is the page: I have a grid of images on my project page that initially looked fine, but as I try to add new elements, i ...

ReactJS continuously updating data with new props

Being a beginner in React, I'm still trying to navigate my way around the framework. I currently have a component that fetches data in order to render an HTML table. So, I utilize my Actions' fetchData() (which makes use of the browser's fe ...

Angular's ngClass directive failed to be applied correctly

I am currently experimenting with the use of [ngClass] in Angular and it appears that it is not being applied as expected. Interestingly, [ngStyle] for similar CSS styles is working without any issues. What could I be doing wrong in this scenario? There ar ...

The inline script is deemed non-compliant as it infringes upon the Content Security Policy directive: "script-src 'self'"

My chrome-extension is built using react-create-app. However, I encountered an error when running npm run build in react-create-app: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src &apo ...

Customizing SharePoint Web Part Styles with CSS: Header Alignment Issue with Body_TEXT

I am currently working on branding a SharePoint website and have encountered an issue with aligning background colors for the title area and body of some web parts. Despite applying background colors, the alignment between the title and body areas is off ( ...

A guide on rotating loaders and inserting custom text within loaders using CSS

Seeking assistance to modify my code for creating a unique loader design. The inner loader needs to remain static with only top and bottom segments, while the middle loader rotates anti-clockwise and the outer loader rotates clockwise. Additionally, the ...

Solving the Color Change Mystery in Your Dash Application

My goal is to design a sleek black dashboard, so I acquired a CSS stylesheet that should give my dashboard a black theme. Following the instructions, I created an assets folder in the root directory of my app and added my CSS and JavaScript files there. Da ...

Adjust the height of the outer div automatically

Currently, I am attempting to dynamically set the height of div#container so that it adjusts based on its relative positioning and the absolute positioning of inner divs. Essentially, I want the inner divs to be centered within the container. <div id=" ...

I am having an issue in React.js where my state is not updating until the second click instead of the first one

Whenever I click items on my dropdown menu, the state only updates after clicking twice. I have provided a video and some code snippets for reference. How can I resolve this issue? https://i.sstatic.net/LkXUx.gif Parent Class Component (APP): class App e ...

What could be causing my Express server to return a 404 error when trying to submit the form, all while failing to display any console

Having trouble setting up multi-user sessions similar to Google Docs, but my server file seems unresponsive. I've double-checked my fetch function and ensured it is accurate, yet no changes are occurring. Even console.logs from the server file command ...

Having a fixed footer in JQuery mobile does not adjust its position downwards as intended

I attempted to move the footer down using the provided code below, but it doesn't seem to be working. I even went ahead and removed all standard text from the CSS file to eliminate any potential issues. It should normally shift downward with <div ...

Triggering React MUIDatatable to redirect to a new page upon clicking a row

When a user clicks on a row in my MUIDataTable, I want to navigate to a different screen. Only one row should be clickable. Here is my attempt: const options = { selectableRows: true, selectableRowsOnClick: true, onRowClick: useHistory('/app/p ...

Whenever I attempt to use window.print(), the styling gets completely messed up. I've experimented with both @media screen and @media print, but unfortunately, I

I am working on creating an invoice, the design looks perfect in the browser, but when I try to window.print() the style gets corrupted. I attempted to include @media screen and @media print, but I am still facing the same issue. The invoice form is incorp ...

Guide to horizontally aligning a div with a dynamic width in the center

After extensive research, I discovered that setting a width allows you to center a div using margin: 0 auto along with left: 0;, right: 0, and position: absolute. However, all the examples I found had a specified width. In my specific case, I need to cent ...

Unable to understand the reason behind why the button is not being displayed

I'm having trouble with my quiz app. I have a button to submit answers and move on to the next question, but whenever I try to place it within the div that contains the quiz, the button disappears. Can someone please help me figure out what's wro ...

Having trouble resolving row border issues with CSS in DataTables?

I need to enhance the appearance of specific rows in my table by adding a darker border at the bottom. To achieve this, I have assigned a custom class (des-rec-row) to the rows and included the following CSS code: .des-rec-row { border-bottom: 1px soli ...

When transitioning to mobile size, I aim to maintain the consistent design of my background-color circle using Bootstrap 5

I am working on creating a card design with a colored background instead of an image. However, I am facing an issue where the rounded-circle background color changes to an ellipsoid shape after passing the mobile size (sm or xs). Here is what I am aiming ...

The parent is relatively positioned and its child is absolutely positioned and floated to the left

I'm currently working on a design where I have a group of parent containers with the float left property applied. Inside each parent container, there is a child div with position absolute defined within them. Here's an example: <div class="wr ...

Why is my component not triggering a rerender when the context gets updated?

I need to display a table after retrieving data from an API. I have implemented the Context API and a custom hook to update the context. The second useEffect function logs the retrieved data, confirming that the hook is functioning correctly. Although Re ...

Creating a personalized loading screen in React Native: A step-by-step guide

Looking to create a unique loader for my company that features our logo with a moving line border or rotating icons that relate to our business model. I have the images ready, but I'm unsure of how to build a custom loader in react-native or react... ...