Shadow box with arrow/bubble element using CSS

I am looking to add a box shadow around the outline of the bubble below.

<div class=speech-bubble-dark></div>

.speech-bubble-dark {
  position: absolute;
  background: #fff;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
  border-radius: 0.4em;
  width: 300px;
  top: 55px;
  left: -100px;
  z-index: 999;
}

.speech-bubble-dark:after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 0;
  border: 15px solid transparent;
  border-top: 0;
  margin-left: -15px;
  margin-top: -15px;
}

edit: code was incorrect, pasted some experimental code I was testing.

https://codepen.io/iasisalomon/pen/PopREzO

Answer №1

When discussing shadows, it seems to involve another layer of the page, in my opinion. I have come up with three alternatives, but there may be better solutions using different CSS properties. The first option involves manipulating the color

.speech-bubble-dark {
      position: absolute;
      background: #fff;
      box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.2);
      border-radius: 0.4em;
      width: 300px;
      top: 55px;
      left: -100px;
      z-index: 999;
    }
    
    .speech-bubble-dark:after {
      content: '';
      position: absolute;
      top: 0;
      left: 50%;
      width: 0;
      height: 0;
      border: 15px solid transparent;
      border-bottom-color: #eef;
      border-top: 0;
      margin-left: -15px;
      margin-top: -15px;
    }

The second suggestion, as mentioned in a previous comment, is to utilize filter: drop-shadow, but with the shadow from another bubble. This might not provide the best visual effect

.speech-bubble-dark {
  position: absolute;
  background: #fff;
  filter: drop-shadow(0 7px 5.5px rgba(0, 0, 0, 0.2));
  border-radius: 0.4em;
  width: 300px;
  top: 55px;
  left: -100px;
  z-index: 999;
}


.speech-bubble-dark:before  {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 0;
  border: 15px solid transparent;
  border-bottom-color: #eee;
  border-top: 0;
  margin-left: -15px;
  margin-top: -15px;
}
.speech-bubble-dark::after {
    content: ' ';
    width: 98%;
    height: 1px;
    background-color: transparent;
    position: absolute;
    top: -2.5px;
    right: 1%;
    border-radius: 1em;
    box-shadow: 0 3px 2px rgba(0, 0, 0, 0.1);
}

Lastly, the third approach appears to be the most favorable in my perspective

.speech-bubble-dark {
  position: absolute;
  background: #fff;
  box-shadow: 0 3px 2px rgba(0, 0, 0, 0.1);
  border-radius: 0.4em;
  border:1px ridge rgba(0, 0, 0, 0.1);
  width: 300px;
  top: 55px;
  left: -100px;
  z-index: 999;
}


.speech-bubble-dark:before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 0;
  border: 15px solid transparent;
  border-bottom-color: #eef;
  border-top: 0;
  margin-left: -15px;
  margin-top: -15px;
}
.speech-bubble-dark::after {
    content: ' ';
    width: 98%;
    height: 1px;
    background-color: rgba(0, 0, 0, 0.1);;
    position: absolute;
    top: -1px;
    right: 1%;
    border-radius: 1em;
    box-shadow: 0 -0.1 2px rgba(0, 0, 0, 0.2);
}

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

Having issues with image hover and click functionality

My website has an image with the cursor set to pointer and a function that should show a hidden element when clicked. However, it's not working at all. When I hover over it or click on it, nothing happens. Here is a screenshot of the issue along with ...

Guide on Creating HTML Embeds for Multiple Selection Code Blocks

I need some help creating a feature similar to this: View Image Unfortunately, I haven't been able to locate any tutorials or code samples on how to implement multi-selectable language code blocks using HTML/CSS. My CSS knowledge is limited, and I r ...

Unable to bypass YouTube advertisement

I am currently experimenting with using nodejs puppeteer to test if I can bypass the ad on Youtube. Although this is just for testing purposes, I am facing some challenges with getting it to work as expected. I have implemented a while loop to search for ...

How can I modify the background color of the datePicker?

I have a couple of inquiries about customizing the DatePicker: Is there a way to modify the background color of the datePicker using CSS? For instance, I would like to change the current green color to blue. Link to datepicker image (Just to note, JS ca ...

How to stop parent event propagation in jQuery

I am facing a frustrating issue with my code. Every time I toggle a checkbox, the parent element's click event also triggers. I have experimented with various solutions like: event.stopImmediatePropagation(); event.stopPropagation(); event.preventD ...

Is it possible to create a table using a loop in an SQLite query?

Welcome In the company where I work, Excel is currently being used to manage a large database of items for cost estimation purposes. To simplify this process, I am developing an Electron App that will replace Excel with a more user-friendly interface and ...

The UI-SELECT feature in angular-js does not seem to be displaying

I've added the necessary ui-select js and css files to my page : <link href="assets/plugins/ui-select/select.min.css" rel="stylesheet" type="text/css" <script src="assets/plugins/ui-select/select.min.js" tyle="text/javascript" </script> ...

What is the best way to ensure an image is shown in full screen exclusively on mobile devices?

My goal is to have two different site templates, one for desktop (which is already good) and one for mobile. For the mobile template, I want it to display only an image that fills the entire screen. The image should take up all the available space in term ...

JavaScript is unable to make changes to the page once it has finished loading

I have implemented a JavaScript code that allows me to send messages in a chat interface: function sendMessageToChat(conversation, message) { $("#content").html(conversation + message); $(".current-msg").hide(); $(".current-msg").delay(500).fadeIn ...

Having trouble with the CSS :hover tag? Try changing the display property from none to inline-block

I'm currently working on a website navigation menu... I've decided to utilize the :hover feature in CSS to switch the display property from none to inline-block. In the past, I have implemented this with no issues whatsoever. However, I am now e ...

Is there a way to customize the background color when the Bootstrap 4 toggle switch is in the "checked" position?

I'm struggling to find a way to adjust the background color of the "checked" state for this toggle switch in Bootstrap 4. It utilizes an additional library for toggling between dark and light modes - you can find it here on github. While that function ...

What is the correct way to specify an image path for a background URL?

Currently, I am setting a background image for the hr tag using the following code: <hr style="height:6px;background: url(http://ibrahimjabbari.com/english/images/hr-11.png) repeat-x 0 0;border: 0;margin:0px!important"> However, I have now saved th ...

Using PHP to dynamically pull and update webpage content directly from the database

Currently, I am utilizing PHP to upload information into a database and then using PHP again to display that data. In the code snippet provided below, PHP is used to exhibit all the content stored in the database. Each row within the database table will b ...

Adjust the placement of image when changing the size of the window

Is there a way to prevent an image with a fixed position from covering up page content when the browser window is resized? <div > <img id="img1" class="wrapperImage"></img> </div> <style type="text/css"> .wrapperImag ...

I am looking to modify the highlighted table cell whenever the value within it changes

I am currently working on a small project related to the Stock Market. In this project, I need to dynamically change the style of the td element based on data fluctuations - green highlight for an increase and red highlight for a decrease. In the provid ...

Tips for adjusting text to fit within a container without needing to use overflow:auto

Is there a way to prevent text overflow in a container without using the overflow:auto property? I've come across plugins that automatically reduce the text size, but I'm not keen on that solution. What I want is for long words or URLs to wrap on ...

Activate all chosen CSS circles

I'm currently working on creating a progress bar using CSS circles. The idea is that when you click on each circle in sequence (1, 2, 3), all three circles and the line connecting them will fill up with red color. If you then go back (3, 2, 1), the co ...

Creating geometric designs on an image and storing them using PHP

I am attempting to retrieve an image from a specific location on my server, draw lines on it, and then save the modified image back to the same location. Below is the code I am using: function drawShapes($src_path, $json) { echo "---inside dra ...

One way to target a span inside a label element when a checkbox is checked using React Material UI createStyles is by using CSS selectors in combination with

I need help targeting the span element within a checkbox label in order to change its background color when the checkbox is checked. <div className={classes.container}> <input type="checkbox" id="checkboxid" /> <lab ...

React.js combined with Webpack may not properly interpret @media queries

Currently, I am working on a website built with React.js (version 15.6.1) and Webpack 1. I have implemented a SASS-compatible version of the Flexbox Grid following this tutorial. However, I have noticed that the @media expressions are not being compiled as ...