Windows 7 Window with CSS3 and jQuery Tutorial Part 2

Nice to welcome you to the second part of the Windows 7 window tutorial! Today’s continuation is seamlessly linked to the first part of HTML and CSS. After the interface design of a Windows 7 window in the Firefox “Look & Feel” was simulated in yesterday’s first part, in today’s second part JavaScript or the plugin jQuery (UI) will play the main role in this tutorial 2-divider. In particular, a possible modification of the window size (resizable) and position (draggable) by the user is discussed.

Step 1 – Create and reference to JavaScript files

Since we have already implemented a Windows 7 window according to the “design specifications”, but still no “movement” is possible, the necessary javascript files as resources (jQuery & jQuery-UI – lines 4 to 6) For the still pending request, is added to the existing HTML code from Tutorial 1. In the finally given JavaScript file windows7.js (line 7) the functions corresponding to our requirements (step 3 to 4) are defined.

...
<title>Windows 7 mit CSS3 und jQuery</title>
...
<s cript type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>
<s cript type="text/javascript" src="../js/jquery-ui- 1.7.2.min.js"></script>
<s cript type="text/javascript" src="../js/windows7.js"></script>
</head>
<body>
...

Step 2 – Draggable shift

In order to make the Windows 7 window look and look like a Windows 7 window (draggable) and resizable, the following code must be created in the file windows7.js become. This code causes the already embedded [jQuery UI module dragging] (http://jqueryui.com/demos/draggable/) to be addressed and executed.

$function 
  $".window".draggable 
    cancel: .inhalt,
    containment: body,
    scroll: false,
    stack: group: .window, min: 1 
  ;
;

A brief explanation of what’s going on here:

  • Line 2 – all elements of class window can be moved
  • Line 3 – Elements of class content can not be used for moving
  • Line 4 elements can not be moved beyond the body-tag
  • Line 5 – no scrollbars when a window is pushed out of the body-tag
  • Line 6 – stack causes the currently active window to be placed in the foreground, is only interesting for more than one window

Windows 7 window - Draggable thanks to jQuery UI

So you can now grab the window and move around.

Step 3 – Resizeable – Change of size

The last feature is still missing, the dynamic change of window size. Just below the dragging code within the windows7.js, the following JavaScript code is created.

$function 
  $".window".resizable
    handles: n, e, s, w, ne, se, sw, nw,
    containment: body,
    minHeight: 80,
    minWidth: 138,
    maxHeight: $window.height,
    maxWidth: $window.width
  ;
;

This will now jump to the Resizable Module.

  • Line 2 – all elements of the class window can be changed in their size
  • Line 3 – handles specifies the corners and edges of the window elements to be added to the size change
  • Line 4 elements can not be expanded beyond the body-tag
  • Line 5 to 6 – minHeight and minWidth define the minimum height or width
  • Line 7 to 8 – maxHeight and maxWidth define the maximum height or width (here, equal to the viewport of the browser)

Windows 7 window - resizable thanks to jQuery UI

Step 4 – Resizeable Features designed by CSS

But a little is missing: The elements added by handles, such as the resizeable cursor, etc., still have to be styled via CSS. For jQuery UI there are themes, which of course already include. For our beginners example, the following code, which must be written into the style.css, is sufficient:

.ui-resizable-handle display:block;position:absolute;
.ui-resizable-disabled .ui-resizable-handle,
.ui-resizable-autohide .ui-resizable-handle display:none;
.ui-resizable-n,.ui-resizable-s height:7px;left:0;width:100%;
.ui-resizable-n cursor:n-resize;top:-5px;
.ui-resizable-s bottom:-5px;cursor:s-resize;
.ui-resizable-e,.ui-resizable-w height:100%;top:0;width:7px;
.ui-resizable-e cursor:e-resize;right:-5px;
.ui-resizable-w cursor:w-resize;left:-5px;
.ui-resizable-se,.ui-resizable-sw,
.ui-resizable-nw,.ui-resizable-ne height:12px;width:12px;
.ui-resizable-se bottom:0;cursor:se-resize;right:0;
.ui-resizable-sw bottom:0;cursor:sw-resize;left:0;
.ui-resizable-nw cursor:nw-resize;left:0;top:0;
.ui-resizable-ne cursor:ne-resize;right:0;top:0;

Windows 7 window in different window sizes

Demo

Now we would be at the end, from now your imagination is asked. The strict separation of content and layout allows you to create other themes as well, eg. With windows in Windows 2000 or Mac OSX Style? Or several windows at once? Who of you in the implementation of the two tutorials have done everything right, should have the following representation of a Windows 7 window:

View Tutorial Demo

On my blog I have a demo, Which also pushes the whole thing further: Aero Peek, maximize or close windows, Taskbar and Start menu, to name only a few points. I hope that I can give you some ideas, especially about CSS3, how useful it is, and how it will make it easier to design everyday.

Download

On Norman’s blog you can also get the final result of this small tutorial series as ZIP for download.

Author

This second part of this small tutorial series with the theme “Windows 7 with CSS3 and jQuery” has been posted by the guest blogger Norman Paschke, whom we welcome on this website on the Webstandard blog. Norman studied Applied Computer Science at the Technical University of Chemnitz and started Norman’s blog in early 2009, where he devoted himself to the subject of “Web and Webdesign”. In addition to tutorials, he also developed current trends and developments such as, for example, the Browsermarkt, picks up.

Source:

Windows 7 Window with CSS3 and jQuery Tutorial Part 1

You can find the Interfacedesign of Windows 7 considerable and are interested in CSS3? Then you are exactly right here. This is because in this tutorial 2-divider a window from Windows 7 is created with the help of CSS3 and jQuery UI. The first part of this tutorial is about the styling of the window, according to the “Interfacedesign Preferences” of Windows 7. The second part of this tutorial is about the dragging & resizing of the created window with the help of jQuery UI.

Windows 7 Windows - The original as a template

Windows 7 – The original as a template

So that you know what will be replicated, here is a picture of a window from Windows 7. However, we will only create a simplified window without closing, minimizing and reducing. That There are only three elements with special interfacedesign characteristics, which are of decisive importance for styling:

  • Window frames: transparency, round corners, shadow shadows
  • Windowtitle: Program-Icon, Text-Shadow, Font: Segoe UI
  • Window content: flexible height and width

But this is not enough, if you enlarge the picture like the picture here on the left, you can see that a few small details are missing in the collection. The window frame has a thin black edge to the outside, but also a pale white edge inwards. The same applies to the window content, but here the light edge is logically outside and the dark edge is inside. In addition, it can be seen that the window content at the corners is quite slightly rounded

Step 1 – Create the HTML framework and content

Before we start the window from Windows 7 using CSS, the HTML framework used for this tutorial is shown. It should be mentioned briefly that the headings h1 to h3 (lines 11, 12 and 14) can correspond to a possible web page structure. To handle the semantics of the headlines, the Windows 7 window in this tutorial example gets the h4 tag.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <title>Windows 7 with CSS3 and jQuery</title>
  <link rel="stylesheet" href="css/style.css" type="text/css" />
  <!-- At this point, JavaScript is referenced in the second part of the tutorial -->
</head>
<body>
  ...
  <h1>Headline of your website</h1>
  <h2>Article heading</h2>
  <p>Lorem ipsum dolor sit amet ...</p>
  <h3>Article Subtitle</h3>
  <p>Lorem ipsum dolor sit amet ...</p>
  ...
  <div class="window">
    <h4 class="title">Mozilla Firefox</h4>
      <div class="content">
      <!-- At this point, there is room for your window content -->
      </div>
    </div>
  ...
  </body>
</html>

Explanation: A doctype should be available, which you use, but is left to you of course. Recommended is of course HTML / XHTML Strict to use, but also the new HTML5 Doctype should work here. In the head, you give the link to the used StyleSheet file. In the second part, this tutorial will refer to the JavaScripts used for Part2.

  • JQuery 1.4.2: the latest version of the popular JavaScript framework from the Microsoft server
  • JQuery UI: here, besides the “core”, the Draggable and Resizeable module is important (if you are not sure since you have everything, just download the file from the example)
  • The last file is a blank JavaScript file, which we will fill in part2

Finally, the actual window, consisting of the above three parts (div.window, div.content and h4, which of course must correspond to the structure of your document), is displayed between lines 19 to 24. Particularly important are the class names, then the styling goes on. The class window stands for the window frame to be created and encloses everything else that belongs to the window. The class title is as the name suggests the window title. The class content logically contains all later window contents.

Step 2 – Create and style the window background

Now it’s interesting, because without CSS, we have so far only a white page and a non-saying title “Mozilla Firefox” (or whatever you wrote in the title …). Therefore, the layout for the background of the window is defined below. The background image of a Steinadler by Richard Bartz under Creative Commons also serves to illustrate the effects, such as transparency.

* 
  margin:0;
  padding:0;

html 
  height:100%;
  width:100%;

body 
  background:#eadfcd url(../img/background.jpg) no-repeat 0 0;
  -webkit-background-size:cover;
     -moz-background-size:cover;
          background-size:cover;
  height:100%;
  width:100%;
  overflow:hidden;

In lines 1 to 4, a CSS reset is performed (one can be used another), the page is refreshed to the full screen size, and a background image is still missing (included in the example). The background-size: cover ensures that the background image, regardless of the resolution, is always drawn to the full height and width of the window.

Step 3 – Create and style the window frame

We know what optical features the frame has, this results in the following CSS code, which is spiked with several CSS3 properties.

.window 
  -webkit-border-radius:7px;
     -moz-border-radius:7px;
          border-radius:7px;
  -webkit-box-shadow:0 0 0 1px #eee inset,
                     0 0 15px rgba(0,0,0,0.9);
     -moz-box-shadow:0 0 0 1px #eee inset,
                     0 0 15px rgba(0,0,0,0.9);
          box-shadow:0 0 0 1px #eee inset,
                     0 0 15px rgba(0,0,0,0.9);
  background-color:rgba(160,160,160,0.4);
  border:1px solid #000;
  height:146px;
  left:555px;
  padding-bottom:46px;
  position:absolute;
  top:125px;
  width:389px;
  • Line 2-4: Round corners through border radius (for Gecko, Webkit and the normal syntax)
  • Lines 5 to 10: thin pale white border inside, black shadow outside
  • Line 11: transparent background color by RGBa
  • Line 12: thin black border
  • Line 15: the padding is needed, so that we can later draw the window contents to the full size
  • Line 16: is necessary for positioning
  • height, left, top and width can be selected as desired, they are only used to initialize the size and position of the window

The current state of affairs would now be a transparent, but still “empty” window without any text and image contents. So, let’s go!

Windows 7 - Transparent window

Step 4 – Styling the window title

In the next step we will devote ourselves to the title area of the window, which includes a favicon in addition to the stylistic award of the title. In this case, the Mozilla Firefox browser is used. The font family is based on the family Segoe UI developed by Microsoft for the operating systems Windows Vista and Windows 7.

.window .title 
  background:transparent url(../img/firefox_favicon.png)
  no-repeat 6px 6px;
  color:#000;
  cursor:move;
  font:normal 12px/16px "Segoe UI",Arial,sans-serif;
  height:16px;
  overflow:hidden;
  padding:6px 0 6px 28px;
  text-overflow:ellipsis;
  text-shadow:0 0 1px #fff,
              3px 3px 5px #fff,
              -3px -3px 5px #fff,
              -3px 3px 5px #fff,
              3px -3px 5px #fff;
  white-space:nowrap;
  • Lines 2 to 3: Program icon, here goes every 16×16 pixel picture
  • Line 5: Cursor becomes a cross, which indicates that you can push it around (according to part 2;))
  • Line 6: Font size and family (with fallback, if first font family does not exist)
  • Line 10: A CSS3 property currently supporting only Chome. Text that is longer than the element is truncated with three points
  • Lines 11 to 15: Text-Shadow, so that the text remains legible on the transparent frame
  • Line 16: Text is not wrapped if it is longer than the element

Well, we are approaching our goal …

Windows 7 - Transparent window with Firefox icon and title

Step 5 – Create and style the window contents

In the next step, we will focus on the content area of the Windows 7 window. This gets assigned to a barely visible but a pixel border radius, as well as appropriate shadow and background properties.

.window .content 
  -webkit-border-radius:1px;
     -moz-border-radius:1px;
          border-radius:1px;
  -webkit-box-shadow:0 0 0 1px rgba(255,255,255,0.65);
     -moz-box-shadow:0 0 0 1px rgba(255,255,255,0.65);
          box-shadow:0 0 0px 1px rgba(255,255,255,0.65);
  background-color:#fff;
  border:1px solid #666;
  color:#000;
  font:normal 12px/18px arial,sans-serif;
  height:100%;
  margin:0 6px;
  overflow:auto;
  padding:5px;
  position:relative;
  • Lines 2 to 4: slightly rounded corners
  • Lines 5 to 7: thin white border on the outside
  • Line 12: Contents must be reeled to the full height of the frame
  • Line 14: Content that goes beyond the element can not be displayed; instead, scrollbars appear at the edges of the element

The CSS work carried out in this step now results in the state which corresponds to our initial task.

Windows 7 window including content

Step 6 – Content is the King!

As is known as Content the King, the window can now be filled with further content (of your choice).

...
<div class="content">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
<p><img alt="Musterbild" src="img/oops.png" /> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
...
</div>
...

Since the text and image contents are too large for the window size, the scroll bar appears. The contents of the scrollbar can then be accessed as in a “real” Windows 7 window.

Windows 7 window in browser comparison

Browser Compatibility

A question which will arise in particular due to the used CSS3 features some of you, is the browser compatibility of this tutorial example. And to get an idea of how this window looks in the other browsers, here is a small preview in the latest versions (FF3.6, Opera10.5, IE8, Safari4, Chrome4):

Browser comparison - FF3.6, Opera10.5, IE8, Safari4, Chrome4 (from the left)

As you might have guessed, the Internet Explorer (8) does not support any of the CSS3 properties used in the Internet Explorer 9 Preview, as does Safari still has its problems with box shadow, where inset occurs. Chrome has a small rendering bug: with border radius in the interplay with box shadow, unsightly light gray corners occur. Only Firefox and Opera render in this tutorial everything, as it corresponds to the task position.

Windows 7 Window with CSS3 – The Demo

Sure, there are also a number of workarounds and fallbacks for the less mature browsers, but they should not be the content of this tutorial. Rather, the first part of this Turorial will show what will be possible with CSS3 in everything. Until all browsers are on the same level, the example could serve as small CSS3-Testsuite. 😉

View Tutorial Demo

In the second part you will learn how to use jQuery UI to move the window and resize it. I thank you already for the attentive reading, thank you! 🙂

Author

The author has written this first part of this small tutorial series of the guest blogger Norman Paschke, which we welcome over this way on the Webstandard blog. Norman studied Applied Computer Science at the Technical University of Chemnitz and started Norman’s blog in early 2009, where he devoted himself to the topics of “Web and Webdesign”. In addition to tutorials, he also presents current trends and developments such as, for example, the Browsermarkt, picks up.

Source: