Oracle APEX 如何在APEX中使用CSS

 
In order to keep the practice momentum of this practical Oracle APEX book (Create Rapid Web Applications Using Oracle Application Express) and to leave something for users to think over, I intentionally left aside the explanation area that is a crucial part of any technology book to provide details about how things actually work.
The purpose of this blog is to bridge that gap by providing explanations of each section of the book. I’ll try to guide you on every aspect that I feel necessary, but, will be grateful to receive your opinion as well about any area that you deem requires enlightenment.
To start with, I’ve chosen Chapter 6 (Place Orders) first, because, it is the lengthiest chapter among all others and has some advance topics that the intended audience of this book (novices) would be eager to learn.

Chapter’s Recap:

You create professional looking web pages to take orders from customers and create seven pages to complete this process in a sequence through a wizard-like approach. The first form will allow user to select an existing customer or create a new one. In the second step, user will select products to order and the last step will show summary of the placed order. Once an order is created, you can view, modify, and delete it through the Order Details page using the edit icon in the orders’ main page. Couple of other pages will be created as well to create a new customer, if one does not exist, and to display product information such as Description, Category and Price. Following are the details of pages that are created in this chapter:


Page No.
Page Name
Purpose
4
Orders
Main page to display all existing orders
29
Order Details
Display complete order with details
11
New Order – Identify Customer (Step 1a)
Select an existing customer
18
New Order – Create Customer (Step 1b)
If customer does not exist, create his/her account
12
New Order – Select Items (Step 2)
Add products to the order
20
Product Info
Show details of a product in a popup window
14
Order Summary (Step 3)
Show summary of the placed order

Before starting the proceedings, let’s acquaint ourselves with the following terms used in this chapter:

is used to group header content
is used to group body content
is used to group footer content
(table row) tag defines a row in an HTML table. It contains one or more
Term
Details
Region
As a developer, you add content to a page by creating a region. A region is an area of a page that serves as a container for content. Each region contains a different type of content such as HTML, a report, a form, a chart, a list, a breadcrumb, PL/SQL, a tree, a URL, or a calendar. You position a region either relative to other regions (that is, based on its sequence number and column), or by using a region position defined in the page template. The style of the region is also controlled by the region template. Like the page template, the region template defines the structure of the area that the region takes up on a page. It defines if the region title i s displayed and where it is displayed relative to the main content or the body. A region can also define absolute positions for buttons.
htp and htf Packages
htp  (hypertext procedures) and htf (hypertext functions) packages generate HTML tags. These packages translate PL/SQL into HTML that is understood by a Web browser. For instance, the htp.anchor procedure generates the HTML anchor tag, . The following commands generate a simple HTML document: 

Create or replace procedure hello AS
BEGIN
    htp.htmlopen;             -- generates
    htp.headopen;             -- generates
    htp.title('Hello');         -- generates Hello
    htp.headclose;             -- generates
    htp.bodyopen;             -- generates
    htp.header(1, 'Hello'); -- generates

Hello

    htp.bodyclose;            -- generates
    htp.htmlclose;             -- generates
END;

Oracle provided the htp.p tag to allow you to override any PL/SQL-HTML procedure or even a tag that did not exist. If a developer wishes to use a new HTML tag or simply is unaware of the PL/SQL analog to the html tag, he/she can use the htp.p procedure.
For every htp procedure that generates HTML tags, there is a corresponding htf function with identical parameters. The function versions do not directly generate output in your web page. Instead, they pass their output as return values to the statements that invoked them. See the use of these packages on page 113 of the book.  
htp.p / htp.print
Generates the specified parameter as a string
htp.p(‘

)

Indicates that the text that comes after the tag is to be formatted as a paragraph
Customer:
Renders the text they surround in bold
htf.escape_sc
Escape_sc is a function which replaces characters that have special meaning in HTML with their escape sequence.
converts occurrence of  to  &
converts occurrence of   to  "
converts occurrence of  to  <
converts occurrence of  > to  >

To prevent XSS (Cross Site Scripting) attacks, you must call SYS.HTF.ESCAPE_SC to prevent embedded javascript code from being executed when you inject the string into the HTML page.
sys.htf.escape_sc
The SYS prefix is used to signify Oracle’s SYS schema. The HTP and HTF packages normally exist in the SYS schema and APEX relies on them.
An HTML table contains three elements
The
or elements. 
Header Cell – defines a header cell in an HTML table
Standard Cell – contains data
html_PopUp
It is a function provided by APEX which opens a page in a popup (see page # 111)
Collection
Collection enables you to temporarily capture one or more non-scalar values. You can use collections to store rows a columns currently in session state so they can be accessed, manipulated, or processed during a use’s specific session. You can think of a collection as a bucket in which you temporarily store and name rows of information.
APEX_COLLECTION
Every collection contains a named list of data elements (or members) which can have up to 50 character attributes (varchar2 (4000)), 5 number, 5 date, 1 XML type, 1 BLOB, and 1 CLOB attribute. You insert, update, and delete collection information using the PL/SQL API APEX_COLLECTION.

You can access the members of a collection by querying the database view APEX_COLLECTIONS.
<style type="text/css">
(Page # 112)
     

           

Class Referenced in CSS

           

A normal paragraph.

           

Note that this is an important paragraph.

     

The body of this page contains three sections:

  1. Class Referenced in CSS

    . The text, “Class Referenced in CSS”, is enclosed in h1 html tag. It is called level 1 heading and is the most important header in a document; it is usually used to indicate the title of the document. The text is preceded by a class, named “header”. Considering the above class syntax, here, h1 is the element and header is the classname. Combined together (element.classname), this class is referenced in the style section using a CSS rule – h1.header {color:blue;} to present the heading in blue color. A CSS rule has two main parts: a selector, and one or more declarations. The selector is normally the HTML element you want to style. Each declaration consists of a property and a value. The property is the style attribute you want to change. Each property has a value. In the above h1.header {color:blue;} rule, h1 is the selector followed by the classname and {color:blue;} is the declaration.
  2. A normal paragraph.

    – A plain paragraph without any style applied to it. HTML documents are divided into paragraphs and paragraphs are defined with the

    tag.

    is called the start tag or opening tag while

    is called the end or closing tag.
  3. Note that this is an important paragraph.

    . A paragraph with a class named “styledpara”.  In the style section, the selector “p” followed by the classname “styledpara” having declaration{ color:red;} is referencing this section to present the paragraph text in red color.        
Now that you have understood how CSS are used in web pages, let’s get back to figure out how we used it in Page-12. Turn to page 113. There is a class named demoCustomerInfo defined in the PL/SQL Dynamic Content on this page. Here is the listing:

Line 1.
Line 2.          Customer:
Line 3.         

Line 4.              cust_first_name + cust_last_name)
Line 5.              cust_street_address1
Line 6.               cust_street_address2)
Line 7.               cust_city + cust_state
Line 8.               cust_postal_code
Line 9.         

Line 10.
           
This code displays the heading “Customer:” along with details of the selected customer as shown in Figure 6-19.


Figure 6-19 (A:sideCartItem  B:sideCartTotal  C:demoCustomerInfo  D:demoProducts  E:demoCurrentOrder  F:demoTitle  G:demoAddtoCart)

Now check the corresponding CSS code in the HTML Header section on page 112.
div.demoCustomerInfo  strong{font:bold 12px/16px Arial,sansserif;display:block;float:left;width:120px;}
div.demoCustomerInfo  p{display:block;float:left;margin:0; font: normal 12px/16px Arial,sans-serif;}

The first rule has the selector  strong which styles the title “Customer:” on Line 2 whereas the second one with the  p selector is used to style the values between tags

- Line 4 through Line 8.

Let’s play with the above two CSS rules and note the effect on our web page. In this exercise you will move customer’s information on the far right side. 
1.      Login to the application
2.      Click the Orders tab
3.      Click Enter New Order button
4.      Select an Existing customer
5.      On Select Items page, click button Edit Page 12 at the bottom of your screen
6.      Click Edit in the Page section
7.      Scroll down to HTML Header and Body Attribute section, locate the above two rules and change/add the properties shown in bold:
div.demoCustomerInfo strong{font:bold  18px/16px Arial,sans-serif;display:block;float:left; width:0px;padding-left:480px;}
div.demoCustomerInfo p{display:block;float: right;margin:0; font: normal 12px/16px Arial, sans-serif;}
8.      Apply changes and click Run. The Customer font increased from 12px to 18px. We added a property padding-left with a value of 480px. This will create a space of 480px from the left side and will show the title on the far right. Similarly, to show customer’s details on the right location we changed the float property from left to right. The width property in the previous rule was set to 120px to create a space between the title “Customer:” and the name of the customer. We set it to zero because we do not need that space now.


Using Cascading Style Sheet (CSS) in Oracle Application Express

This section explains CSS used in chapter 6, page 112. As mentioned earlier, CSS provides a way to control the style of a Web page without changing its structure. We used it in Page 12 of our application to present the page’s contents in a desired format. In Page 12, you select items for your order and is the second step in order processing wizard. Following are the CSS rules – explained individually.  


tag is used to define style information for an HTML document. Inside the
This is the closing style tag.

In this tutorial, we learned how CSS is used in Oracle Application Express to position page elements. I left out some unnecessary rules mentioned in the book that were there for experimentation purposes.
转载自:
【1】Using Cascading Style Sheets in Oracle Application Express
http://oracle-apex-book.blogspot.jp/2012/06/elucidation-chapter-6-place-orders.html




你可能感兴趣的:(apex)