Set styles to div

I am new to css and not a programmer. I understand what a class is and I understand what a div is, but what I cannot find is how to set the styles for the div.

Any help is appreciated,

Joost verplancke

+3
source share
5 answers

In your HTML

<div class="myClass">Look at me!</div>

In your CSS

.myClass
{
   background-color:#eee;
}

EDIT

As Dave noted, you can assign multiple classes to an element. This means that you can modularly style styles as needed. Helps with the DRY principle .

For example, in your HTML

<div class="myClass myColor">Look at me too!</div>

In your CSS

.myClass
{
   background-color:#eee;
   color:#1dd;
}

.myColor
{
   color:#111;
}

, class , . , class="myClass myColor" class="myColor myClass". , CSS.

, , color myColor color myClass, CSS, .

.myColor
{
   color:#111;
}

.myClass
{
   background-color:#eee;
   color:#1dd;
}
+13

div, div id.

CSS , div.

#specialDiv {
    font-family: Arial, Helvetica, Sans-Serif;
}

<div id="specialDiv">Content</div>

.specialDiv {
    font-family: Arial, Helvetica, Sans-Serif;
}

<div class="specialDiv">Content</div>

div:

<div style="font-family: Arial, Helvetica, Sans-Serif;">Content</div>
+6
 <div class="featured">Featured</div>

 <style type="text/css">
      .featured { padding:5px; font-size:1.4em; background-color:light-yellow; }
 </style>

(.) ids (#) .

+4

, :

#test 
 {
  background-color: red;
 }

(), - :

.test
 {
  background-color: red;
 }

, :

<div id="test"> this is a test </div>

# :

<div class="test"> this is a test </div>

.

- : http://www.w3schools.com/css/

CSS. css, / , inline. - , . inline.

0
<div style = "your css goes here"> </div>

Edit - Don’t do this, Announcement Rights. I misunderstood your question. You already have a lot of really good answers that give you the information you are asking for.

-1
source

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


All Articles