CSS: font color, styles, background, size

Programming is like a mirror: at the beginning there was a word, but not the answer was reflected. And very quickly I had to ā€œchangeā€: first the mirror, then the word ... At the given time, cascading style sheets are good, but why did the developerā€™s consciousness go to them for so long? CSS is still the same array of times since the beginning of the era of computer programs, but only from a different angle. Even when arrays became associative, this did not produce a revolution.

CSS font color

A site page is an HTML markup tag that can be assigned a specific style class or style identifier. The first can be determined once and attributed to anything as many times as needed, the second belongs to a specific element.

General style description logic

By tradition, a style is placed in a CSS file, but can be assigned to a specific element in its style attribute. A style can be created dynamically using JavaScript. It does not really matter how to describe, for example, through CSS, the font color, size, typeface, background beneath it, and so on. The place to describe a style matters in the context of usually two ideas: the later it is described, the more priority it is, and if it is described on an element, then it is! Important. The last one, recorded as is, clearly defines the priority.

Font color

You can apply style so that, for example, a certain font color changes color, anywhere and anytime. The question is how the browser will react to this in the process of disassembling all the styles in the aggregate. How much will he spend CPU time on this?

Ideally, font color should be indicated only once - this is a classic. To think of one simple description a couple more, and then another and more ... of course, you can. It is fashionable but impractical.

Common Logic Example

Everything is very simple: by defining with CSS color for just three elements, you can get at least three long-playing problems:

# Ele1, # Ele2, # Ele3 {
POSITION: absolute;
left: 20px;
top: 14px;
color: red;
}

# Ele2, # Ele3 {
left: 90px; // change the horizontal coordinate of CSS
color: yellow; // change CSS font color
}

# Ele3 {
top: 114px; // change CSS vertical coordinate

color: green; // change CSS font color again

background-color: lightgrey; // CSS text selection color is changed, but this is not present in # Ele1 and # Ele2; the position is also changed, but it has already changed in # Ele2 and not like it is here

}

Now you have to remember that all these three elements are defined somewhere, and in case of changing the color representations of the site owner, the developer will have to remember not only about color, but also about the rules left and top, and you should not forget about changing the color of highlighting the text.

Not all developers honor the CSS requirement: the identifier style is for only one element, and the class style is for many tags, and the latter can be indicated as adjectives in the tags:

  • set the font color in CSS - style of the groundColor class;
  • specify the font size - class size15;
  • set position - PlaceUp class.

Naturally, the use of identifiers, especially when they belong to the same markup element, is better than a dozen style classes, painted in different combinations of hundreds of page elements. But everything has its own objective logic.

The developer simply has to competently take into account: even if the font color of HTML, CSS offers to describe rigidly, then the flexibility of the general structure of descriptions is his job.

Expected Result of Applying Common Logic

Modern browsers calmly relate to a large number of style files and their volumes. However, when designing, in particular, through CSS, the color of the entire page, you should always think about reasonable sufficiency. Not all style rules are ā€œcheapā€ in use. Simple concise notation: * {color: white;} - certainly beautiful, but it applies to all elements of the page without exception.

CSS color

Of all the rules that CSS is equipped with, the most important:

  • style is a class, and then its name begins with ".";
  • style - identifier and its name begins with the symbol "#";
  • in other cases, this is the name of the tag or something special

The remaining ideas regarding the description of styles (inheritance, overlapping properties, priorities, position, order, etc.) should be applied meaningfully and strictly as necessary.

The browser will always miss what it does not make out in the description, so there will be no special surprises. If something wasnā€™t in the right place or it was not possible to set the font color in CSS, then a style error.

Unexpected opportunities

Do not abuse styles like * {left: 124px; } or

ol ol, ol ul, ul ul, ul ol {margin-bottom: 0; }
a img {border: 0; }

Although it's hard to get even a novice developer to use CSS rules as they are. Always in the design of any website, even perfectly simple CSS syntax presents unforeseen problems. However, if we direct our efforts towards the correct use of syntax, but apply JavaScript functionality to it, then unexpected new features will allow us to avoid the monotonous creation of identifiers for each element or to monitor the variety of application of style classes.

Change css font color

CSS is not only a stylesheet connected to a page through a link tag or inserted into it through a style tag. It is also an opportunity to create a style on the fly or change an existing one.

Using CSS, the font color can be made programmatically. As well as size and position, indentation. A site is not a goal to apply knowledge in CSS, HTML, PHP or to show off effects of JavaScript.

A web resource is primarily information that is offered in a certain way. That is why CSS is best viewed in dynamics through the prism of how you can create, while the page is still on the server (PHP is busy with it when the visitor came to the site, and not the developer when he was developing the site), the desired stylesheet under a specific text, under relevant content, or create a style of a class or identifier on the fly in the process of working a page when it is viewed by a specific visitor.

Static dynamics

It is not always necessary to write complex JavaScript-code to make the content dynamic, and its design - adequate to the content. Sometimes itā€™s enough to use the available opportunities correctly. In particular, by using CSS to determine the font color as an initially static rule, you can hide this rule (hidden) and render another (visible).

Set font color in css

Here the dynamics do not require an algorithm:

// highlight the button to enter the site
function scfWelcomeOver () {
document.getElementById ('scDocxNamePiP'). style.visibility = 'visible';
}

// hide the login button
function scfWelcomeOut () {
document.getElementById ('scDocxNamePiP'). style.visibility = 'hidden';
}

CSS offers its own dynamics options: creeping lines, element transparency, various options for overlays, manifestations, color fading. In CSS, the font color can even be made such that no style rule provides for it.

Dynamic content display

If there were no dogmas, probably there would have been no progress. There is simply nothing to fight with. Hypertext brought a lot of dogma to the world. It is time to pay attention to them and start developing sites in a pragmatic and practical style.

CSS html font color

Initially, there is a page (P), content (K) is placed on it, all page tags are described in the style sheet (S). It is not new to form page P through PHP or Perl on the server, choosing K from the database. The existing stylesheet S will be applied automatically. However, K can be changed, and in most cases, such a change will entail the need for other styles, that is, S +.

For example, a customer said: ā€œA site describing the life of Moscow would look better if news articles were written in the style of" Breakfast and Breakfast ", descriptions of the nightlife in the style of Las Vegas, and articles on scientific and technological progress in the style of ModernTechno." But if you make S for these three options, then there is no guarantee that the customer will not have an idea to have a set of articles "News", "Holidays", "Work", "CSS / HTML" and the bonus "MistressNote".

Another approach is more practical. Regardless of the category of the article, it always has content that can be painted in a specific color. Here at this place there is quite a sound idea: having received a specific K, form an adequate S on the server, and when the browser requires P, it will receive the necessary content in the proper design.

JavaScript style dynamics

A minimal, albeit a very effective solution is to do the styling directly in the clientā€™s browser. Firstly, it offloads the server - there will be no need to spend time creating the hypertext of the page and style files for it.

Secondly, the natural waste of time inside the browser will create the effect that the page is busy with business and actively maintains a dialogue with the visitor: anyway, he does not perceive the content in bulk, therefore, he will like a consistent and thoughtful output of information.

Thirdly, this enables the developer to provide the visitor with a mechanism for creating content in a style that is convenient for him. Nobody has this yet.

To implement this idea, it is necessary to implement a mechanism for creating styles of elements immediately after loading the page and in the process of its functioning. A modern site is AJAX in one form or another. It is not difficult to perform the formation of styles directly in the process of forming the page tree. It is simple, affordable and effective, because the content comes with its design.

This does not contradict the current tendency to separate the presentation of data from their processing and is performed on data that goes into display.

CSS as an active component

Hypertext brought a lot of good, but only a small fraction of natural information was successfully formalized, tools and experience appeared in creating high-quality HTML, XML, CSS documents. It is not a problem to formalize new volumes of information and change what has already been done.

With regard to CSS, this process is already being activated in a completely different context. Built-in JavaScript tools that allow you to create elements and element styles on the fly did not suggest such an opportunity, and the creators of PHP, in particular, intended to create HTML pages only.

Both the first and second allow you to do programming styles. This is a new direction in the field of information technology. Styles are a much more formal thing than HTML or XML; the rules are very simple. Style is always present in information, whatever nature it may be.

Programmers are always involved in data processing in much more informal spheres, but the CSS theme is a very simple task, but somehow it did not fall into the field of view of the development process.

About dogmas in the field of programming

Like an iceberg, dogma cannot plow information spaces for a long time. The accumulated experience should have been concentrated not only in HTML and CSS standards, tools for working with them, the knowledge of developers.

CSS text highlight color

The simple task of making the font color with CSS was a great solution. Rules, syntax, logic, and usability are certain. But even when there really arenā€™t a lot of fonts needed, there arenā€™t a lot of colors for practice, and indeed for the purposes of virtualization of reality all the accumulated ā€œpowerā€ of HTML and CSS is not needed at all, there comes a time when situational knowledge goes into reproducing ones, and it appears experience and tools for natural education styles from content.

How this will be may not be entirely clear, but the fact that the process is already ongoing is obvious.

Source: https://habr.com/ru/post/K946/


All Articles