Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X close button only using css

Tags:

css

button

How to make a cross (X) only in CSS3, to use as a close button?

I've been searching for a long time, and cannot found how.... When I look at source code on a website using it, there's always something weird which makes the code I take unusable.

The X button I want: http://tympanus.net/Tutorials/ThumbnailGridExpandingPreview/

When you click an image, this is the cross on the right:

enter image description here

I think this would be great if somebody can post a simple universal CSS code to make a simple X cross in CSS3.

like image 472
hedi Avatar asked Sep 04 '13 10:09

hedi


People also ask

How do I add a close button in CSS?

The task is to make the close button using Pure CSS. There are two approaches that are discussed below. Approach 1: Create a <div> inside another <div> which has alphabet 'X' in it which helps in displaying the close button. When the “click” event occurs on 'X', then perform the operation.

How do you make an X button in CSS?

As a pure CSS solution for the close or 'times' symbol you can use the ISO code with the content property. I often use this for :after or :before pseudo selectors. The content code is \00d7. You can then style and position the pseudo selector in any way you want.

How do you close CSS?

Close Button CSS 2: Plus You can also create a close button using the plus( + ) symbol. You will need to rotate the plus sign so that it looks like a cancel button.

How do I create a close button in HTML?

A close button is a <button> element with the class . close-button . We use the multiplication symbol ( &times; ) as the X icon. This icon is wrapped in a <span> with the attribute aria-hidden="true" , so screen readers don't read the X icon.


2 Answers

As a pure CSS solution for the close or 'times' symbol you can use the ISO code with the content property. I often use this for :after or :before pseudo selectors.

The content code is \00d7.

Example

div:after{   display: inline-block;   content: "\00d7"; /* This will render the 'X' */ } 

You can then style and position the pseudo selector in any way you want. Hope this helps someone :).

like image 108
andycrone Avatar answered Oct 22 '22 10:10

andycrone


Try This Cross In CSS

.close {    position: absolute;    right: 32px;    top: 32px;    width: 32px;    height: 32px;    opacity: 0.3;  }  .close:hover {    opacity: 1;  }  .close:before, .close:after {    position: absolute;    left: 15px;    content: ' ';    height: 33px;    width: 2px;    background-color: #333;  }  .close:before {    transform: rotate(45deg);  }  .close:after {    transform: rotate(-45deg);  }
<a href="#" class="close">
like image 21
Zubair Saif Avatar answered Oct 22 '22 09:10

Zubair Saif