I want to create a close button using CSS only.
I\'m sure I\'m not the first to do this, so does anyone know which font has an \'x\' the same width as height, so that it
Using modern browsers you can rotate a + sign:
.popupClose:before {
content:'+';
}
.popupClose {
position:relative;
float:right;
right:10px;
top:0px;
padding:2px;
cursor:pointer;
margin:2px;
color:grey;
font-size:32pt;
transform:rotate(45deg);
}
then simply place the following html where you need:
<span class='popupClose'></span>
Forget about a font and use a background image!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<title>Select :after pseudo class/element</title>
<style type="text/css">
.close {
background:url(http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/images/ui-icons_222222_256x240.png) NO-REPEAT -96px -128px;
text-indent:-10000px;
width:20px;
height:20px;
}
</style>
</head>
<body>
<input type="button" class="close" value="Close" />
<button class="close">Close</button>
</body>
</html>
This will be more accessible for users visiting the page with a screen reader.
HTML
✕ ✕
✓ ✓
✖ ✖
✔ ✔
✗ ✗
✘ ✘
× ×
×
CSS
If you want to use the above characters from CSS (like i.e: in an :before
or :after
pseudo) simply use the escaped \
Unicode HEX value, like for example:
[class^="ico-"], [class*=" ico-"]{
font: normal 1em/1 Arial, sans-serif;
display: inline-block;
}
.ico-times:before{ content: "\2716"; }
.ico-check:before{ content: "\2714"; }
<i class="ico-times" role="img" aria-label="Cancel"></i>
<i class="ico-check" role="img" aria-label="Accept"></i>
✕
HTML'\2715'
CSS like i.e: .clear:before { content: '\2715'; }
'\u2715'
JavaScript stringhttps://home.unicode.org/
✖ works really well. The HTML code is ✖
.
An alternative is ✕
: ✕
×
and font-family: Garamond, "Apple Garamond";
make it good enough. Garamond font is thin and web safe