CSS interview questions and Answers
Cascading Style Sheets (CSS) is a style sheet language or a mechanism used for enhancing its style by adding colors, fonts, and spacing to your web documents. We have a collection of CSS interview questions that helps in crack your interviews. It is designed to enable the separation of content for improving content accessibility and providing more flexibility in the specification of presentation and reducing complexity in the structural content. The specifications of CSS are maintained and managed by the W3C.
Most Frequently Asked CSS interview questions
Cascading Style Sheets is a style sheet language which is used for describing the presentation of a document written in a markup language like HTML. It is a cornerstone technology of the WWW, alongside HTML and JavaScript. It handles the look and feel part of a webpage.
CSS can be applied to our website's HTML files in various ways. We can use an external css, an internal css, or an inline css.
Inline CSS : It can be applied on directly on html tags. Priority of inline css is greater than inline css.
Internal CSS : It can be applied in web page in top of the page between heading tag. It can be start with
A CSS selectors is used to select HTML elements based on their name,id,class and attribute. It is the part of a CSS rule that actually selects the content we want to style.
Type of CSS selectors
- Universal Selector
For Example
* {
color: green;
} - Element Type Selector
For Example
ul {
list-style: none;
} - ID Selector
#container {
width: 960px;
} - Class Selector
For Example
.box {
padding: 20px;
} - Attribute Selector
For Example
input[type="text"] {
background-color: #444;
}
In between @media screen and (max-width: 600px) {
and }
we can write our CSS. It can directly effect for mobile device.
CSS Box Model is used when talking about design and layout. It is essentially a box that wraps around every HTML element. It consists of margins, borders, padding, and the actual content.
Elements of CSS Box Model
- Content
- Padding
- Border
- Margin
@media
can be used in media query to apply different styles for different media types or devices. It can be used to check many things, such as width and height of the view port.
CSS2 : It was released in 1998. In CSS2 designers could only use web safe fonts for being 100% sure to use fonts that would always display the same on every system. CSS2 had "simple selectors". In CSS2, the developers or designers had difficulty because the standard was not equipped with automatically breaking of the text so that it fits within a box.
CSS3 : It was released in 1999. In CSS3 designers can use special fonts like those available in Google Fonts and Typecast. CSS3 calls the components as "a sequence of simple selectors". In CSS3 has the capability to split text sections into multiple columns so that it can be read as a newspaper.
It is used to select elements with a specified attribute. It is possible to add css that have specific attributes or attribute values.
It is used to select elements with an attribute value containing a specified word.
a[href="#"] {
background-color: yellow;
}
CSS3 is a new version of CSS that have various benefits from technical features and properties. From better maintenance, loading speed, and layout design properties CSS3 is much more versatile than CSS. Designers can use all these property in a simpler manner.
Tweening is a familiar term for those used to animating in Flash. With CSS animation we can use the latter, pose to pose.
p {
animation-duration: 2s;
animation-name: slidein;
}
@keyframes slidein {
from {
margin-left: 95%;
width: 200%;
}
to {
margin-left: 0%;
width: 100%;
}
}
Latest Version : CSS version 4 was released in March 2017.
Advantages
- Saves time
- Pages load quickly
- Easy to maintain
- Superior styles in HTML
- Compatible with multiple devices
Development History
CSS was proposed by Hakon Wium Lie in October 1994. The first released was made public in December 1996.