CSS (Cascading layout Sheets) is the password that formats web content. CSS basics walks through maafkan saya you need to gain started. We"ll answer concerns like: how do i make message red? just how do ns make content display in ~ a certain location in the (webpage) layout? just how do ns decorate my webpage v background images and colors?
Like HTML, CSS is not a programming language. It"s not a markup language either. CSS is a style sheet language.
Anda sedang menonton: Apakah ciri bagian teks yang disebut
CSS is apa you usage to selectively layout HTML elements. Because that example, this CSS selects paragraph text, setup the shade to red:
Let"s shot it out! lihat a message editor, paste the three lines that CSS (above) right into a new file. Save the paper as style.css in a magazine named styles.
To make the code work, we still require to use this CSS (above) to your HTML document. Otherwise, the styling won"t change the appearance of the HTML. (If girlfriend haven"t been adhering to our project, pause di sini to read dealing with files and HTML basics.)save index.html and load it in your browser. You have to see something prefer this:
Anatomy the a CSS ruleset
Let"s dissect the CSS code for red paragraph text to understand just how it functions :
The whole struktur is called a ruleset. (The hatchet ruleset is regularly referred come as hanya rule.) note the names of the separation, personal, instance parts:Selector
This is the HTML aspect name at the awal of the ruleset. It specifies the element(s) to it is in styled (in this example, elements). To layout a berbeda element, change the selector.penjelasan
This is a single rule favor color: red;. It specifies which of the element"s properties you want to style.nature
These are ways in which you can format an HTML element. (In this example, shade is a building of the elements.) In CSS, you choose which properties you want to impact in the rule.property value
To the right of the property—after the colon—there is the property value. This chooses one out of many possible appearances because that a given property. (For example, there room many color values in enhancement to red.)
Note the other important parts of the syntax:apart from the selector, every ruleset should be wrapped in curly braces. () Within each declaration, you must use a colon (:) to separate the building from its worth or values. Within every ruleset, you must use a semicolon (;) to separate each declaration from the lanjut one.
To modify multiple residential property values in one ruleset, write them be separated by semicolons, prefer this:
p color: red; width: 500px; border: 1px heavy black;
Selecting multiple elements
You can juga select multiple elements and apply a solitary ruleset to all of them. Separate multiple selectors by commas. For example:
p, li, h1 color: red;
Different types of selectors
There are many different types of selectors. The examples over use element selectors, which pick all elements of a provided type. But we have the right to make an ext specific selections as well. Di sini are few of the an ext common types of selectors:
|Element selector (sometimes referred to as a tag or kind selector)||All HTML elements of the mentioned type.||pselects|
|ID selector||The element on the page with the mentioned ID. Top top a provided HTML page, each id value need to be unique.||#my-idselects or|
|Class selector||The element(s) on the halaman with the stated class. Multiple instances the the same course can appear on a page.||.my-classselects and also|
|Attribute selector||The element(s) top top the halaman with the stated attribute.|| img|
CSS: all about boxes
Something you"ll notification about writing CSS: a most it is around boxes. This includes setup size, color, and also position. Most HTML facets on your halaman can be pikiran of together boxes sitting on top of various other boxes.
CSS layout is mostly based on the box model. every box taking up an are on your halaman has properties like:padding, the space around the content. In the instance below, that is the room around the i text. Border, the heavy line the is just outside the padding. Margin, the an are around the exterior of the border.
In this ar we tambahan use:broad (of one element). Background-color, the color behind an element"s content and padding. Color, the shade of an element"s content (usually text). Text-shadow sets a drop shadow on the message inside an element. Display screen sets the display screen mode of one element. (keep reading to find out more)
To continue, let"s add more CSS. Keep adding these brand-new rules in ~ the bottom that style.css. Experiment with changing values to see maafkan saya happens.
Changing the halaman color
html background-color: #00539F;
Styling the body
body width: 600px; margin: 0 auto; background-color: #FF9500; padding: 0 20px 20px 20px; border: 5px solid black;
Positioning and also styling the main page title
h1 margin: 0; padding: 20px 0; color: #00539F; text-shadow: 3px 3px 1px black;
Next, we collection the heading"s top and bottom padding to 20 pixels.
Following that, we collection the heading message to it is in the same color as the HTML elevator color.
Finally, text-shadow uses a zero to the text content of the element. Its 4 values are:The very first pixel worth sets the horizontal offset that the zero from the text: how far it moves across. The second pixel value sets the vertical offset of the zero from the text: how much it moves down. The third pixel value sets the blur radius that the shadow. A bigger value produces a much more fuzzy-looking shadow. The fourth value setsthe base color of the shadow.
Try experimenting with different values come see just how it transforms the appearance.
Centering the image
img display: block; margin: 0 auto;
The is a block element, meaning it ambil up space on the page. The margin used to a block element will be respect by other elements on the page. In contrast, images are inline elements, because that the auto margin cheat to work-related on this image, we must provide it block-level behavior lihat display: block;.
Note: The instructions above assume that you"re lihat an photo smaller 보다 the width set on the body. (600 pixels) If your photo is larger, it will certainly overflow the body, spilling into the rest of the page. To solve this, you can either: 1) reduce the photo width penampilan a graphic editor, or 2) use CSS to dimension the photo by setup the width residential or commercial property on the
(You have the right to view our version here.) If you gain stuck, friend can selalu compare your work-related with ours finished example code ~ above GitHub.
In this exercise, us have just scratched the surface of CSS. To go further, see discovering to layout HTML using CSS.
In this module
Found a difficulty with this page?
Last modified: Oct 8, 2021, through MDN contributorsChange your languageSelect your preferred language bahasa inggris (US)DeutschEspañolFrançais日本語한국어PolskiPortuguês (doBrasil)Русский中文 (简体)正體中文 (繁體) adjust language