Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic CSS Concepts

Tags:

html

css

After discussion with some of my friends about css concepts, I have some questions to ask to you guys.

When do we use Id and class in css? and we have a conflict idea with Div and Span. When are Div and Span are used?

Any key to these questions?

like image 649
Sinal Avatar asked Nov 28 '22 05:11

Sinal


2 Answers

A basic rule is that an ID may only exists once in the complete page. The ID is usually used to identify an object in your page. Most of the time you will use class in CSS.

A span is an in-line element, a div is a block element (by default, you can override this in your CSS). Spans are usually used inside a textblock to "mark" a piece of text. A div is used to group objects in a container.

Hope this helps you a bit.

like image 117
Gertjan Avatar answered Dec 14 '22 22:12

Gertjan


div is used as a section of a document. span is used to style individual parts of text. A key difference is that a div will insert a line break on either side.

However div and span are HTML not CSS.

You use id when there is one of an element and you need it to be uniquely identified. You use class when there are multiple element which you want to apply the same stylings to.

like image 21
Mike McQuaid Avatar answered Dec 14 '22 22:12

Mike McQuaid