What is the best way to create a transparent popup using only CSS?

https://i.sstatic.net/gNLMM.png

Creating a pure CSS design using background properties.

body{
      background: linear-gradient(to left bottom, blue, red) no-repeat;
      width: 100%;
      height: 300px;
   }
  
 .content{
    position: relative;
 }
  
 .popup{
    display: inline-block;
    position: absolute;
    top: 10px;
    left: 20px;
    color: #ffffff;
    border: 1px solid #ffffff;
    padding: 10px 10px;
    z-index: 200000;
 }

.popup::after{
  display: block;
  content: ' ';
  position: absolute;
  margin: auto;
  z-index: 10;
  top: -4px;
  right: 10px;
  width: 5px;
  height: 5px;
  transform: rotate(45deg);
  border-top: 1px solid #ffffff;
  border-left: 1px solid #ffffff;
  background-color: #81007F;
}
<div class="content">
    <div class="popup">test</div>
</div>

The entire content area and the triangular popup are designed to be transparent. Although it is possible to create a non-transparent version by adding a background color to the triangle, this approach may not be easily reusable with other backgrounds.

An alternative method involves using SVG elements, which also has its limitations due to fixed width and height values.

SVG graphic implementation:

 body{
      background: linear-gradient(to left bottom, blue, red) no-repeat;
      width: 100%;
      height:300px;
   }
<svg xmlns="http://www.w3.org/2000/svg" viewBox="160 100">
    <path stroke="#ffffff" fill="none" stroke-width="1" d="M10 10 L10 100 L150 100 L150 10 L130 10 L125 0 L120 10 L10 10"/>
    <text x="20" y="30" stroke="#ffffff">
        test
    </text>
</svg>

Answer №1

For those who are open to using fieldset and legend, here is a suggestion to try out:

body{
      background: linear-gradient(to left bottom, blue, red) no-repeat;
      width: 100%;
      height: 300px;
   }
  
 .content{
    position: relative;
 }
  
 .popup{
    display: inline-block;
    position: absolute;
    top: 10px;
    left: 20px;
    color: #ffffff;
    border: 1px solid #ffffff;
    padding: 10px 10px;
    z-index: 200000;
 }

legend{
  width: 5px;
  height: 5px;
  transform: rotate(45deg);
  border-top: 1px solid #ffffff;
  border-left: 1px solid #ffffff;
  padding: 0;
}
<div class="content">
    <fieldset class="popup"><legend align="right"></legend>test</fieldset>
</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

Issue with loading a stylesheet from a GitHub raw URL

How are you feeling today? I appreciate your willingness to assist, although I realize this may seem like a trivial question. I am struggling to comprehend why things are not functioning as expected. Within my local directory, I have the following tree s ...

When the page is scrolled, the div is fixed in place and a class is dynamically added. Some issues may

Greetings everyone, I have a webpage with two floating divs - one is about 360px wide and the other has an auto width. As the page scrolls, the left div is assigned a class that fixes it to the screen, allowing the other div to scroll. This functionality w ...

How can Angular display an alert when no items are visible?

I want to display a message saying "Item doesn't exist" when the item is not found. Suppose this is my list: user 0 user 1 user 2 The following code displays the list above: <ng-container *ngFor="let user of users | async; let i = index"> ...

Default behavior in Fullcalendar 6 allows for rendering links on both days of the month and weekdays

Is there a way to customize the rendering of days and weekdays in Fullcalendar React? Currently, they are displayed as links by default (<a>{dayContent}</a>), but I'm looking to have them rendered as <div> or <span>. Any sugges ...

Is it possible to impose a different style on an element from another culture?

I am currently developing a themes library along with a demo page. The challenge I'm facing is that the demo page needs to showcase styles from the library without using all of the elements. For instance, consider the following style in an external s ...

Can a nofollow attribute be added to concealed modal content in Bootstrap?

Query: I am dealing with a situation where I have a significant amount of disclaimer text within a modal on my website. This text is initially hidden (display:none) until a user clicks a button to reveal it. I want to prevent search engines from indexing t ...

Unable to decipher Material UI class names

I am experimenting with a React app using Material UI to explore different features. I'm attempting to customize the components following the original documentation, but making some changes as I am using classes instead of hooks. However, I keep encou ...

Displaying a trio of items in a horizontal row on the page

I am currently working on displaying a list item with three data elements positioned next to each other. My goal is to achieve the following layout: https://i.sstatic.net/XiFzE.png However, at the moment, my list appears like this with the circle distort ...

Incorporating various videos into product listings

In my current school project, we are required to create a webshop using a database containing product details. The majority of the work is completed in HTML. I would like to incorporate a video for each product on the site, but the code snippet I found onl ...

"Revamp your Node.js and HTML with the click of a

I recently built a basic counter for my website, but I'm having trouble with its consistency across different browsers and computers. The button seems to work only about 1/12th of the time. Any tips on making it more reliable? Any help would be great ...

Why does getElementById work when getElementsByClassName doesn't?

I created a script with the purpose of hiding images one and two, while keeping image 3 visible and moving it into their place. The script functions correctly when using div Id's instead of div Classes. However, I prefer to use div classes for groupin ...

Is there a way to make the product list view in Magento much more compact and smaller in size?

My issue is pretty straightforward. I find Magento's product display in list view to be too large for my liking. The images are bigger than necessary and each product takes up too much space. I want to resize the listing so that each product only occu ...

Struggling to remove the excess white space while working with Bootstrap 5

Trying to eliminate the white space visible in the image. Utilizing Bootstrap for my project, but still getting acquainted with it. My teacher suggested (without reviewing any code) that a container might be causing the issue. I disagree as the HTML contai ...

Obtain checkbox input from HTML using Angular 2 typescript

Within my HTML code, I have defined two checkboxes in the following manner: <label><input type="checkbox" id="checkbox1" /> Folder 1: </label> <label><input type="checkbox" id="checkbox2" /> Folder 2: </label> I am fac ...

Ensure that the contents of the upper and lower divs are appropriately aligned, while maintaining the centered positioning of the

As a complete beginner in the world of HTML and CSS, I am facing a challenge with my code. Here's the HTML snippet: <section class="instructions"> <div class="row"> <div class="instructions-col" ...

Sliding background in a multi-column accordion

I've hit a roadblock with this project. I'm working on setting up a FAQ section that needs to display its items in two columns on desktop, each with a drop shadow effect using Bootstrap 4. I've experimented with Flexbox and CSS columns with ...

The labels assigned to buttons will direct users to unique links specifically designated for that button

I've been working on a website to share some code I created, but my skills in HTML and CSS are not the best. Please forgive me if there are obvious mistakes. Here's the code I have so far: <!DOCTYPE html> <html> <head> ...

setting different iframe widths for desktop and mobile views

I am working with an iframe and facing a challenge. I want to make it full screen width on mobile devices, but only half the screen width on a normal monitor (100% and 50%, respectively). The minimum specification for the mobile device would be iPhone, alt ...

JavaScript can be utilized to monitor outbound clicks effectively

I am currently working on implementing the code found at this link: Make a ping to a url without redirecting. The original poster is looking to ping a URL without opening multiple windows. My goal is to achieve the same functionality, but I also want to vi ...

When using jQuery, the PHP variable value is not retrieved from the DIV data-id attribute, instead it just displays the variable name

I currently have the following code: <div class= "obutton feature2" data-id=".$bookID."><button>Reserve Book</button></div> <div class="modal-box"></div> Although this button triggers the jQuery script, the modal box ...