Use overflow instead of left to intercept the specified length string

Source: Internet
Author: User

In order to prevent the article headers from exceeding the container (td,div) width and displaying multiple lines, we usually work with the caption to display it on one line, usually in two ways: one way is to set the container's overflow property with CSS on the client Another method is to intercept the header string with the left function on the server side. Both methods are usually able to achieve our goal:

<style type= "Text/css" >
div{
width:200px;
Overflow:hidden;
}
</style>
<div> gently insert a radio button/check box in the page </div>
<div><% =left ("Insert radio buttons/checkboxes in the page lightly", one)%></font></div>

Today we're going to compare their pros and cons:

1. Different treatment locations

One is located on the client and one is on the server side. Can be handled at the client as far as possible not in the server-side processing, reduce the burden on the server, this principle everyone knows.

2. Dealing with the different objects

CSS is to set the container properties, left is to handle the title string, which is more reasonable? Before answering this question, let us ask: Why should the title length be handled? For the "let the title length does not exceed the container length" Can! CSS is to set the container properties, when the length of the title is beyond the length of the container to handle, and left is to handle each title, the length of the title is controlled in the length of our test to reach the N range [Left (title,n)], there is a knife-cut suspicion. It can be seen that the former is more reasonable.

3. Simplicity of HTML processing

This is the most convincing reason for me to use CSS. Sometimes, for some reason, we add HTML code to some headings, such as: <font color= "#FF0000" > Gently insert radio buttons/checkboxes in the page </font> we want the result to be that the title doesn't appear as two lines. But make sure it's still red! This left can not do, to achieve the effect we first have to remove the HTML, and then the remaining string to intercept, and then add HTML, very troublesome, and CSS completely ignore HTML, really do "only string processing", very convenient, such as:

<style type= "Text/css" >
div{
width:200px;
Overflow:hidden;
}
</style>
<div><font color= "#FF0000" > Gently insert radio buttons/check boxes in the page </font></div>
<div><% =left ("<font color=" "#FF0000" > Gently insert radio buttons/check boxes </font> "in the page"%></font>< /div>

Using left not only can not achieve the effect, and sometimes cause the page display error! By contrast, you know which one you have in mind.

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.