Speech bubble's :before element fails to appear outside the div

I'm facing a little issue and hoping for a quick solution as I can't seem to figure out the problem.

Recently, I came across an answer on how to create a complex CSS shape like a speech bubble. Inspired by it, I tried implementing something similar in my code. However, I'm struggling with getting the :before pseudo element to display outside the "parent" div. My goal is to make it look like a speech bubble, which requires the element to extend beyond the boundaries of the div.

Below is the code snippet:

HTML

<div class="image">
    <img class="test" src="http://fc00.deviantart.net/fs71/f/2011/322/e/2/e292b11555866aec8666ded2e63ee541-d4gl4vg.png" alt="leopard" />
</div>

CSS

body {
 background-color: #333;
}
.image {
    position:relative;
    width:360px;
    background:orange;
    border-radius: 15px;
    overflow: hidden;
    margin-left: 15px;
}

.image:before {
  position: absolute;
  z-index: 1;
  content: '';
  background-color: #fff;
  border: solid 0 transparent;
  top: 50px; left: -1.25em;
  width: 5em; height: 1em;
  transform: rotate(45deg) skewX(75deg);
   -moz-box-shadow:    inset 0 0 5px #000000, -3px 0px 2px 6px #000;
   -webkit-box-shadow: inset 0 0 5px #000000, -3px 0px 2px 6px #000;
   box-shadow:         inset 0 0 5px #000000, -3px 0px 2px 6px #000;
}

.test {
    display:block;
    width:100%;
}

You can view the codepen demo here.

Any helpful insights would be greatly appreciated.

Answer №2

When you apply overflow: hidden to the image element, it prevents anything from displaying outside of its boundaries. This is the purpose of using the hidden property.

To address this issue, you have a few options:

  • Eliminate the overflow: hidden and convert the image into a div with defined dimensions, utilizing the image as a background image instead,
  • Enclose the image within another element and utilize the :before style on the enclosing element.

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

HTML Settings Menu: Customize Your Preferences

Greetings! I am currently in the process of creating a website and am seeking advice on how to approach incorporating a menu option. After researching, I discovered that the <menu> tag is not supported by major browsers, which came as a surprise. Add ...

Innovative HTML5 Video Canvas Shapes

I'm currently working on creating a circular frame or canvas for live HTML5 Video. While I am able to round the corners using keyframes radius property, it results in an oval shape rather than a circle. My preference would be to utilize a div object ...

What is the best way to enhance accuracy when hovering?

Have you ever noticed that the bottom menu becomes less precise when hovering over it on certain browsers? While Firefox seems to handle it perfectly, other browsers lack that smooth "snap" effect as you move through the numbers. I'm trying to find a ...

Is there a way to redirect links within an iframe when a user decides to open them in a new tab?

I am currently developing a web application that allows users to access multiple services, such as Spark and others. When a user selects a service, like Spark for example, the app will open a new tab displaying my page (service.html) with user information ...

What is the best approach to styling a sub-child element within the first child using TailwindCSS?

Currently working with React (Next.js) and TailwindCSS. <ul> <li> <h1 className="bg-red-400">first</h1> </li> <li> <h1 className="bg-green-400">second</h1> </li> &l ...

Tips for ensuring a functioning dropdown menu while maintaining a fixed navigation bar position

I am facing an issue with my navigation bar. I have set the position to fixed to keep it at the top, but this is causing the drop-down functionality to stop working. Please advise on where I should move the position fixed property so that my nav bar remai ...

Struggling with adding two-digit numbers in a JavaScript calculator

While I can add single digits with no problem, adding double digits proves to be a bit tricky. The split method in this if statement is useful for isolating individual numbers, but it struggles when dealing with double digit numbers. if(e.value == '= ...

Offsetting touch events in an iPhone's UIWebView(Note: This

Exploring the canvas drawing feature in a UIWebView, I am developing an app that enables finger painting on the iPhone. Currently facing a challenge where I need to offset the touch so that users can see what they are painting without their finger obstru ...

Shell script for swapping all occurrences of :*; with a comma

Below are some CSS color variables defined in hex: --state-success-text: #3c763d; --state-success-background: #dff0d8; To create a comma-separated list of these color variables, the output should look like this: state-success-text, state-success ...

Square-shaped picture with Bootstrap 4 design

I need help making images of different sizes appear as squares in a preview on my webpage. /* This is the CSS code which sets automatic height: */ .preview-img { width: 100%; height: auto; object-fit: cover; } How can I adjust the image height bas ...

Emails in Dark Mode: Enhancing the User Experience

I am currently working on a project involving emails and I need to implement a dark mode for the email body. The email body is comprised of HTML with specific color styles defined. My objective is to change the text and background colors to create a dark m ...

Tips on implementing CSS post jQuery-induced modifications

I am currently working on dynamically adding elements to an HTML page while also implementing the bootstrap 3.2 css. Below is the jquery function that I am using: $( document ).ready(function() { $(".refresh-btn").click(function (){ $("<d ...

Discrepancies in Flexbox Handling of Images between Chrome and Firefox

My goal is to showcase images on a flexbox grid, and while it works perfectly in Chrome, I'm encountering issues in Firefox (uncertain where the problem lies). Check out the CodePen link for reference : https://codepen.io/anon/pen/QJNajw?editors=1100 ...

I have a task to retrieve a specific element from a HTML tag using BeautifulSoup4

Having a bit of trouble here - I've got this tag in my soup and I'm trying to extract the date from the 'value' element. <input class="mm-date-field form-control input-sm date-picker" title="Select as of date" typ ...

Having trouble with my JavaScript onClick function in obtaining the expected output value

Hey there, I've encountered an issue where using a loop to iterate through an array and check the onclick function results in all array elements producing the same result when clicked. The expected behavior is for only the first element's result ...

Is there a way to transform an HTMLCollection into an array without depleting it of its elements?

I've been attempting to transform a collection of 4 divs in HTML into an array, but all my efforts seem to lead to the array becoming void. <div class="container"> <div class="shape" id="one"></div> <div class="sh ...

Incorrect form element style is only visible when contained within an unstyled HTML Details tag

A demonstration form control extracted from the Bulma CSS framework documentation performs as anticipated with Bulma 0.7.2 (most up-to-date version at the time of writing). However, when this form is contained within a standard html <details> tag, t ...

Choose a row at random from the table, then delete it and use it to create a new table

I stumbled upon some code that really helped me out. Big shoutout to daiscog for that! I'll explain what I'm trying to achieve. There's a table with rows of entries for a giveaway, and I want to be able to click a button to remove a row from ...

Tips for eliminating repetitive code in JavaScript

I have a jQuery function that deals with elements containing a prefix 'receive' in their class or ID names. Now, I need to duplicate this function for elements with the prefix 'send'. Currently, it looks like this: function onSelectAddr ...

Java servlet is unable to interpret the name of an html select tag

Currently, I am implementing a feature where table rows with select boxes are added dynamically and the values of these select boxes are retrieved in a servlet. The process of adding the select boxes is functioning properly; however, when attempting to ret ...