如何在跨浏览器兼容的第二行中获得省略号 [React]
How to get ellipsis in second line that is crossbrowser compatible [React]
Click for image
我需要这样。 Clip 仅适用于 chrome。我需要这个用于反应项目。仅使用 css 会有所帮助。
您可以使用Trunk8插件(jQuery)来达到这个效果。它具有浏览器兼容性并且也具有响应能力。
您可以这样使用一种解决方案。
像这样。
/* styles for '...' */
.block-with-text {
/* hide text if it more than N lines */
overflow: hidden;
/* for set '...' in absolute position */
position: relative;
/* use this value to count block height */
line-height: 1.2em;
/* max-height = line-height (1.2) * lines max number (3) */
max-height: 3.6em;
/* fix problem when last visible word doesn't adjoin right side */
text-align: justify;
/* place for '...' */
margin-right: -1em;
padding-right: 1em;
}
/* create the ... */
.block-with-text:before {
/* points in the end */
content: '...';
/* absolute position */
position: absolute;
/* set position to right bottom corner of block */
right: 0;
bottom: 0;
}
/* hide ... if we have text, which is less than or equal to max lines */
.block-with-text:after {
/* points in the end */
content: '';
/* absolute position */
position: absolute;
/* set position to right bottom corner of text */
right: 0;
/* set width and height */
width: 1em;
height: 1em;
margin-top: 0.2em;
/* bg color = bg color under block */
background: white;
}
参考。 link - http://hackingui.com/front-end/a-pure-css-solution-for-multiline-text-truncation/
Click for image
我需要这样。 Clip 仅适用于 chrome。我需要这个用于反应项目。仅使用 css 会有所帮助。
您可以使用Trunk8插件(jQuery)来达到这个效果。它具有浏览器兼容性并且也具有响应能力。
您可以这样使用一种解决方案。
像这样。
/* styles for '...' */
.block-with-text {
/* hide text if it more than N lines */
overflow: hidden;
/* for set '...' in absolute position */
position: relative;
/* use this value to count block height */
line-height: 1.2em;
/* max-height = line-height (1.2) * lines max number (3) */
max-height: 3.6em;
/* fix problem when last visible word doesn't adjoin right side */
text-align: justify;
/* place for '...' */
margin-right: -1em;
padding-right: 1em;
}
/* create the ... */
.block-with-text:before {
/* points in the end */
content: '...';
/* absolute position */
position: absolute;
/* set position to right bottom corner of block */
right: 0;
bottom: 0;
}
/* hide ... if we have text, which is less than or equal to max lines */
.block-with-text:after {
/* points in the end */
content: '';
/* absolute position */
position: absolute;
/* set position to right bottom corner of text */
right: 0;
/* set width and height */
width: 1em;
height: 1em;
margin-top: 0.2em;
/* bg color = bg color under block */
background: white;
}
参考。 link - http://hackingui.com/front-end/a-pure-css-solution-for-multiline-text-truncation/