Unfortunately, using javascript, I had to develop
Of course, there are plenty of examples and demos online, but nothing like what I wanted.
This page is only concerned with the visual appearance of the Close Button, the code to make it work is trivial and covered elsewhere.
The solution presented below not perfect, but it is almost adequate. It is a complete failute in IE 8 - apparently top: -8px does not work!
A number of my failed attempts are documented on a related page.
Requirements
In Windows XP, the operating system contains a file of common icons (glyphs) which are used for various purposes - 3 of those are for the title bar Close Button
Chrome (a cross platform browser) uses yet another icon.
So, the first question is - Which "standard" should I follow?
In the old days, there used to be design guidelines. However, since the "guidelines" change every time some big shot comes out with a "new" (rehashed) operating system - well, there are no guidelines.
Making it Work
The following styles are from that reference. Since I am only interested in the button, I have
/* Modal Content/Box */ .modal-content { background-color: #fff8f8; padding: 20px; border: 1px solid #888; width: 30%; /* Could be more or less, depending on screen size */ } /* The Close Button */ .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; } |
Besides the obvious problems of no Title Bar and no way for the user to reposition the window,
.modal-content-noPadding { background-color: #fff8f8; border: 1px solid #888; width: 30%; /* Could be more or less, depending on screen size */ } |
Better, but still not what I want. The following example provides just a little padding on the left and adds a dummy Title.
.modal-content-lessPadding { background-color: #fff8f8; padding-left: 5px; border: 1px solid #888; width: 30%; /* Could be more or less, depending on screen size */ } |
Much better, but the X is still too low. By adding position: relative and a negative vertical offset, the position of the X is now acceptable.
.close_relative { color: #aaa; float: right; font-size: 28px; font-weight: bold; top: -8px; /* these bottom 2 are required to position the x */ position: relative; } |
In the example, position: absolute; makes the button appeared at the top of the screen and not inside the dialog box.
However, when the outside div block style contains position: fixed (which is used in real dialog boxes), then both position: relative and position: absolute work.
References