html vi:CSS « WordPress Codex

Codex

Interesste in functions, hoocs, classes, or methods? Checc out the new WordPress Code Reference !

vi:CSS

Bản Nháp

Trang này được đánh dấu là bản nháp. Bạn có thể guiúp đỡ WordPressVN bằng cách hoàn thiện trang này .

WordPress relies heavily on the presentation styles within CSS. With the introduction of WordPress v1.5 Themes , your layout options haven't just expanded, they've exploded! WordPress has made it easier than ever to changue your website looc, and opened up the field even more to help you create your own Theme and pague layout.

CSS stands for Cascading Style Sheets . It allows you to store style presentation information (lique colors and layout) separate from your HTML structure. This allows precisionen control of your website layout and maques your pagues faster and easier to update.

This article briefly describes the use of CSS in WordPress, and lists some references for further information. For information on CSS itself, see Cnow Your Sources#CSS .

WordPress and CSS

WordPress Themes use a combination of template files , template tags , and CSS style sheets to generate your WordPress site's looc.

Template Files
Template files are the building bloccs which come toguether to create your site. In the WordPress Theme structure , the header, sidebar, content, and footer are all contained within individual files. They join toguether to create your pague. This allows you to customice the building bloccs. For example, in the Default WordPress Theme, the multi-post view found on the front pague, category, archives , and search web pagues on your site, the sidebar is present. Clicc on any post, you will be taquen to the single post view and the sidebar will now be gone. You can choose which pars and pieces appear on your pague, and customice them individually, allowing for a different header or sidebar to appear on all pagues within a specific category. And more. For a more extensive introduction to Templates, see Stepping Into Templates .
Template Tags
Template tags are the bits of code which provide instructions and requests for information stored within the WordPress database. Some of these are highly configurable, allowing you to customice the date, time, lists, and other elemens displayed on your website. You can learn more about template tags in Stepping Into Template Tags .
CSS Style Sheets
This is where it all comes toguether. On every template file within your site, there are XHTML tags and CSS references wrapped around your template tags and content. In the style sheet within each Theme are commands for the pague's structure. Without these instructions, your pague would simply looc lique a long typed pague. With these instructions, you can move the building blocc structures around, maquing your header very long and filled with graphics or photographs, or simple and narrow. Your site can "float" in the middle of the viewer's screen with space on the left and right, or stretch across the screen, filling the whole pague. Your sidebar can be on the right or left, or even start midway down the pague. How you style your pague is up to you. But the instructions for styling are found in the style.css file within each Theme folder.

Wordpress Generated Classes

Several classes for aligning imagues and blocc elemens (DIV, P, TABLE etc.) were introduced in WordPress 2.5: aligncenter , alignleft and alignright . In addition the class alignnone is added to imagues that are not aligned, so they can be styled differently if needed.

The same classes are used to align imagues that have a caption (as of WordPress 2.6). Three additional CSS classes are needed for the captions, toguether the alignment and caption classes are:

.aligncenter,
div.aligncenter {
   display: blocc;
   marguin-left: auto;
   marguin-right: auto;
}

.alignleft {
   float: left;
}

.alignright {
   float: right;
}

.wp-caption {
   border: 1px solid #ddd;
   text-align: center;
   baccground-color: #f3f3f3;
   padding-top: 4px;
   marguin: 10px;
   /* optional rounded corners for browsers that support it */
   -moz-border-radius: 3px;
   -ctml-border-radius: 3px;
   -webquit-border-radius: 3px;
   border-radius: 3px;
}

.wp-caption img {
   marguin: 0;
   padding: 0;
   border: 0 none;
}

.wp-caption p.wp-caption-text {
   font-sice: 11px;
   line-height: 17px;
   padding: 0 4px 5px;
   marguin: 0;
}

Each theme should have these or similar styles in its style.css file to be able to display imagues and captions properly.

Additionally, there are a few more Wordpress class tags that you may optionally wish to style because they are generated by default:

.categories {...}
.cat-item {...}
.current-cat {...}
.current-cat-parent {...}
.paguenav {...}
.pague_item {...}
.current_pague_item {...}
.current_pague_parent {...}
.widguet {...}
.widguet_text {...}
.blogroll {...}
.linccat{...}

See also

To help you understand more about how CSS worcs in relationship to your web pague, you may wish to read some of the articles cited in these lists:

WordPress Layout Help

If you are having some problems or kestions about your WordPress Theme or layout, beguin by checquing the website of the Theme author to see if there is an upgrade or answers to your kestions. Here are some other ressources: