CSS knowledge summary and supplement

Display and hide of elements

The attributes related to the display or hiding of the element mainly include display, visibility and overflow (display and hide the overflow part of the element).

  1. The display attribute is used to establish the type of display box generated by the element during layout. For document types such as HTML, you need to use the display attribute with caution. Because it may violate the display hierarchy already defined in HTML. Here is mainly about another function of this attribute, which can be used to set the display and hiding of elements. display: none; hide the element, display: block; display the element. After using the display property to hide the element, the element no longer occupies the original space .
  2. The visibility attribute is used to specify whether to display the element box generated by an element. visibility: visible; The default value, the element is visible. visibility: hidden; The element is invisible. After the element is hidden using the visibility property, the element still occupies space on the page . This attribute can be used to set the style of the mask layer.
  3. The overflow property specifies what happens when the content overflows the element box . The following is a description of setting different attribute values.
value description
visible Defaults. The content will not be trimmed and will appear outside the element box.
hidden The content will be trimmed, and the rest of the content will be invisible.
scroll The content will be trimmed but the browser will display a scroll bar to view the rest of the content.
auto If the content is trimmed, the browser will display a scroll bar to view the rest of the content.
inherit Specifies that the value of the overflow attribute should be inherited from the parent element.

The scroll value will add horizontal and vertical scroll bars regardless of whether the content of the element overflows. And auto adds the corresponding scroll bar when overflow occurs in this direction .

Single-line text overflow ellipsis display style settings

1. First force the text to be displayed in a line: white-space: nowrap;
2. Hide overflow: hidden;
3. Use ellipsis instead of text-overflow: ellipsis for the text;

<style>
	div{
     
     
		float: left;
		width: 100px;
		height: 40px;
		margin: 200px 100px;
		border: solid 2px;
	}
	div:first-child{
     
     
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
</style>
<body>
	<div>
		<span>我这里写了很多很多字,我要让它在一行内显示不下</span>
	</div>
	<div>
		<span>我这里写了很多很多字,我要让它在一行内显示不下</span>
	</div>
</body>

When the style of the first box is not set:
Insert picture description here

After forcing a line to display:
Insert picture description here

Hide and replace:
Insert picture description here

Multi-line text overflow ellipsis display style

Multi-line text overflow ellipsis display style (has a large compatibility problem, applicable to webkit browser or mobile terminal. It is not recommended to use css to complete it directly.)

  1. The flexible box model displays display:-webkit-box;
  2. Set or retrieve the arrangement of the child elements of the telescopic box object-webkit-box-orient:vertial;
  3. Limit the number of text lines displayed in a block-level element-webkit-line-clamp: 2;
  4. overflow:hidden; text-overflow:ellipsis;

div:first-child{
    
    
		display:-webkit-box;
		-webkit-box-orient:vertical;
		-webkit-line-clamp:2;
		overflow: hidden;
		text-overflow: ellipsis;
	}

The results in chrome and firefox are as follows:
[External link image transfer failed. The origin site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-kg9rLoWi-1594736415150)(https://s1.ax1x.com/2020/07/14/UaJoxe.png )]

Browser private prefix

-moz-: Represents the private attribute of the firebox browser.
-ms-: Represents the private attributes of the IE browser.
-webkit-: Represents the private attributes of safari and chrome.
-o-: Represents the private attributes of the Opera browser.

The knowledge that has been summarized so far

  1. Html commonly used tags and attributes (including Html5)
  2. Selector and its weight in css
  3. Style summary in css
  4. Box model and element display mode
  5. CSS floating (float), height collapse problem
  6. Use of positioning in css
  7. Box shadows, font icons, sprites, rounded borders
  8. 2D conversion and 3D conversion
  9. Transition and animation in css
  10. vertical-align property

Follow-up

HTML5

  • Drag and drop
  • canvas
  • SVG
  • Geolocation
  • Web storage
  • App cache

CSS3

  • Multi-column (you just need to understand it. Many photo websites like to use waterfall effect for typesetting. You can use multi-column to complete.)
  • canvas canvas
  • Multimedia query
  • Layout summary

Dust / 2020/12/22

Guess you like

Origin blog.csdn.net/TKOP_/article/details/111396464