CSS Questions
CSS Questions
● CSS1
● CSS2
● CSS3
CSS1 was founded in 1996, which was the first version. The latest CSS version is CSS3,
which is the most advanced version with numerous functionalities and features.
Q3. How do you include CSS on a web page?
Three ways to include CSS in web pages.
● The inline approach is used to insert style sheets into an HTML document.
● The embedded/internal method applies a distinct style to a single copy.
● When you want to make changes on numerous pages, you use the
linked/imported/external technique.
● Bootstrap
● Tailwind CSS
● Foundation
● Bulma
● Skeleton
● Ulkit
● Milligram
<style>
body {
background-color: linen;
}
h1 {
color: red;
margin-left: 80px;
}
</style>
Padding is the space inside the border and between the border and the actual image or cell
contents. Note that padding goes completely around the contents. It can be on the top,
bottom, right and left sides.
Margins are the spaces outside the border, between the border and the other elements next
to this object.
Make sure that when you write CSS color styles, you use the US English spelling for them:
● color
● background-color
● border-color
● outline-color
● Selector
● Property
● Value
As an example:
<style>
img.trans {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
</style>
<style>
*{
color: green;
font-size: 20px;
}
</style>
<style>
body {
background-image: url("paper1.gif");
margin-left:100px;
}
</style>
<style>
.center {
text-align: center;
color: blue;
}
</style>
CSS Id Selector
<style>
#para1 {
text-align: center;
color: blue;
}
</style>
Syntax
Syntax
<style>
body {
background-color: linen;
}
h1 {
color: red;
margin-left: 80px;
}
</style>
Syntax
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Q23. Explain the CSS Box model and what are its
components.
CSS box models specify the design and layout of CSS elements.
● Margin: Margin is the area around the border that is removed. It is unmistakable.
● Border: This is the area around the cushioning.
● Padding: It eliminates the area around the content. It is transparent.
● Content: It means content like text, images, etc.
The closest option is the 'initial' property value, which restores the default CSS values rather
than the browser's default styles.
<!DOCTYPE html>
<html>
<head>
<style>
h1.vis {
visibility: visible;
}
h1.hid {
visibility: hidden;
}
</style>
</head>
<body>
<h1 class="vis">It is visible</h1>
<h1 class="hid">It is hidden</h1>
Display: none also hides the element but does not occupy space. It will not affect the layout
of the document.
<!DOCTYPE html>
<html>
<head>
<style>
h1.vis {
display: block;
}
h1.hid {
display: none;
}
</style>
</head>
<body>
<h1 class="vis">It is visible</h1>
<h1 class="hid">It is hidden</h1>
<p>Note - Second heading is hidden and not occupy space.</p>
</body>
</html>
CSS3 also includes new General Sibling Combinators, responsible for matching sibling
elements with supplied elements.
Example:
<style>
*{
color: blue;
font-size: 10px;
}
</style>
In addition, it improves the ability to change the proportions of things and optimally use the
available space in the container. CSS3 gives various attributes to help with this.
Flexbox has the following properties:
Flex-direction
This parameter specifies how the container should stack the flex-targeted objects. This
property has the following values:
● row: Stacks items in the flex container horizontally from left to right.
● Column: Stacks items in the flex container vertically from top to bottom.
● Row-reverse: Stacks items in the flex container horizontally from right to left.
● Column-reverse: Stacks items in the flex container vertically from bottom to top.
Flex-wrap
This property determines whether or not flex elements should be wrapped. Possible values
include:
● wrap: If necessary, the flex items would be covered.
● nowrap: The default value indicates that the items will not be wrapped.
● Wrap-reverse: This specifies that the elements will be wrapped in reverse order if
necessary.
Flex-flow
This property sets both the flex-direction and the flex-wrap attributes in a single sentence.
● Justify-content: This is used to align the flex components. Possible values include:
● center: This indicates that all flex components are located in the container's center.
● Flex-end: This value ensures the elements are aligned at the container's end.
● Space-around: This value shows the things with space between, before, and around
them.
● Space-between: This value shows items with lines separated by spaces.
Align-items
This is used for flex item alignment.
Align-content
Align the flex lines.
● Block Element
All block elements begin on a new line. They will also take up a whole row or width of space.
The block elements are <div> and <p>.
● Inline Elements
Inline elements do not start a new line.; instead, they appear on the same line as the content
and tags adjacent to them. Inline elements include the tags <a>, <span>, <strong>, and
<img>.
Pseudo-elements
It enables us to create items that do not appear in the document tree, such as
● ::after
● ::before
● ::after
● ::first-letter
● ::first-line
● ::selection
The color will appear just on the first line of the paragraph in the example below.
p: :first-line {
color: #ffOOOO;
font-variant: small-caps;
}
Pseudo-classes
It chooses regular items only when particular conditions are met, for example, when the user
hovers over a link.
● :link
● :visited
● :hover
● :active
● :focus
As an example of a pseudo-class, the color changes when the anchor tag hovers in the
sample below.
It keeps its relative size. Responsive typefaces are an option. Em is going to cascade 1em is
the same as the element's current font size or the browser's default. If you set the font size
to 16px, 1em equals 16px. The default body font size is usually set to 62.5 percent (equal to
10px).
In print, pt (point) is commonly used. This is because 1 point equals 1/72 inch and is a
fixed-size unit.
Percent (percentage) specifies the font size of the body font size. As a result, you must
adjust the body font size to a reasonable level.
42. Do margin-top and margin-bottom affect inline elements?
No, it does not affect the inline parts. Inline items flow with the page's content.
Q43. What are the limitations of CSS?
There are certain CSS limitations you must know: