Basics CSS Questions Part 1
What does CSS stand for?
- Cascading Style Sheets.
What is the purpose of CSS?
- It's used to style the layout and appearance of web pages.
How do you link an external CSS file to an HTML document?
- Using the
<link>
tag within the HTML<head>
section, like this:<link rel="stylesheet" href="styles.css">
.
- Using the
What is the difference between padding and margin in CSS?
- Padding is the space inside an element, while margin is the space outside the element.
How do you select an element by its ID in CSS?
- Using
#
followed by the ID name. For instance,#myElement { ... }
.
- Using
Explain the box model in CSS.
- The box model describes how elements are rendered on a web page, including content, padding, border, and margin.
What is the default display property for most elements in CSS?
display: block;
for elements like<div>
,<p>
, etc., anddisplay: inline;
for elements like<span>
.
How do you center an element horizontally in CSS?
- Using
margin: 0 auto;
with a fixed width ortext-align: center;
for inline elements within a container.
- Using
What are pseudo-classes in CSS?
- They are keywords added to selectors that specify a special state of the selected elements.
What is the difference between
inline
andblock
elements in CSS?Inline
elements do not start on a new line and only take up as much width as necessary, whileblock
elements start on a new line and take up the full width available.
Explain the difference between
padding
andmargin
.Padding
is the space inside an element, whilemargin
is the space outside the element.
What is the purpose of
z-index
in CSS?- It determines the stacking order of positioned elements.
How do you include comments in CSS?
- Using
/* */
around the comment text.
- Using
What is the difference between
em
andrem
units in CSS?em
units are relative to the font size of the nearest parent element, whilerem
units are relative to the root element's font size.
How do you make a text italic in CSS?
- Using the
font-style: italic;
property.
- Using the
What is the use of the
float
property in CSS?- It's used to position elements to the left or right inside their container.
How do you apply a background color to an element in CSS?
- Using the
background-color
property.
- Using the
What is the purpose of the
position
property in CSS?- It defines the type of positioning method used for an element.
Explain the difference between
class
andid
in CSS.Class
can be used multiple times in a document, whileid
must be unique within a document.
How do you hide an element in CSS?
- Using
display: none;
.
- Using
What does the
overflow
property do in CSS?- It specifies what should happen if content overflows its containing element.
What is the purpose of the
box-sizing
property in CSS?- It defines how the total width and height of an element are calculated.
How do you set the text color in CSS?
- Using the
color
property.
- Using the
What is the purpose of the
@media
rule in CSS?- It is used to apply different styles for different media types/devices.
How do you select all paragraphs in CSS?
- Using the
p
selector:p { ... }
.
- Using the
Subscribe to my newsletter
Read articles from Namya Shah directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Namya Shah
Namya Shah
I am a developer who is very enthusiast about technology and coding.