1. Difference between Block & Inline?
1. inline(only accepts left/right padding/margin, no top/bottom will take effect), block accepts all
2. inline accepts vertical-align, blocks doesn’t
3. block’s default width is 100%
4. inline doesn’t accept width/height, block accepts all
5. when a inline element is floated, it accepts width and height
Credit: http://www.impressivewebs.com/difference-block-inline-css/
2. Different Ways to Hide an Element?
// More common
display: none;
visibility: hidden;
opacity: 0;
// Tricky
position: absolute;
z-index: 1000;
margin: -100px; ???
left:-9999px;
position:relative ???
left:-9999px;
position:absolute; ???
transform: translateX(-9999px);
Credit: https://kitt.hodsden.org/blog/2013/07/5_3_ways_hide_element_css
Follow-up: What's the difference between visibility: none
and opacity: 0
?
Click event. Element with visibility: none
doesn't respond to click-event. But opacity: 0
element does.
Source: Personal experience
3. Selectors
What are those selectors??
s
Source: https://code.tutsplus.com/tutorials/the-30-css-selectors-you-must-memorize--net-16048
4. Centering
for centering, the ultimate way is to use flex. However, to support some old browsers, we need some classical approaches.
1. Vertically align elements?
- for inline elements
vertical-align: center;
- for block elements:
- use flex if you can
.parent { display: flex } .children { align-self: center; } /* or */ .parent { display: flex; flex-direction: column; justify-content: center; }
- use negative margin if know the height
.parent { position: relative; } /* to work with children's absolute position */ .children { position: absolute; height: 200px; margin-top: -100px; top: 50%; }
- use transform is dont know the height
.parent { position: relative; } .children { position: relative; top: 50%; transform: translateY(-50%); }
- use flex if you can
2. Horizontally align Elements?
- for inline elements:
.item-parent { text-align: center; }
- for block-level elements
- use flex, supports multiple items as well:
.parent { display: flex; justify-content: center; }
- otherwise use margin: 0
.children { margin: 0 auto; }
- use flex, supports multiple items as well:
3. Follow-up: How about both vertical and horizontal align?
- Use flex:
.parent { display: flex; justify-content: center; /* this will center all items on the main axis */ } .children { align-self: center; }
- Old fashion ways, the trick of 0
/* https://www.smashingmagazine.com/2013/08/absolute-horizontal-vertical-centering-css/ */ .children { margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0; }
- use translate
.parent { position: relative; } .children { position: absolute; }
Source: https://css-tricks.com/centering-css-complete-guide/
More about vertical using flex: https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/
5. What is responsive design? How to use it?
Media Query:
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
6. Text Space
How to display space in HTML text?
Note: there is a ; at the bottom
How to display the text
?
// Text we want to display exactly:
...
The text 'nbsp;' means 'space'
...
Answer:
The text 'a ' means 'space' // use & to escape ;
Source: Presonal experience
Reference:
- How to write out HTML entity name ( , <, >, etc)? http://stackoverflow.com/questions/17427713/how-to-write-out-html-entity-name-nbsp-lt-gt-etc
- Does opacity:0 have exactly the same effect as visibility:hidden? http://stackoverflow.com/questions/272360/does-opacity0-have-exactly-the-same-effect-as-visibilityhidden?answertab=votes#tab-top