Unit II Ui Design
Unit II Ui Design
UNIT II UI Design
OM SAKTHI
ADHIPARASAKTHI ENGINEERING COLLEGE
MELMARUVATHUR.
DEPT.OF MCA
UNIT - 2
UNIT II UI DESIGN
2.1 SVG
SVG Definition
SVG Advantages
Advantages of using SVG over other image formats (like JPEG and GIF) are:
SVG images can be created and edited with any text editor
SVG images can be searched, indexed, scripted, and compressed
SVG images are scalable
SVG images can be printed with high quality at any resolution
SVG images are zoomable
SVG graphics do NOT lose any quality if they are zoomed or resized
SVG is an open standard
SVG files are pure XML
SVG images can be created with any text editor, but it is often more convenient to create
SVG images with a drawing program, like Inkscape.
Code:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
2.2 I frame
The <iframe> tag is not somehow related to <frameset> tag, instead, it can appear
anywhere in your document. The <iframe> tag defines a rectangular region within the
document in which the browser can display a separate document, including scrollbars and
borders. An inline frame is used to embed another document within the current HTML
document.
The src attribute is used to specify the URL of the document that occupies the inline
frame.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Iframes</title>
</head>
<body>
<p>Document content goes here...</p>
</html>
Most of the attributes of the <iframe> tag, including name, class, frameborder, id,
longdesc, marginheight, marginwidth, name, scrolling, style, and title behave exactly like
the corresponding attributes for the <frame> tag.
1 Src
This attribute is used to give the file name that should be loaded in the frame. Its value
can be any URL. For example, src = "/html/top_frame.htm" will load an HTML file
available in html directory.
2
Name
This attribute allows you to give a name to a frame. It is used to indicate which frame a
document should be loaded into. This is especially important when you want to create
links in one frame that load pages into an another frame, in which case the second
frame needs a name to identify itself as the target of the link.
3
Frameborder
This attribute specifies whether or not the borders of that frame are shown; it overrides
the value given in the frameborder attribute on the <frameset> tag if one is given, and
this can take values either 1 (yes) or 0 (no).
4
Marginwidth
This attribute allows you to specify the width of the space between the left and right of
the frame's borders and the frame's content. The value is given in pixels. For example
marginwidth = "10".
5
Marginheight
This attribute allows you to specify the height of the space between the top and bottom
of the frame's borders and its contents. The value is given in pixels. For example
marginheight = "10".
6
Height
This attribute specifies the height of <iframe>.
7
Scrolling
This attribute controls the appearance of the scrollbars that appear on the frame. This
takes values either "yes", "no" or "auto". For example scrolling = "no" means it should
not have scroll bars.
8
Longdesc
This attribute allows you to provide a link to another page containing a long description
of the contents of the frame. For example longdesc = "framedescription.htm"
9
Width
This attribute specifies the width of <iframe>.
Embedding Video
should support in the video tag. But most commonly used video formats are −
Ogg − Ogg files with Thedora video codec and Vorbis audio codec.
mpeg4 − MPEG4 files with H.264 video codec and AAC audio codec.
You can use <source> tag to specify media along with media type and many other attributes.
A video element allows multiple source elements and browser will use the first recognized
format −
<!DOCTYPE HTML>
<html>
<body>
</body>
</html>
This will produce the following result − Video Attribute SpecificationThe HTML5 video tag can have
a number of attributes to control the look and feel andvarious functionalities of the control –
1 Autoplay
This Boolean attribute if specified, the video will automatically begin to play back as soon
as it can do so without stopping to finish loading the data.
Autobuffer
2
This Boolean attribute if specified, the video will automatically begin buffering even if it's
not set to automatically play.
Controls
3
If this attribute is present, it will allow the user to control video playback, including
volume, seeking, and pause/resume playback.
4 Height
This attribute specifies the height of the video's display area, in CSS pixels.
Loop
5
This Boolean attribute if specified, will allow video automatically seek back to the start
after reaching at the end.
Preload
6
This attribute specifies that the video will be loaded at page load, and ready to run.
Ignored if autoplay is present.
7 Poster
This is a URL of an image to show until the user plays or seeks.
8
Src
The URL of the video to embed. This is optional; you may instead use the <source>
element within the video block to specify the video to embed.
9 Width
This attribute specifies the width of the video's display area, in CSS pixels.
Embedding Audio
HTML5 supports <audio> tag which is used to embed sound content in an HTML or
XHTML document as follows.
<audio src = "foo.wav" controls autoplay>
Your browser does not support the <audio> element.
</audio>
The current HTML5 draft specification does not specify which audio formats browsers
should support in the audio tag. But most commonly used audio formats are ogg,
mp3 and wav.
You can use <source&ggt; tag to specify media along with media type and many other
attributes. An audio element allows multiple source elements and browser will use the first
recognized format −
<!DOCTYPE HTML>
<html>
<body>
The HTML5 audio tag can have a number of attributes to control the look and feel and
various functionalities of the control −
1 Autoplay
This Boolean attribute if specified, the audio will automatically begin to play back as soon
as it can do so without stopping to finish loading the data.
Autobuffer
2
This Boolean attribute if specified, the audio will automatically begin buffering even if it's
not set to automatically play.
Controls
3
If this attribute is present, it will allow the user to control audio playback, including
volume, seeking, and pause/resume playback.
Loop
4
This Boolean attribute if specified, will allow audio automatically seek back to the start
after reaching at the end.
Preload
5
This attribute specifies that the audio will be loaded at page load, and ready to run.
Ignored if autoplay is present.
Src
6
The URL of the audio to embed. This is optional; you may instead use the <source>
element within the video block to specify the video to embed.
CSS style applied by referencing external stylesheet has lowest precedence and is
overridden by Internal and inline CSS.
Internal CSS is overridden by inline CSS.
Inline CSS has highest priority and overrides all other selectors.
Example:
<html>
<head>
<style type="text/css">
h1 {
background-color: red;
color: white;
h2 {
color: blue;
</style>
</head>
<body>
<h1>
</h1>
</h2>
</body>
</html>
“external.css” of Example-1:
h1{
background-color: lightgreen;
h2{
color: pink;
Output:
What is a box-model?
One or more rectangular boxes make up every element that can be shown on a web page. The
CSS box model explains how rectangular boxes are displayed on a web page.
These boxes can have a variety of features and interact with one another in various ways, but
they all contain a content area as well as optional padding, border, and margin areas used
for changing the appearance.
Let’s start with the box-model’s layout, which is depicted in the accompanying image below.
As we said earlier, we may change the appearance of the HTML components of the box by
adjusting the content, padding, border, and margin. Let’s look at each of them.
Content
The content consists of data in the form of text, images, or other forms of media.
The width and height attributes change the box’s dimensions. While this is a straightforward
definition, it should be emphasized that “content” can also refer to empty space. For example,
using an empty div tag to add extra unique designs to a webpage can be great.
Padding
Padding is the gap between the content’s outside edge and its border. The padding property
may be used to resize the box. Padding-left, padding-bottom, and other edge-specific
attributes aid in obtaining custom spacing.
NOTE: You can use one value to represent the padding across the box, for example, padding:
35px; or you can give each side of the box a value, for example, padding-left:25px;.
p{
border-style: solid;
border-color: red;
}
Since there is no padding set for this p tag, you will get the result displayed as below.
p{
padding: 35px;
border-style: solid;
border-color: red;
}
The additional padding between the paragraph content and the border has been altered
significantly, as we can see.
Border
The border of an element is defined by the distance between the padding’s outer edge and the
margin’s inner edge. Its width is set to 0 by default.
The border property is used to specify the boundary of an element. Individual edges can be
customized as well.
The following are the three fundamental properties for creating borders:
Margin
Margin is the portion on the outside of the CSS Box Model. In simpler words, Margin is the
distance between an element’s box and the boxes of its surrounding elements.
This is similar to the page margin, which is the distance between a page’s boundary and its
content. It is translucent and has padding-like features, although it clears space outside the
element’s boundary.
Example
<html>
<p>Am the first Box.</p>
<p>Am another Box.</p>
</html>
<style>
p{
height: 150px;
width: 150px;
padding: 20px;
border: 10px solid blue;
margin: 15px;
}
</style>
The code above shows us how to apply spaces between the two boxes. It separates the two
boxes with 15px.
1. Block boxes.
2. Inline boxes.
These are the two main types of boxes. Let’s look at each of them.
Block boxes
The <div> HTML element is the most popular and used HTML element for a block box.
Inline Boxes
By default, inline boxes take up the space required by the wrapped content.
The <span> HTML element is the most often used inline box element.
Beginners usually make the mistake of assuming that padding, margins, and borders are
included in an element’s height and width. This is wrong.
The height and width attributes let you customize the height and width of a web element’s
content area. Other components on the web page are not taken into account.
When we write the HTML block width element, width: auto; the value is equal to the width
of the row by default. However, we may assign HTML components a particular width value,
such as width: 200px;.
We’ll need to do a quick calculation to see how much space our entire box takes up. Let’s
look at an example (let’s use the values that we had supplied in the margin code above):
height: 150px;
width: 150px;
padding: 20px;
border: 10px solid blue;
margin: 15px;
150px(Width) + 40(right and left padding) + 20px (right and left border) + 30px (right and
left margin) = 240
To calculate the height, we use the height’s pixels plus the top and bottom of the padding,
border, and margin.
Where the internet was originally intended for sharing scientific documents, now people
wanted to share other things as well. Very quickly, people started wanting to make the web
look nicer.
Because the web was not initially built to be designed, programmers used different hacks to
get things laid out in different ways. Rather than using the <table></table> to describe
information using a table, programmers would use them to position other elements on a page.
As the use of visually designed layouts progressed, programmers started to use a generic
“non-semantic” tag like <div>. They would often give these elements a class or id attribute to
describe their purpose. For example, instead of <header> this was often written as <div
class="header">.
As HTML5 is still relatively new, this use of non-semantic elements is still very common on
websites today.
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
Elements such as <header>, <nav>, <section>, <article>, <aside>, and <footer> act more or
less like <div> elements. They group other elements together into page sections. However
Prepared By. E. Janakiraman.MCA,MPhil. AP/APEC Page 15
where a <div> tag could contain any type of information, it is easy to identify what sort of
information would go in a semantic <header> region.
An example of semantic element layout by w3schools
Why use semantic elements?
To look at the benefits of semantic elements, here are two pieces of HTML code. This first
block of code uses semantic elements:
<header></header>
<section>
<article>
<figure>
<img>
<figcaption></figcaption>
</figure>
</article>
</section>
<footer></footer>
Whilst this second block of code uses non-semantic elements:
<div id="header"></div>
<div class="section">
<div class="article">
<div class="figure">
<img>
<div class="figcaption"></div>
</div>
</div>
</div>
<div id="footer"></div>
First, it is much easier to read. This is probably the first thing you will notice when looking
at the first block of code using semantic elements. This is a small example, but as a
programmer you can be reading through hundreds or thousands of lines of code. The easier it
is to read and understand that code, the easier it makes your job.
It has greater accessibility. You are not the only one that finds semantic elements easier to
understand. Search engines and assistive technologies (like screen readers for users with a
sight impairment) are also able to better understand the context and content of your website,
meaning a better experience for your users.
Overall, semantic elements also lead to more consistent code. When creating a header using
non-semantic elements, different programmers might write this as <div
class="header">, <div id="header">, <div class="head">, or simply <div>. There are so
many ways that you can create a header element, and they all depend on the personal
preference of the programmer. By creating a standard semantic element, it makes it easier for
everyone.
Since October 2014, HTML4 got upgraded to HTML5, along with some new “semantic”
elements. To this day, some of us might still be confused as to why so many different
elements that doesn’t seem to show any major changes.
<section>
<p>Top Stories</p>
<section>
<p>News</p>
<article>Story 1</article>
<article>Story 2</article>
<article>Story 3</article>
</section>
<section>
<p>Sport</p>
<article>Story 1</article>
<article>Story 2</article>
<article>Story 3</article>
</section>
</section>
<header> and <hgroup>
The <header> element is generally found at the top of a document, a section, or an article and
usually contains the main heading and some navigation and search tools.
<header>
<h1>Company A</h1>
<ul>
<li><a href="/home">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact us</a></li>
</ul>
<form target="/search">
<input name="q" type="search" />
The float property enables you to take an element out of normal flow and put content side-by-side.
Elements are floated horizontally , that means, an element can only be floated left or right only
Float property accepts keyword values left and right float elements those directions respectively and
set to none for not floated. When you set the float property for an element , you should specify the
width and height otherwise its sizing becomes shrink-to-fit horizontally and vertically.
<!Doctype>
<html>
<head>
<style>
.box1 {
background: #DDF;
height: 100px;
width:100px;
background: #4FFFA1;
height: 100px;
width:100px;
</style>
</head>
<body>
<div class="box1">
Box1
</div>
<div class="box2">
Box2
</div>
</body>
</html>
When you run this code on browser you will get the folowing output:
In the above picture the boxes are not set the float property.
float:left;
background: #DDF;
height: 100px;
width:100px;
.box2 {
float:left;
background: #4FFFA1;
height: 100px;
width:100px;
Now you can see the boxes floated from left to right.
.box1 {
float:left;
background: #DDF;
height: 100px;
width:100px;
.box2 {
float:right;
height: 100px;
width:100px;
}
output
Now you can see first box is floted to left and second one is floated to right.
z-index
While overlapping CSS elements, when using absolute and relative position, the default behavior is
to have the first elements underneath later ones. In these cases we can control layering of positioned
elements by using the z-index property . When using the z-index property you can specify which
of the boxes appears on top the other one.
<!Doctype>
<html>
<head>
<style>
div {
width:100px;
height:100px;
div.box1 {
background:#dad7d7;
position:relative;
z-index:1;
div.box2 {
background:#ffe7bc;
position:relative;
top:-80px;
left:50px;
z-index:2;
</style>
</head>
<body>
</body>
</html>
output
Now you can see the BOX-1 is behind the BOX-2, because z-index of BOX-1 is 1 and BOX-2 is 2.
Now we are going to change the z-index order as BOX-1 is 2 and BOX-2 is 1.
div {
width:100px;
height:100px;
div.box1 {
position:relative;
z-index:2;
div.box2 {
background:#ffe7bc;
position:relative;
top:-80px;
left:50px;
z-index:1;
}
output
Now you can see BOX-1 come in front and BOX-2 going behind the BOX-1.
It is noted that z-index works on positioned elements only like position:absolute, position:relative
and position:fixed.
Sass (Syntactically Awesome Style Sheets) is a powerful CSS preprocessor scripting language that
helps you to work on your style sheet much faster than ever. Sass allows you to use features such as
variables, nestings, modules, etc. that don’t exist in CSS. Apart from Sass, there are two other
important CSS extensions – Stylus & LESS (Leaner Style Sheets).
Also, with the help of Sass, you can improve DRY (Don’t Repeat Yourself) CSS and make your
code more readable. Additionally, it is also totally compatible with all versions of CSS. Once you
get familiar with Sass, you will feel more comfortable and easy to handle large scale projects. To
play around with Sass CSS preprocessor, you have to create a separate style sheet with the
extensions “.scss” or “.sass”. You can then compile it into a normal CSS file. Your browser will
read only the finally compiled CSS file to style your website/web application.
1. Requires Minimal Coding – Comparatively, Sass requires very few codes and help the
developers to write CSS quickly.
2. Rapid Code Compilation – Unlike other preprocessors, you can easily compile your code
using Sass command.
3. Bigger Developer Community – Sass has a massive ecosystem with a huge number of
active developers.
4. Powerful Frameworks – Sass uses Compass for mixins, which contains almost all possible
options, including updates for future support.
SCSS (New): SCSS is commonly called as Sassy CSS. You can save it with .scss extension.
It is a superset of CSS, which means it contains all the features that CSS holds. Also, you
can easily adapt yourself to SCSS if you are familiar with the basics of CSS.
Indented Syntax (Old): Indented Syntax can be implemented on style sheet with the .sass
extension. When compared to .scss, the indented syntax has a wider audience because it
helps you to write code quickly and concisely. Indented syntax use indentation to describe
the format of the document; whereas, .scss uses curly brackets and semicolons. Below is an
example of an indented syntax:
Indented
.content-navigation
border-color: $red
color: darken($red, 9%)
.border
padding: $margin / 2
margin: $margin / 2
border-color: $red
SCSS
$red: #FF0000;
$margin: 10px;
.content-navigation {
border-color: $red;
color: darken($red, 9%);
}
.border {
padding: $margin / 2; margin: $margin / 2; border-color: $red;
}
CSS
.content-navigation {
border-color: #FF0000;
color: #d10000;
}
.border {
padding: 5px;
margin: 5px;
border-color: #FF0000;
}
Variables
Sass enables you to use variables to store values, and you can use it wherever you need it. For instance, you
can store a specific color in a variable at the top of your style sheet, and call the respective variable wherever
you want to apply that color.
Nesting
Using the nesting method, you can reduce the amount of code massively. The nesting structure in Sass is
somewhat similar to HTML. Both technologies follow the same visual hierarchy. But, keep in mind that
nesting will over-qualify your CSS if you didn’t execute properly.
Partials
It is one of the most powerful Sass features. Partials are more like a portable style sheet that can be linked to
any other style sheet, and you can use it in another CSS file. It helps you to make your code transportable
and maintain it easily. Remember, the partials file name should start with an underscore: _example.scss.
You will get a clear picture of the partials below.
Modules
As discussed in the previous section, you can use some other sass files in your current sass file using @use
rule. It lets you incorporate multiple .sass files into your project file. Also, keep in mind that each import
will generate a new HTTP request. Too many HTTP requests will result in the slow down of your website.
Mixins
The main reason for using preprocessors is it helps you convert the long-winded code into a concise one.
That’s exactly where mixins come in. For instance, while working on vendor prefix on CSS, you will be
spending more time than usual. Instead of using CSS, you can use the mixin feature from Sass to avoid
writing the code again and again.
Extend/Inheritance
The @directive is usually called as the most powerful Sass features. You can use a group of CSS properties
from one selector to another using @directive. This implies that you don’t have to use multiple class names.
All you have to do is, write a set of CSS properties that will repeat in your program over and over and give it
a name. Then, wherever you want to apply those styles, include it using @directive.