Practical Two Mobile Demo

Source: Internet
Author: User

Today I saw two very good mobile demo, a record of

I. Text interception

The implementation of the style is like this, such as:

Seems to be a little ugly, a brief explanation, the implementation of the function is to display two lines of text, beyond the partial truncation, with three points instead of a more icon (just use > instead of ~ ~), you can imagine him a very perfect ~ ~

First of all, to talk about ideas, the implementation of the method is more ingenious, mainly using pseudo-elements after and before Content:attr (Attribute-name)

1. Front with: Bofore control the preceding text, the last line of text use: After control

2. Use Felx-box's-webkit-line-clamp to control how many lines of text are displayed

3. Use text-indent and padding-right to leave the ' more ' icon

4. Use font color and background color for a series of font masking

See code comments for details ~

Code implementation:

The HTML code is as follows:

<!--Div should have all the content to open the container size, the Title property value can be appropriately reduced according to the number of rows displayed -<!--I inside is more icons, here is just a simple substitute -<Divclass= "Js-toggle-box lastline-space-ellipsis"title= "The idea is simple: because the label element corresponding to the control is clickable and toggles the control state">    <Divclass= "Expend-box">The idea is simple: because the label element of the control can be clicked and toggle the control state, and the style of the label element can be set freely, we can hide the input element and interact with the label element. <Iclass= "Right-row">></I>    <Div></Div>

The CSS code is as follows:

. Lastline-space-ellipsis{width:200px;position:relative;Max-height:40px;/*Maximum height = line-height * Number of rows displayed*/Line-height:20px;Overflow:Hidden;Word-wrap:Break-word;Word-break:Break-all;/*avoid the occurrence of too long English words*/Color:#fff;/*hides the font inside the container with the same background color*/Border:1px solid Red;}. Lastline-space-ellipsis:after,.lastline-space-ellipsis:before{position:Absolute;Top:0; Left:0;width:100%;content:attr (title);/*use content to get the Title property value*/Color:#333;/*Font Color*/}. Lastline-space-ellipsis:before{Display:Block;Overflow:Hidden;Z-index:1;Max-height:20px;/*(number of rows displayed-1) * Line-height*/Background-color:#fff;/*same as background color*/}. Lastline-space-ellipsis:after{Display:-webkit-box;-webkit-box-orient:Vertical;box-sizing:Border-box;-webkit-line-clamp:2;/*number of rows displayed*/text-indent:-1em;/*Here's the text indent 1 characters to leave a blank section*/Padding-right:1em;}. Expend-box{Max-height:40px;/*number of rows displayed * Line-height*/position:relative;}. Right-row{/*adjust the position and size of icons*/background-size:cover;width:10px;Height:10px;position:Absolute;Bottom:7px; Right:2px;Color:#333;}

If you want to also implement click to display more occurrences of all the text, as long as the control Lastline-space-ellipsis class name is good, but with JS to determine the current state, according to the height of the judge.

Cons: Now I can feel the disadvantage is that the title value is too long, but feel that this can be completely ignored.

This method is referenced from the alloyteam:http://www.alloyteam.com/2015/10/usage-of-content-attibute-of-pseudo-elements/

Two. Implement switch buttons with pure CSS

Implementation results such as:

The HTML code is as follows:

<inputtype= "checkbox"ID= "checkbox"class= "checkbox"/><Divclass= "Checkbox-wrapper">    <label for= "checkbox"class= "Checkbox-label"></label></Div>

The CSS code is as follows:

. Checkbox-wrapper{position:relative;width:80px;Height:32px;Overflow:Hidden;}. CheckBox{Display:None;}. Checkbox-label::before,.checkbox-label::after{position:Absolute;Line-height:32px;Height:32px;width:40px;font-family:Sans-serif;font-size:13px;Color:#fff;Font-weight:Bold;text-align:Center;}. Checkbox-label::before{content:' on '; Left:-40px;background:#45b6af;}. Checkbox-label::after{content:' OFF '; Right:-40px;background:#f3565d;}. Checkbox-label{Display:Block;position:Absolute; Left:0;width:40px;Height:32px;transition:All . 4s ease;cursor:Pointer;background:#dddddd;}. checkbox:checked +. Checkbox-wrapper. Checkbox-label{ Left:40px;}

To tell the truth before always thought to achieve this style of good tall, the results later found .... hehe ~

Strong still have many, need me to accumulate slowly ~ today is this!

Practical Two Mobile Demo

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.