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

Change the display, animate the elements within

Currently working on a landing page with a contentSwitcher and everything is functioning properly. However, I am interested in animating the contents sequentially to add some stylish flair. Take a look at the Test Landing Page for reference. If you observ ...

Unbelievable attribute: sup causing peculiar styling in link element

We've recently come across an issue where the text-decoration of an underline in an anchor tag appears strange when there is a sup element present. The visual glitch looks like this: For reference, here's the HTML structure we are working with: ...

Concealing a button within a specific interface

I am currently facing an issue with a data table that includes two control buttons: edit and save. My problem lies in hiding the save button on the initial preview. Basically, what I want to achieve is displaying only the Edit button on the first page. Wh ...

What is the best way to design a Global Navigation menu for websites?

For example, I am looking to integrate a Navigation menu into my website using just one file. I have considered using PHP or creating an HTML frame, but I am wondering what the current industry standard is for professionals. Any insights? ...

Unable to relocate CSS Loader Container

Can someone help me with adjusting the placement of my container? I'm struggling to maintain the styles while getting rid of the position: absolute; on the .dot class. Every attempt I make is resulting in the dots moving erratically! To clarify, I w ...

Issue with displaying HTML escaped characters such as "&#39" results in showing a pound sign instead of a single quote

Whenever I store data in my Java code, I employ HtmlUtils.htmlEscape to ensure that HTML characters are escaped. However, when retrieving the data and trying to display it in an HTML format (using AngularJS 1.6), the escaped characters (&rsquo;, &am ...

Unusual CSS hierarchy observed post AJAX content load

Currently, I am facing a puzzling issue where my CSS rules seem to be losing precedence on a page loaded via AJAX. Despite placing my custom CSS file last in the main page, allowing it to take precedence over any bootstrap styles, after loading new content ...

Display the table once the radio button has been selected

Before we proceed, please take a look at the following two images: image 1 image 2 I have over 20 fields similar to 'Image 1'. If "Yes" is selected, then a table like in 'Image 2' should be displayed. This means I have 20 Yes/No fields ...

Please do not exceed two words in the input field

I need to restrict the input field to only allow up to two words to be entered. It's not about the number of characters, but rather the number of words. Can this restriction be achieved using jQuery Validation? If not, is there a way to implement it u ...

What is the secret to creating a button that can sort text and another button that flips the word density in my content?

I'm not a fan of having something like this because it's displeasing to the eye: https://i.stack.imgur.com/3F4sp.jpg Instead, I prefer my word density to be more organized and structured. How can I achieve this? Sort by highest word density fi ...

Vuejs unstyled content flash

I encountered an issue while loading a page with Vue. Initially, I am able to access variables like @{{ value }} but once the page is fully loaded, the variable becomes invisible. How can I resolve this issue? I have already included Bootstrap and all scri ...

A helpful tip for creating line breaks within a Vue JS v-for loop using CSS

I am looking to arrange the names in alphabetical order when a list item is clicked. My tools of choice are Vue.js and Flex Grid. The list item I am working with is called ListAll, When clicking on ListAll, I want to display all the records grouped by na ...

Is there a jQuery or Javascript alternative to CSS Counter?

Can a counter be implemented that changes the text of a tag directly using jQuery/Javascript? For example, if there were two tags like this: <a>hello</a> <a>bye</a> After executing the jQuery/JS function, the result would be: < ...

Excessive screen height causes the CSS box layout to overflow

I am looking to create a screen layout similar to the one shown in this image. It should consist of a row with no overflow and include: A left box that contains: A fixed height header (20px), An aspect square box taking up the remaining height. ...

Unable to attach a tooltip to a list item

As an Angular developer, I am working on a list element that displays all the cars and I am looking to add a tooltip to enhance its visual appeal. Here is what I have attempted so far: I created a span tag with the class "tooltip" to wrap around the ul el ...

Folding without extending

My button has a div inside it with content. I've set it up so that when the div is clicked, the collapsed content expands. The hover effect changes color and pointer as expected. But for some reason, clicking on the div doesn't expand the content ...

Utilizing the data sent to a modal to enhance the functionality of the code by combining it with the src attribute of an <embed> element

I am trying to pass a dynamic string of data to a Bootstrap modal using the data-val attribute in an HTML table. <td <button type="button" class="btn btn-success btn-xs" data-val="<?php echo $row['order_id']; ?&g ...

Utilize jQuery and JSP (or PHP) to showcase detailed information about a specific item when a user clicks on it within an HTML page

For my upcoming college project, I am tasked with developing a movie library. The main page of the library will feature various movie posters. Upon clicking on a poster, users will be directed to a dedicated page displaying detailed information about the ...

The class is failing to be applied to the parent div that holds an id starting with the letter x

I have been attempting to assign a class to the parent container when the child element has the 'hidden' class. If not, then a different class should be added. function tagMissions() { if ($('span[id^="mission_participant_new"]').h ...

Learn how to retrieve images from the web API at 'https://jsonplaceholder.typicode.com/photos' and showcase them on a webpage using Angular10

Using the API "https://jsonplaceholder.typicode.com/photos", I have access to 5 properties: albumId: 1 id: 1 thumbnailUrl: "https://via.placeholder.com/150/92c952" title: "accusamus beatae ad facilis cum similique qui sunt" url: "https://via.placeh ...