NO. 213 Day: 12 HTML and CSS must know the key points of the problem

Source: Internet
Author: User

12 HTML and CSS must know the key points of the problem

These 12 questions, basically is the HTML and the CSS Foundation key difficulty, also must be clear the basic question, in which the localization absolute localization and relative localization exactly relative what locates? This is still easy to overlook, floating is also a big pit, there are many details.

These 12 points of knowledge I personally think, below we will look at these 12 points of knowledge.

1. How do I make an indefinite wide DIV, centered vertically?

Using Flex

    • Only need to set in parent box: Display:flex; Justify-content:center;align-items:center;

Using CSS3 Transform

    • Parent Box settings:position:relative
    • Div settings:transform: translate(-50%,-50%);position: absolute;top: 50%;left: 50%;

Using the Display:table-cell method

    • Parent box settings: display:table-cell; text-align:center;vertical-align:middle ;
    • Div settings: display:inline-block;vertical-align:middle ;
Function of several properties of 2.position

Common four attribute values for position: relative,absolute,fixed,static. It is generally used with the "left", "Top", "right" and "bottom" properties.

    • **static: Default location. * * In general, we do not need to declare it in particular, but sometimes we encounter inheritance, we do not want to comment to the element inherited by the property affect itself, so you can use Position:static to cancel the inheritance, that is, to restore the default value of the element positioning. An element that is set to static, which is always in the position given by the page stream (the static element ignores any top, bottom, left, or right declarations). Generally not used.
    • **relative: relative positioning. * * Relative positioning is a position relative to the default position of the element, and the value of its offset top,right,bottom,left is offset by its original position, regardless of other elements. Note that the relative moved element still occupies space in its original position.
    • **absolute: Absolute positioning. * * Element set to Absolute, if its parent container has the Position property set, and position's property value is absolute or relative, then the parent container will be offset. If the parent container does not have the Position property set, the offset is based on body. Note the element that sets the absolute property does not occupy a position in the standard stream.
    • **fixed: fixed positioning. * * position is set to the fixed element and can be positioned relative to the specified coordinates of the browser window. The elements remain in that position, regardless of whether the window is scrolled or not. It is always based on the body. Note the element that sets the fixed property does not occupy a position in the standard stream.
3. Floating and clear floating 3.1 floating related knowledge

Value of the Float property:

    • Left: the element floats to the left.
    • Right: the element floats to the left.
    • None: Default value. The element does not float and appears in its position in the text.

Characteristics of float:

    • The floating element is detached from the normal document stream, but the floating element affects not only itself, it affects the surrounding element alignment.
    • Whether an element is an inline element or a block-level element, if a float is set, the floating element generates a block-level box that can set its width and height, so float is often used to create a menu with horizontal columns that can be sized and arranged horizontally.

The display of floating elements will have different rules in different situations:

    • When floating elements float, their margin does not exceed the padding of the containing block. PS: You can set the margin property if you want the element to be exceeded
    • If two elements one floats to the left and one floats to the right, the marginright of the left floating element will not be adjacent to the marginleft of the right floating element.
    • If there are multiple floating elements, the floating elements are sorted sequentially without overlapping.
    • If there are multiple floating elements, the subsequent element height does not exceed the preceding element and does not exceed the containing block.
    • Floating elements are not higher than non-floating elements if there are non-floating elements and floating elements that are present at the same time, and non-floating elements are in front.
    • Floating elements are aligned as far as possible to the top, left or right

Overlap Issues

    • Inline elements overlap with floating elements, their borders, backgrounds, and content appear above the floating elements
    • When a block-level element overlaps with a floating element, the border and background appear below the floating element, and the content is displayed above the floating element

Clear property Clear property: Ensures that there are no floating elements on the left or right side of the current element. Clear only works on the layout of the element itself. Value: Left, right, both

3.2 Parent Element Height collapse problem

Why to clear floating, parent element height collapse resolves parent element height collapse problem: A block-level element if no height is set, its height is stretched by a child element. When a pair element is floating, the child element is detached from the standard document flow, meaning that no content in the parent element can open its height so that the height of the parent element is ignored, which is called a height collapse.

3.3 How to clear floating

Method 1: Define the height principle for the parent div: Define a fixed height (height) for the parent Div to solve the problem that the parent div cannot get the height. Pros: Code Concise Disadvantage: The height is fixed dead, is suitable for the content fixed unchanged module. (Not recommended)

Method Two: The use of empty elements, such as the <div class="clear"></div> (.clear{clear:both}) principle: Add a pair of empty div tags, using the CSS Clear:both property to clear the float, so that the parent div can get the height. Pros: Browser Support Good disadvantage: more than a lot of empty div tags, if the number of floating modules on the page, there will be a lot of vacant div, so the feeling is not too satisfactory. (Not recommended)

Method Three: Let the parent Div also float together to do this can initially solve the current floating problem. But it also lets the parent float, and it creates a new floating problem. Not recommended for use

Method Four: The parent div definition display:table principle: Force the DIV attribute into a table advantage: No drawbacks: New unknown issues arise. (Not recommended)

Method Five: Parent element set Overflow:hidden, auto; principle: The key of this method is to trigger the BFC. There is also a need to trigger haslayout (zoom:1) benefits in IE6: code introduction, no structural and semantic problems disadvantage: Unable to display elements that need to overflow (also not recommended)

Method Six: Parent div definition Pseudo-class: After and zoom

1 . Clearfix:after {2    content:'. '; 3     Display:block; 4     height:0; 5     Clear:both; 6     Visibility: hidden; 7 }8{zoom:1;}

Principle: IE8 above and non-IE browser support :after , the principle and method 2 a bit similar, zoom (ie turn to have attributes) can solve the ie6,ie7 floating problem advantages: The structure and semantics are completely correct, the code is moderate, repeatable utilization (recommended definition of public class) Cons: Code is not very concise (highly recommended)

How to be refined by the benefit

1{2    content:"\200b"3    display:block 4     height:05    clear:both;  6  }7{ *zoom:1;} take care of ie6,ie7, you can.
4.BFC Related knowledge

definition : BFC (block formatting context) literal translation is "chunk-level formatting context". It is a separate rendering area that only block-level box participates in, which specifies how the internal block-level box is laid out and irrelevant to the outside of the area.

BFC Layout Rules BFC is a separate, isolated container on the page, and the child elements inside the container do not affect the outer elements. The reverse is true.

    • BFC the vertical margin of this element will overlap, the distance from the vertical direction is determined by the margin maximum value
    • The BFC area does not overlap with the floating box ( 清除浮动原理 ).
    • When calculating the height of the BFC, floating elements are also involved in the calculation.

Which elements will generate BFC

    • root element
    • The Float property is not none
    • Position for absolute or fixed
    • Display for Inline-block, Table-cell, Table-caption, Flex, Inline-flex
    • The overflow is not visible
What is 5.box-sizing?

Set the CSS box model to the standard model or IE model. The width of the standard model includes only content , the two IE models include border and the padding box-sizing attribute can be one of three values:

    • Content-box, default value, only calculates the width of the content, border and padding do not count into width
    • Padding-box,padding Calculation in width
    • Border-box,border and padding are calculated into the width
The difference between 6.px,em,rem

px pixels (Pixel). Absolute units. Pixel px is 相对于显示器屏幕分辨率 the case, is a virtual length unit, is the digital image length unit of the computer system, if PX to be converted to physical length, you need to specify the accuracy DPI. em is a unit of relative length 相对于当前对象内文本的字体尺寸 . If the font size of the current inline text is not artificially set, the default font size is relative to the browser. It inherits the font size of the parent element, so it is not a fixed value. REM is a new relative unit of CSS3 (root em, root em) that uses REM to set the font size for the element, still relative size, but 相对的只是 HTML 根元素 .

What are the ways 7.CSS is introduced? What is the difference between link and @import?

There are four kinds: inline (the style attribute on the element), inline (style label), outer chain, import (@import) The difference between link and @import:

    • linkis the XHTML tag, in addition to loading CSS, you can also define other transactions such as RSS @import , which belongs to CSS category 只能加载CSS .
    • linkWhen referencing CSS, in 页面载入时同时加载 ; @import需要页面网页完全载入以后加载 .
    • linkis the XHTML tag, which 无兼容问题 @import is presented in CSS2.1 低版本的浏览器不支持 .
    • linkSupport for using JavaScript to control the DOM 改变样式 @import is not supported.
8. The difference between a streaming layout and a responsive layout

flow layouts use non-fixed pixels to define the content of the Web page 也就是百分比布局 , and the width of the box is set as a percentage to scale according to the width of the screen, without the restriction of fixed pixels, and the content is padded to both sides.

Responsive Development uses media query (media queries) in CSS3 to specify a page layout for a width range by querying the width of screen.

    • Ultra small screen (mobile device) 768px or less
    • Small screen Device 768px-992px
    • Medium Screen 992px-1200px
    • Widescreen Device 1200px or more

Since responsive development is cumbersome, it is common to use a third-party response framework, such as Bootstrap, to complete part of the work and, of course, to write the response yourself.

Difference

9. Progressive enhancement and graceful demotion

The key difference is the content they focus on, and the differences in the work processes that result from this difference

    • Graceful Downgrade build the full functionality from the beginning and then be compatible with the low-version browser.
    • Progressive Enhancement builds pages for low-version browsers, guaranteeing the most basic functionality, and then improving and appending features such as effects and interactivity for advanced browsers to achieve a better user experience.

Difference:

    • Graceful demotion begins with a complex situation and attempts to reduce the supply of user experience
    • Progressive enhancement begins with a very basic, workable version and is continuously expanded to suit the needs of the future environment
    • Downgrading (functional decay) means looking back, while progressive enhancement means looking forward while keeping its roots in a safe zone
Several ways and differences of 10.CSS hidden elements

Display:none

    • The element disappears completely on the page, and the space that the element originally occupies is occupied by other elements, which means that it causes the browser to reflow and redraw.
    • Does not trigger its Click event

Visibility:hidden

    • And display:none the difference is that 元素在页面消失后,其占据的空间依旧会保留着 , so it 只会导致浏览器重绘 does not reflow.
    • Cannot trigger its Click event
    • For scenarios where elements are hidden and do not want the page layout to change

opacity:0

    • When you set the transparency of an element to 0, the element is hidden in the eyes of our users, which is a way of hiding elements.
    • And visibility:hidden one thing in common is that the element is hidden and still occupies space, but we all know that after setting the transparency to 0, the element is just invisible, it still exists in the page.
    • Can trigger a click event

Set the Height,width box model property to 0

    • Simply put, the elements,,, and other elements of the margin border padding height width element Box model properties set to 0 , if the element has child elements or content, it should also be set overflow:hidden to hide its child elements, which is a kind of artifice.
    • If the element is set to an attribute other than 0, it is clear that the element is still visible on the page, and the click event of the triggering element is completely border,padding. If all properties are set to 0, it is clear that this element is the equivalent of disappearing, which means that the Click event cannot be triggered.
    • This approach is neither practical nor likely to have some problems. But usually we use some of the page effect may be done in this way, such as jquery slideup animation, it is set elements of the Overflow:hidden, and then through the timer, constantly set the element height,margin-top, The Margin-bottom,border-top,border-bottom,padding-top,padding-bottom is 0, which achieves the slideup effect.

Other Brain hole methods

    • Set elements position and left,top,bottom,right, etc. to move elements out of the screen
    • Set the position and Z-index of the element and set the Z-index to a small negative number as little as possible
11. Briefly describe the difference between src and href

hrefis the link between the location of the network resource, the establishment and the current element (anchor point), or the current document (link), for hyperlinks.

srcis the location of the external resource, which is embedded in the document where the current label is located, and the src resources it points to are downloaded and applied to the document, such as JS scripts, IMG images, and frame elements. When the browser resolves to the element, it pauses the download and processing of other resources until the resource is loaded, compiled, executed, and so on, like pictures and frames, similar to embedding the resource in the current tag. This is why the JS script is placed at the bottom instead of the head.

12. What are the inline elements? What are block-level elements? What are the empty (void) elements?

This question interview occasionally asked when a bit of a crazy force ~ ~ ~ usually don't care about ....

Inline elements: A, B, span, IMG, input, strong, select, Label, EM, Button, textarea
Block-level elements: Div, UL, Li, DL, DT, DD, p, H1-h6, blockquote
Empty element: A HTML element that has no content, for example: BR, meta, HR, LINK, input, img






NO. 213 Day: 12 HTML and CSS must know the key points of the problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.