WEB development often uses issues related to text processing. Here we will summarize it in combination with the usage situation. There are also problems with jQuery Object height, which are explained as follows:
1. Text styles in CSS
1, word-break: normal | keep-all | break-all
Set or retrieve how words are processed at container boundaries, and whether to allow line wraps within words;
normal: The default processing method of the browser;
keep-all: When encountering the container boundary, there is no line break in the word;
break-all: When encountering the container boundary, line breaks can be displayed in the word, that is, word breaks and lines breaks;
2, word-wrap: normal | break-word
Sets or retrieves whether to break the line when the content exceeds the boundary of the specified container;
normal: When the content exceeds the container boundary, the content can be pushed or overflowed from the container boundary;
break-word: When the content exceeds the container boundary, the content will be line-breaked at the container boundary;
3,white-space: normal | pre | nowrap | pre-wrap | pre-line
Set or retrieve the processing method of spaces in the object;
normal: The default processing method of the browser;
pre: No blanks are merged, and most contents exceed the container boundaries and do not wrap lines;
Nowrap: Forces all text to be displayed within a line, merge unnecessary blanks until the text ends or encounters a br object;
pre-wrap: Do not merge blank spaces between text, and the content often breaks lines when encountering boundaries;
pre-line: Do not preserve the blank space between text, and when the content is often encountered line breaks at the boundary;
4,text-transform: none | capitalize | uppercase | lowercase | full-width
Retrieve or set the case of text in an object;
none: Keep it as it is, without conversion;
capitalize: convert the first letter of each word into capital;
uppercase: convert all words to capital;
lowercase: Convert all words to lowercase;
full-width: All texts are converted into fullwidth form, and if there is no corresponding fullwidth form, they will remain as it is.
5,text-overflow: clip | ellipsis
Set the processing method of searching text beyond the container boundary;
clip: When the content exceeds the boundary, the excess is cut;
ellipsis: When the content exceeds the boundary, the excess is represented by an ellipsis;
Note: This property needs to be set white-space=nowrap, overflow=hidden to work, and these two properties are placed before text-overflow;
6,text-indent: <length> | <percentage> [ hanging || each-line ]
Retrieve or set the indentation of text in an object;
length: Text indents the specified length value, which can be negative.
percentage: Text indentation specifies the percentage value, which can be negative.
hanging: Defines the first line of indentation acting on the first line of the block container or the first line of each forced line break inside, and the soft line break is not affected;
each-line: reverse all indented lines;
For example: p{text-indent:2em each-line}
7,line-height: normal | <length> | <percentage> | number
Retrieve or set the line height of the object, that is, the distance between the lowest and top of the text characters;
normal: By default, the content is allowed to be opened or the specified container is allowed to be opened;
length: Use the specified value to specify the row height, which can be a negative number;
percentage: Use the specified percentage to specify the row height, which can be a negative number;
number: Use the product factor to specify the row height, which can be a negative number;
For example:
<div style="border:1px solid red; width:500px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
When the text exceeds the container, it will be displayed with a display ellipsis, text... text... abc6666666666666666666666666666666666666666666666666666666666666666666666666666666666666
</div>
2. jQuery gets the height and width of DOM objects
The methods related to height are: height(), outerHeight(), outerHeight(true), width(), outerWidth(), outerWidth(true)
If there is a div object with id=div_id, then find the various widths and heights as follows:
$("#div_id").height() / $("#div_id").width(); // What you get is the height/width of the div itself, (not including padding, margin, border)
$("#div_id").outerHeight() / $("#div_id").outerWidth(); // Contains the height/width of the div itself, the height/width of the padding, and the height/width of the border (not including the height/width of the margin)
$("#div_id").outerHeight(true) / $("#div_id").outerWidth(true); // Contains the height/width of the div itself, as well as the total height/width of padding, border, margin
For example:
<div style="margin:10px 5px; width:600px; padding:10px 20px; height:60px; border:2px solid red; font-family:arial,verdana;">
div info: height : 30px, width : 500px, padding:10px 20px; margin:10px 5px,
</div>
<input type="button" value="TEST" onclick="testHeight();"/>
<script type="text/javascript">
function testHeight(){
var obj = $('#testDiv');
alert('obj height = ' + () + '\nobj outerHeight = ' + () + '\nobj outerHeight(true) = ' + (true));
alert('obj width = ' + () + '\nobj outerWidth = ' + () + '\nobj outerWidth(true) = ' + (true));
}
</script>
1. Text styles in CSS
1, word-break: normal | keep-all | break-all
Set or retrieve how words are processed at container boundaries, and whether to allow line wraps within words;
normal: The default processing method of the browser;
keep-all: When encountering the container boundary, there is no line break in the word;
break-all: When encountering the container boundary, line breaks can be displayed in the word, that is, word breaks and lines breaks;
2, word-wrap: normal | break-word
Sets or retrieves whether to break the line when the content exceeds the boundary of the specified container;
normal: When the content exceeds the container boundary, the content can be pushed or overflowed from the container boundary;
break-word: When the content exceeds the container boundary, the content will be line-breaked at the container boundary;
3,white-space: normal | pre | nowrap | pre-wrap | pre-line
Set or retrieve the processing method of spaces in the object;
normal: The default processing method of the browser;
pre: No blanks are merged, and most contents exceed the container boundaries and do not wrap lines;
Nowrap: Forces all text to be displayed within a line, merge unnecessary blanks until the text ends or encounters a br object;
pre-wrap: Do not merge blank spaces between text, and the content often breaks lines when encountering boundaries;
pre-line: Do not preserve the blank space between text, and when the content is often encountered line breaks at the boundary;
4,text-transform: none | capitalize | uppercase | lowercase | full-width
Retrieve or set the case of text in an object;
none: Keep it as it is, without conversion;
capitalize: convert the first letter of each word into capital;
uppercase: convert all words to capital;
lowercase: Convert all words to lowercase;
full-width: All texts are converted into fullwidth form, and if there is no corresponding fullwidth form, they will remain as it is.
5,text-overflow: clip | ellipsis
Set the processing method of searching text beyond the container boundary;
clip: When the content exceeds the boundary, the excess is cut;
ellipsis: When the content exceeds the boundary, the excess is represented by an ellipsis;
Note: This property needs to be set white-space=nowrap, overflow=hidden to work, and these two properties are placed before text-overflow;
6,text-indent: <length> | <percentage> [ hanging || each-line ]
Retrieve or set the indentation of text in an object;
length: Text indents the specified length value, which can be negative.
percentage: Text indentation specifies the percentage value, which can be negative.
hanging: Defines the first line of indentation acting on the first line of the block container or the first line of each forced line break inside, and the soft line break is not affected;
each-line: reverse all indented lines;
For example: p{text-indent:2em each-line}
7,line-height: normal | <length> | <percentage> | number
Retrieve or set the line height of the object, that is, the distance between the lowest and top of the text characters;
normal: By default, the content is allowed to be opened or the specified container is allowed to be opened;
length: Use the specified value to specify the row height, which can be a negative number;
percentage: Use the specified percentage to specify the row height, which can be a negative number;
number: Use the product factor to specify the row height, which can be a negative number;
For example:
Copy the codeThe code is as follows:
<div style="border:1px solid red; width:500px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
When the text exceeds the container, it will be displayed with a display ellipsis, text... text... abc6666666666666666666666666666666666666666666666666666666666666666666666666666666666666
</div>
2. jQuery gets the height and width of DOM objects
The methods related to height are: height(), outerHeight(), outerHeight(true), width(), outerWidth(), outerWidth(true)
If there is a div object with id=div_id, then find the various widths and heights as follows:
Copy the codeThe code is as follows:
$("#div_id").height() / $("#div_id").width(); // What you get is the height/width of the div itself, (not including padding, margin, border)
$("#div_id").outerHeight() / $("#div_id").outerWidth(); // Contains the height/width of the div itself, the height/width of the padding, and the height/width of the border (not including the height/width of the margin)
$("#div_id").outerHeight(true) / $("#div_id").outerWidth(true); // Contains the height/width of the div itself, as well as the total height/width of padding, border, margin
For example:
Copy the codeThe code is as follows:
<div style="margin:10px 5px; width:600px; padding:10px 20px; height:60px; border:2px solid red; font-family:arial,verdana;">
div info: height : 30px, width : 500px, padding:10px 20px; margin:10px 5px,
</div>
<input type="button" value="TEST" onclick="testHeight();"/>
<script type="text/javascript">
function testHeight(){
var obj = $('#testDiv');
alert('obj height = ' + () + '\nobj outerHeight = ' + () + '\nobj outerHeight(true) = ' + (true));
alert('obj width = ' + () + '\nobj outerWidth = ' + () + '\nobj outerWidth(true) = ' + (true));
}
</script>