0% found this document useful (0 votes)
74 views7 pages

Inline Styles: 10. Compare Inline, Embedded and External Style Sheet With Example

The document compares inline, embedded, and external stylesheets. Inline styles are coded directly into HTML tags and override embedded or external styles for individual elements. Embedded styles are defined within the <head> and override external styles without needing to define each element. External styles are defined in a separate CSS file and can change styles on all pages linking to that file. Examples are provided of each type of stylesheet.

Uploaded by

shreyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views7 pages

Inline Styles: 10. Compare Inline, Embedded and External Style Sheet With Example

The document compares inline, embedded, and external stylesheets. Inline styles are coded directly into HTML tags and override embedded or external styles for individual elements. Embedded styles are defined within the <head> and override external styles without needing to define each element. External styles are defined in a separate CSS file and can change styles on all pages linking to that file. Examples are provided of each type of stylesheet.

Uploaded by

shreyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

10.

Compare inline, embedded and external style sheet with example


Inline Styles
An inline style rule is coded directly into an HTML tag within the flow of your source
code, just as an HTML attribute is used. The purpose of inline styles is to allow you to
override an embedded or linked style rule, or to make a quick change of style where you
don't want a reusable rule. For example, you may have a rule that specifies H1 headings
should be the color blue. If you have a place on your page where you want an H1 heading
in red, an inline style rule allows you to override an embedded or external style rule. To
override an embedded or linked style, an inline style must be coded into each HTML
element each time you want to override the embedded or linked style.
<p id="inlineExample" style="background: yellow">Inline style example</p>
Embedded Styles
Embedded styles are set in the HEAD section of your web page. Similar to an inline style
rule, embedded styles allow you to override the rules of an external style sheet. The
difference is that with an embedded rule, you don't have to create a rule with each use of
an HTML element. An H1 heading given the color red in an embedded style rule will
render the H1 heading in red every time you use it on the page without having to code the
rule into each heading tag as you must do with inline rules or with HTML attributes.
<head>
...
<style type="text/css">
p#embeddedExample {
background: orange;
}
</style>
...
</head>
...
<p id="embeddedExample">Embedded style example</p>

External Styles
External styles (sometimes called linked styles or remote styles) are the least important in
the cascading order*, but the most powerful! An external style is simply a link placed in
the HEAD section of your web page to a separate file containing your style rules. The
primary advantage of using external styles is that you can change that one external file,
and have that change reflected on every page of your site that links to the external CSS
file. Any or all methods of implementing CSS can be used on the same page.
<head>
...
<link rel="stylesheet" type="text/css" href="external-styles.css" />
...
</head>
...
<p id="externalExample">External style example</p>
...
03. Write a sample code demonstrating block level and alignment tags in HTML.
<!DOCTYPE html>
<html>

<head>
<title>HTML div Tag</title>
</head>

<body>
<!-- First group of tags -->
<div style = "color:red">
<h4>This is first group</h4>
<p>Following is a list of vegetables</p>

<ul>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</div>

<!-- Second group of tags -->


<div style = "color:green">
<h4>This is second group</h4>
<p>Following is a list of fruits</p>

<ul>
<li>Apple</li>
<li>Banana</li>
<li>Mango</li>
<li>Strawberry</li>
</ul>
</div>
</body>

</html>

This is first group

Following is a list of vegetables

 Beetroot
 Ginger
 Potato
 Radish
This is second group

Following is a list of fruits

 Apple
 Banana
 Mango
 Strawberry

15. Write a JavaScript program to perform a binary search


<html>
<head>
<title>Binary Search</title>
<script type="text/javascript">
function binary()
{
var n=parseInt(prompt("enter the size of an array: "));
var a=new Array(n);
var p=0;
for(var i=0;i<a.length;i++)
{
a[i]=parseInt(prompt("enter array elements"));
}
for(var i=0;i<a.length;i++)
{
for(var j=i+1;j<a.length;j++)
{
if(a[i]>a[j])
{
var t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
var k=parseInt(prompt("enter the key element "));
var i=0;
var u=parseInt(a.length-1);
while(i<=u)
{
var m=parseInt((i+u)/2);
if(k==a[m])
{
p=1;
break;
}
else if(k>a[m])
{
i=m+1;
}
else if(k<a[m])
{
u=m-1;
}
}
if(p==1)
document.writeln("element found at :"+m);
else
document.writeln("element not found");

}
</script>
</head>
<body onLoad="binary();"></body>
</html>

29. Demonstrate with suitable example PHP session and PHP cookie.
What is a Cookie?

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the
user's computer. Each time the same computer requests a page with a browser, it will send the
cookie too. With PHP, you can both create and retrieve cookie values.

Create Cookies With PHP

A cookie is created with the setcookie() function.

Syntax
setcookie(name, value, expire, path, domain, secure, httponly);

Only the name parameter is required. All other parameters are optional.
PHP Create/Retrieve a Cookie

The following example creates a cookie named "user" with the value "John Doe". The cookie
will expire after 30 days (86400 * 30). The "/" means that the cookie is available in entire
website (otherwise, select the directory you prefer).

We then retrieve the value of the cookie "user" (using the global variable $_COOKIE). We also
use the isset() function to find out if the cookie is set:

Example
<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
<html>
<body>

<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>

</body>
</html>
PHP Sessions

❮ PreviousNext ❯

A session is a way to store information (in variables) to be used across multiple pages.

Unlike a cookie, the information is not stored on the users computer.


What is a PHP Session?

When you work with an application, you open it, do some changes, and then you close it. This is
much like a Session. The computer knows who you are. It knows when you start the application
and when you end. But on the internet there is one problem: the web server does not know who
you are or what you do, because the HTTP address doesn't maintain state.

Session variables solve this problem by storing user information to be used across multiple pages
(e.g. username, favorite color, etc). By default, session variables last until the user closes the
browser.

So; Session variables hold information about one single user, and are available to all pages in
one application.

Tip: If you need a permanent storage, you may want to store the data in a database.

Start a PHP Session

A session is started with the session_start() function.

Session variables are set with the PHP global variable: $_SESSION.

Now, let's create a new page called "demo_session1.php". In this page, we start a new PHP
session and set some session variables:

Example
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>
</body>
</html>

You might also like