Creating an error icon using only CSS, identical to the one shown in the picture

I'm attempting to create a similar X icon, resembling the one shown here:

Here is the HTML code I am using:

<div class='error-circle'>
    <div>X</div>
</div>

And this is the corresponding CSS:

.error-circle{
    width: 70px;
    height: 70px;
    background: #990000;
    border-radius: 100px;
    border: 4px solid white;
    color: white;
    font-size: 45px;
    font-weight: bold;
    padding-left: 17px;
}

Although it's close, I really need the same result as the image (without the background). I believe the X should not be the x character but rather two lines crossed on top of each other. How can I achieve this desired outcome?

Answer №1

1) Eliminate any extra padding

2) Set the border-radius to 50%

3) Experiment with a different typeface such as verdana

View Example on FIDDLE

.error-circle {
  width: 70px;
  height: 70px;
  line-height: 70px;
  background: #990000;
  border-radius: 50%;
  border: 4px solid white;
  color: white;
  font-size: 45px;
  font-family: verdana;
  text-align: center;
}
<div class='error-circle'>
  <div>X</div>
</div>

Answer №2

If you're aiming for a more realistic look, consider adding some shadows to your design

*{box-sizing: border-box}
:root{background: #ccc}
div{
    width: 150px;
    height: 150px;
    border-radius: 50%;
    position: relative;
    margin: 40px auto;
    box-shadow: 0 0 0 10px white, 0 0 24px 12px #B3B3B3, inset 0 0 16px 1px #B3B3B3;
}

div:before, div:after{
    content: ''; 
    position:absolute;
    width: 20px;
    height: 100px;
    left: 64px;
    top: 25px;
    box-shadow: 0 0 16px 1px #B3B3B3;
    background: white
}
div:before{
    transform: skew(28deg)
}
div:after{
    transform: skew(-28deg);
}
<div/>

For a different effect, try changing the background color to red

*{box-sizing: border-box}
:root{background: #ccc}
div{
    background: red;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    position: relative;
    margin: 40px auto;
    box-shadow: 0 0 0 10px white, 0 0 24px 12px #B3B3B3, inset 0 0 16px 1px #B3B3B3;
}

div:before, div:after{
    content: ''; 
    position:absolute;
    width: 20px;
    height: 100px;
    left: 64px;
    top: 25px;
    box-shadow: 0 0 16px 1px #B3B3B3;
    background: white
}
div:before{
    transform: skew(28deg)
}
div:after{
    transform: skew(-28deg);
}
<div/>

To create variations in size, use transform: scale(.5,.5); on div

Answer №3

To create a circular shape, apply the border radius property as demonstrated below.

body { 
   background-color: #A5A5A5; /* used for visualizing the error icon */
   }

 #circlude {
   width: 100px;
   height: 100px;
   background-color: red;
   border-radius: 50%;
   color: white;
   font-weight: bold;
   text-align: center;
   font-size: 72px;
   font-family: calibri; /* Choose your preferred font */
   line-height: 100px;
   border: solid 4px white;
 }
<div id="circlude"> X </div><!-- End Circlude -->

Answer №4

Check out this code snippet:

.error-circle {
  color: #000;
  font-size: 2em;
  font-weight: bold;
  text-align: center;
  width: 40px;
  height: 40px;
  border-radius: 5px;
}

Answer №5

.error-circle{
    position: absolute;
    width: 70px;
    height: 70px;
    border-radius: 40px;
    background-color: #990000;
    border: 5px solid #fff;
}

.error-circle > div {
    position: fixed;
    top: 50%;
    left: 50%;
    margin-left: -15px;
    margin-top: -27px;
    text-align: center;
    width: 20px;
    font-size: 48px;
    font-weight: bold;
    color: #fff;
    font-family: Arial;
}
<div class='error-circle'>
    <div>X</div>
</div>

Answer №6

To create a button without using extra elements, I recommend utilizing pseudo effects with absolute positioning.


Exploring Pseudo Effects


By leveraging the :before and :after pseudo effects, you can achieve the desired button effect without the need for additional elements:

SEE LIVE DEMO

html{
background-color:gray;
}
.error-circle {
  width:70px;
position:relative;
  height: 70px;
  background: #990000;
  border-radius: 50%;
  border: 4px solid white;
}
.error-circle:after,.error-circle:before {
  position:absolute;
content:'';
width:10%;
left:45%;
top:10%;
height:80%;
background-color:white;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.error-circle:before{      
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
<div class='error-circle'>
  
</div>


Utilizing pseudo effects simplifies editing and maintenance:


For cross compatibility, remember to include the -webkit- prefix to ensure Safari recognizes the rotation property.

Answer №7

Focusing on the X with two cross lines, rather than solving the circle problem like other answers.

Here is a solution using two arrows:

body{padding:20px;}


#arrow-left{
  position: relative;
  padding: 30px;
}

#arrow-left:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 40%;
  background: blue;
  -webkit-transform: skew(135deg, 0deg);
  -moz-transform: skew(135deg, 0deg);
  -ms-transform: skew(135deg, 0deg);
  -o-transform: skew(135deg, 0deg);
  transform: skew(135deg, 0deg);
}
#arrow-left:after {
  content: '';
  position: absolute;
  top: 100%;
  right: 60%;
  height: 100%;
  width: 40%;
  background: blue;
  -webkit-transform: skew(-135deg, 0deg);
  -moz-transform: skew(-135deg, 0deg);
  -ms-transform: skew(-135deg, 0deg);
  -o-transform: skew(-135deg, 0deg);
  transform: skew(-135deg, 0deg);
}


#arrow-right{
  position: relative;
  padding: 30px;
}

#arrow-right:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0px;
  height: 100%;
  width: 40%;
  background: red;
  -webkit-transform: skew(45deg, 0deg);
  -moz-transform: skew(45deg, 0deg);
  -ms-transform: skew(45deg, 0deg);
  -o-transform: skew(45deg, 0deg);
  transform: skew(45deg, 0deg);
}
#arrow-right:after {
  content: '';
  position: absolute;
  top: 100%;
  right: 60%;
  height: 100%;
  width: 40%;
  background: red;
  -webkit-transform: skew(-45deg, 0deg);
  -moz-transform: skew(-45deg, 0deg);
  -ms-transform: skew(-45deg, 0deg);
  -o-transform: skew(-45deg, 0deg);
  transform: skew(-45deg, 0deg);
}​
<span id="arrow-right"></span>
<span></span>
<span id="arrow-left"></span>

Answer №8

You have the option to utilize an svg format as well:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
     viewBox="0 0 256 256" style="enable-background:new 0 0 256 256;" xml:space="preserve"gt;
<title>icon / close / dark</title>
  <desc>Created with Sketch.</desc>
  <g id="icon-_x2F_-close-_x2F_-dark">
    <polygon id="icon-_x2F_-close" points="224.3,0 128,96.3 31.7,0 0,31.7 96.3,128 0,224.3 31.7,256 128,159.7 224.3,256 256,224.3 
        159.7,128 256,31.7  "/>
</g>
</svggt;

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 trouble with applying a class in Gtk3 css?

MY ATTEMPT AND EXPLANATION: In my application, I have the following layout structure: GtkWindow GtkOverlay GtkBox GtkGrid GtkButton Even after trying to apply this CSS style: GtkButton{ background-color:blue; } T ...

data-abide is flagging all fields as incorrect

Recently, I encountered an issue with a specific form I have created: <%= form_for(@building_shared_space, data: {abide:''}) do |f| %> ... <div class="field"> <%= f.label :room_type, 'Room Type' %> <%= ...

Changing Ionic Column Widths Based on Content Length

In my dynamic ionic 2 grid system, I am facing a layout issue. <div> <ion-row> <ion-col > ; <ion-card-header class="card-header"> {{hunt.title}} </ion-card-header> </ion-col> <ion-col *ngIf="!hunt. ...

Data modifications in polymer are not being accurately displayed

I need help with hiding/unhiding a UI element using a button in Polymer. Despite having the necessary elements and code set up, it is not working as expected: <button id="runPredictionButton"> <i>Button text</i> </button> <p ...

Image hover effect displayed when hovering over an image

Is it possible to create a hover effect using purely CSS when hovering over an image, like in this example: https://i.sstatic.net/jjAWm.jpg I've come across several similar examples online, but they all seem to rely on jquery or javascript. I'm ...

Achieving the Perfect Alignment: Displaying Text and Progress Bar Side by Side using Bootstrap 5

How can I align the text and progress bar on the same line using Bootstrap 5? <nav class="navbar bg-light fixed-bottom"> <div class="row m-0"> <div class="col-12 countdown"> <p class=&q ...

When I engage with the input field, it ceases to be in focus

Here is the code I've been working on: https://github.com/Michael-Liendo/url-shortener/blob/main/src/pages/index.js If you want to see the issue for yourself, check it out at: ...

Adjusting the width of titles in a CSS menu upon hover

I am currently creating a basic CSS menu. However, I am facing an issue where selecting a menu title in the menu bar causes the width of the title to extend to match the width of the associated menu, which is not my desired outcome (the title's width ...

When the content in one box exceeds the content in the other, one box is considered to be overfilled

For the image, click here: I am facing an issue with boxes stacking on top of each other. When one box has more content, it overlaps the other. CSS: #destaques_container{ margin: 0 auto; } #destaques_container_dentro{ float: left; margi ...

Choose a specific option from the dropdown menu using a URL parameter

After reviewing this code snippet: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> // <![CDATA[ $(document).ready(function() { // Parse your query parameters here, and assi ...

Maintain an equal distance between 2 out of 3 elements while resizing the window to ensure responsiveness

There are two image divs stacked on top of each other, positioned beside a fluid header logo (.svg) also contained in a div. The HTML: <header class="site-header" role="banner" itemscope="itemscope" itemtype="http://schema.org/WPHeader"><div cla ...

Issue: CSS breaking in Node.js Express app when navigating with multiple child paths or parameter paths in the route.Description: Encounter

When attempting to load a page like /patient_profile, the CSS loads correctly. However, when continuing the path to /patient_profile/settings_patient_profile, the CSS breaks. Both pages mentioned are the same file, just testing the routing. The route is m ...

Using Placeholder in JavaScript for Multiple Form Validations

I am currently facing an issue with my form validation. It checks each input to determine if it is valid or not, but the problem arises when only one input is valid, as all inputs are then considered valid. I have tried moving the return true statement, bu ...

User IDs should not be shown on the jQuery datatable, although they are still accessible

I am wondering if there is a way to display certain user data in a datatable without showing the user id in the table itself. Here is my table: <table id="mitabla" class="display"> <thead> <tr><th>Last Name</th> ...

Updating dropdown selection with JavaScript

I have a dropdown select menu with two options. I am using JavaScript to retrieve the selected value from the drop-down menu and display it in a text area. Here is my code: $(document).ready(function () { $('#pdSev').change(function () { ...

Reloading the same page with looping HTML forms through Ajax postback

I've been developing a complex multi-part form for my WordPress website, consisting of 3 forms that are loaded sequentially on a single page. The first form is displayed initially, while the second and third forms remain hidden. To achieve this, I upd ...

The default margin of an HTML element is set to fill the width of its containing div and cannot be overridden

As a budding web developer, I'm encountering a basic issue that has me scratching my head. Any assistance would be highly appreciated: Regardless of the width I specify for elements within a particular div container, both Safari and Chrome seem to au ...

Can you trigger the playback of a sound file by clicking on a specific URL?

Can a sound file be played when clicking depending on the URL? For example: url/sample/#1 Click to play sound1 url/sample/#3 Click to play sound2 ...

Having issues with Bootstrap 5 modal not functioning correctly?

I'm facing an unusual issue that I'm struggling to resolve. I'm currently utilizing Bootstrap 5 and encountered the following problem: const reportBtns = Array.from(document.querySelectorAll('.report')) reportBtns.forEach((btn) ...

Is it possible to modify the appearance of the element that was just clicked on?

Hello everyone, I'm currently working on a form with different inputs, all with the same class: <input type="text" name="username" class="field" /> <input type="text" name="email" class="field" /> I'm trying to figure out how to ch ...