HTML, CSS Flashcards

1
Q

What is doctype? Why do u need it?

A

Doctype is an instruction to the browser to inform about the version of html document and how browser should render it.

It ensures how element should be displayed on the page by most of the browser. And it also makes browser’s life easier. otherwise, browser will guess and will go to quirks mode. Moreover, doctype is required to validate markup.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are data- attributes good for?

A

Before JavaScript frameworks became popular, front end developers used data- attributes to store extra data within the DOM itself, without other hacks such as non-standard attributes, extra properties on the DOM. It is intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

These days, using data- attributes is not encouraged. One reason is that users can modify the data attribute easily by using inspect element in the browser. The data model is better stored within JavaScript itself and stay updated with the DOM via data binding possibly through a library or a framework.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can u generate public key in html?

A

html has a keygen element that facilitate generation of key and submission via a form.
keygen has to be used inside a form.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can u change direction of html text?

A
use bdo (bidirectional override) element of html.
dir='rtl' - right to left. 
dir='ltr' - left to right.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can u highlight text in html?

A

use mark element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are optional closing tag? and why would u use it?

A

p, li, td, tr, th, html, body, etc. you don’t have to provide end tag. Whenever browser hits a new tag it automatically ends the previous tag. However, you have to be careful to escape it.
reason : you can save some byte and reduce bytes needs to be downloaded in a html file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between span and div?

A

div is a block element and span is inline element.
It is illegal to put block element inside inline element. div can have a p tag and a p tag can have a span. However, span can’t have a div or p tag inside.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When should you use section, div or article?

A

section - group of content inside is related to a single theme, and should appear as an entry in an outline of the page. It’s a chunk of related content, like a subsection of a long article, a major part of the page (eg the news section on the homepage), or a page in a webapp’s tabbed interface. A section normally has a heading (title) and maybe a footer too.

article - represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.

div -on the other hand, does not convey any meaning, aside from any found in its class, lang and title attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does float do?

A

float pushes an element to the sides of a page with text wrapped around it. you can create entire page or a smaller area by using float. if size of a floated element changes, text around it will re-flow to accommodate the changes. You can have float left, right, none or inherit.

if you set, ‘float: left;’ for an image, it will move to the left until the margin, padding or border of another block-level element is reached. The normal flow will wrap around on the right side.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can you clear sides of a floating element?

A

If you clear a slide of an element, floating elements will not be accepted on that side. With ‘clear’ set to ‘left’, an element will be moved below any floating element on the left side. clear is used to stop wrap of an element around a floating element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which one would you prefer among px, em % or pt and why?

A
  • px gives fine grained control and maintains alignment because 1 px or multiple of 1 px is guaranteed to look sharp. px is not cascade, this means if parent font-size is 20px and child 16px. child would be 16px.
  • em maintains relative size. you can have responsive fonts. em is the width of the letter ‘m’ in the selected typeface. However, this concept is tricky. 1em is equal to the current font-size of the element or the browser default. if u sent font-size to 16px then 1em = 16px. The common practice is to set default body font-size to 62.5% (equal to 10px). em is cascade
  • % sets font-size relative to the font size of the body. Hence, you have to set font-size of the body to a reasonable size. this is easy to use and does cascade. for example, if parent font-size is 20px and child font-size is 50%. child would be 10px.
  • pt(points) are traditionally used in print. 1pt = 1/72 inch and it is fixed-size unit.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How absolute, relative, fixed and static position differ?

A
  • absolute, place an element exactly where you want to place it. absolute position is actually set relative to the element’s parent. if no parent available then relatively place to the page itself.
  • relative, is position an element relative to itself (from where the element would be placed, if u don’t apply relative positioning). for example, if u set position relative to an element and set top: 10px, it will move 10px down from where it would be normally.
  • fixed, element is positioned relative to viewport or the browser window itself. viewport doesn’t changed if u scroll and hence fixed element will stay right in the same position.
  • static, element will be positioned based on the normal flow of the document. usually, u will use position static to remove other position might be applied to an element.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the differences between visibility hidden and display none?

A

display: none removes the element from the normal layout flow and allow other elements to fill in. visibility: hidden tag is rendered, it takes space in the normal flow but doesn’t show it.

if u want to say it smartly, display: none causes DOM reflow where is visibility: hidden doesn’t.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the differences between inline, block and inline-block?

A

inline, elements do not break the flow. think of span it fits in the line. Important points about inline elements, margin/ padding will push other elements horizontally not vertically. Moreover, inline elements ignores height and width.

block, breaks the flow and dont sits inline. they are usually container like div, section, ul and also text p, h1, etc.

inline-block, will be similar to inline and will go with the flow of the page. Only differences is this this will take height and width.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the properties related to box model?

A

Technically, height, width, padding and border are part of box model and margin is related to it.

Everything in a web page is a box where you can control size, position, background, etc. Each box/ content area is optionally surrounded by padding, border and margin. When you set height and width of an element, you set content height and width.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Does overflow: hidden create a new block formatting context?

A

Yes, overflow property deals with the content if content size exceeds the allocated size for the content. You can make extra content visible, hidden, scroll or auto (viewport default behavior)

17
Q

What are the some pseudo classes?

A

pseudo class tells you specific state of an element. allow to style element dynamically. The most popular one is :hover. Besides i have used :visited, :focus, :nth-child, nth-of-type, :link, etc.

pseudo classes is better if you don’t want to mess up with javaScript however, pseudo-classes is slow to process and apply rules.

18
Q

What are the some pseudo elements?

A

pseudo elements helps you to add cosmetics contents. pseudo elements generates content where as pseudo class deals with state of the element. for example, you can style :first-letter of every paragraph. similarly, :first-line and fancy stuff with :before, :after

19
Q

What is specificity? How do u calculate specificity?

A

is a process of determining which css rule will be applied to an element. it actually determines which rules will take precedence.

inline style usually wins then ID then class value (or pseudo-class or attribute selector), universal selector (*) has no specificity.

20
Q

What do you know about transition?

A

transition allows to add an effect while changing from one style to another. You can set the which property you want to transition, duration, how you want to transit (linear, ease, ease-in, ease-out, cubic-bezier) and delay when transition will start. you can transition more than one property by comma separation

21
Q

What are the reasons to use preprocessor?

A

you write css in high level with some special syntax (declaring variable, nested syntax, mathematical operations, etc.) and that is compiled to css. Preprocessor helps you to speed up develop, maintain, ensure best practices and also confirms concatenation, compression, etc.

22
Q

What kind of things must you be wary of when designing or developing for multilingual sites?

A
  • Use lang attribute in your HTML.
  • Directing users to their native language - Allow a user to change his country/language easily without hassle.
  • Text in images is not a scalable approach - Placing text in an image is still a popular way to get good-looking, non-system fonts to display on any computer. However, to translate image text, each string of text will need to have a separate image created for each language. Anything more than a handful of replacements like this can quickly get out of control.
  • Restrictive words/sentence length - Some content can be longer when written in another language. Be wary of layout or overflow issues in the design. It’s best to avoid designing where the amount of text would make or break a design. Character counts come into play with things like headlines, labels, and buttons. They are less of an issue with free-flowing text such as body text or comments.
  • Be mindful of how colors are perceived - Colors are perceived differently across languages and cultures. The design should use color appropriately.
  • Formatting dates and currencies - Calendar dates are sometimes presented in different ways. Eg. “May 31, 2012” in the U.S. vs. “31 May 2012” in parts of Europe.
  • Do not concatenate translated strings - Do not do anything like “The date today is “ + date. It will break in languages with different word order. Use a template string with parameters substitution for each language instead. For example, look at the following two sentences in English and Chinese respectively: I will travel on {% date %} and {% date %} 我会出发. Note that the position of the variable is different due to grammar rules of the language.
  • Language reading direction - In English, we read from left-to-right, top-to-bottom, in traditional Japanese, text is read up-to-down, right-to-left.
23
Q

Consider HTML5 as an open web platform. What are the building blocks of HTML5?

A
  • Semantics - Allowing you to describe more precisely what your content is.
  • Connectivity - Allowing you to communicate with the server in new and innovative ways.
  • Offline and storage - Allowing webpages to store data on the client-side locally and operate offline more efficiently.
  • Multimedia - Making video and audio first-class citizens in the Open Web.
  • 2D/3D graphics and effects - Allowing a much more diverse range of presentation options.
  • Performance and integration - Providing greater speed optimization and better usage of computer hardware.
  • Device access - Allowing for the usage of various input and output devices.
  • Styling - Letting authors write more sophisticated themes.
24
Q

Describe the difference between a cookie, sessionStorage and localStorage.

A
Cookie(1) LocalStorage(2) SessionStorage(3)
<b>Initiator:</b> 
     1.Client or server. Server can use Set-Cookie header	 
     2.Client	
     3.Client
<b>Expiry:</b> 
     1.Manually set	
     2.Forever	
     3.On tab close
<b>Persistent across browser sessions:</b> 
     1.Depends on whether expiration is set	
     2.Yes	
     3.No
<b>Sent to server with every HTTP request:</b>
     1.Cookies are automatically being sent via Cookie header
     2.No	
     3.No
<b>Capacity (per domain):</b> 
     1. 4kb	
     2. 5MB	
     3. 5MB
<b>Accessibility:</b> 
    1.Any window	
    2.Any window	
    3.Same tab
25
Q

Does margin-top or margin-bottom/ padding-top or padding-bottom has effect on inline element?

A

NO

26
Q

Does padding-left or padding-right or margin-left or margin-right has effect on inline element?

A

YES