What does a dot before a variable indicate in html?

本小妞迷上赌 提交于 2019-12-01 17:44:18
Couto

those are not variables. Those are CSS Selectors, and they represent a HTML node with that class per example

<div class="page_title">Page Title</div>

You use CSS Selectors to style those elements in the HTML


Since they've suggested. =)

There are a few ways to reference HTML nodes in CSS, the most common are ID's, Classes and the tag name.

take a look at this example

<div>
    <ul id="first_set">
       <li class="item"> Item 1 </li>
       <li class="item"> Item 2 </li>
    </ul>
    <ul id="second_Set">
       <li class="item"> Item 1 </li>
       <li class="item"> Item 2 </li>
    </ul>
</div>

Ok. we have a div with two unordered lists, each list as two list-items, now the CSS:

div { background-color: #f00; } 
#first_set { font-weight: bold; }
#second_set { font-weight: lighter; }
.item { color: #FF00DA }

the div selector will select all <div> 's in the HTML page, the # means ID, so #first_set it will select the object with that id in this case it will select

<ul id="first_set">

the dot symbol select classes so the .item selector will select all objects with the item class in this case it will select all

<li class="item">

This is just the basics really, you can mix these selectors to be more specific per example:

#first_set .item { text-decoration: underline; }

and it will only select the objects with class item that are inside the #first_set.


It's worth mentioning that in general, an ID (selected with #myID) should only be used ONCE on an HTML page, and a class can be used on multiple elements. Additionally, an element can have more than one class; just separate them with spaces. (e.g., <li class="item special-item">) – Platinum Azure

That is to mark a style grouping as a class in CSS. Please go through the tutorial @w3schools, that is a real good starter.

http://www.w3schools.com/css/default.asp

usually the class something belongs to for example

.treeListContainer input

treelistcontainer is the class and input is the control within the class so the style only affects the controls within that class

The section you talk about is CSS embedded in HTML. Neither CSS nor HTML have variables, you are looking at selectors.

The dot prefix indicates that it is a class selector and will match an HTML element which is a member of the given class.

To make an element a member of a class, the class name is added to the space separated list given as the value of the class attribute.

Thus .page_title will match an element with:

class="foo page_title bar baz"

Generally speaking, however, anything you give a class name such as "page_title" to is likely to be the same thing as the main heading, so the HTML should usually look like:

<h1>Main heading goes here</h1>

And the CSS:

h1 { … }

Incidentally, <!-- Modify these styles -->, is an error in HTML (and HTML compatible XHTML). A CSS comment is delimited with /* and */.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!