score:-1
score:1
You can do that, but not so easily like one text line.
There are several ways to do that.
Check it out:
Pure CSS multiline text with ellipsis
-webkit-line-clamp: xx(lines to show);
and
score:1
For webkit-browsers you can use this CSS:
.block-with-text {
border: 1px solid #000;
padding: 5px;
display: block;
display: -webkit-box;
max-width: 400px;
-webkit-line-clamp: 4; /* max line number */
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
<div class="block-with-text">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
score:2
Crossbrowser solution through pseudoelements. Requires text-align: justify;
and setting the same background-color
for pseudoelement as background of parent:
/* styles for ellipsis '…' */
.block-with-text {
/* hide text when we have more than N lines */
overflow: hidden;
/* for setting absolutely positioned ellisis '…' */
position: relative;
line-height: 1.2em;
/* max-height = line-height × line number, 1.2 × 3 = 3.6 */
max-height: 3.6em;
text-align: justify;
/* place for ellipsis '…' */
padding-right: 1em;
}
/* creating ellipsis … */
.block-with-text:before {
content: "…";
position: absolute;
/* ellipsis move to right bottom corner */
right: 0;
bottom: 0;
}
/* hide ellipsis if we have text not more that maximum line numbers */
.block-with-text:after {
content: "";
position: absolute;
/* move to the right bottom corner */
right: 0;
/* setting width и height */
width: 1em;
height: 1em;
margin-top: 0.2em;
/* hide ellipsis using white background */
background: white;
}
<div class="block-with-text">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
Source: stackoverflow.com
Related Query
- Div container with text on the left side and overflow image on the right
- Align text with previous text after a line break
- Trying to break the text in 2 line with React
- How to replace word in text with Hashtag in React?
- Is it possible to break word in space in AG Grid Wrap text
- How to select all text in input with Reactjs, when it focused?
- How to select element text with react+enzyme
- React JSX, how to render text with a single quote? Example <p>I've</p>
- React Material UI Label Overlaps with Text
- A control must be associated with a text label
- Updating a React Input text field with the value on onBlur event
- Test setting text value with React and Enzyme
- React slow with multiple controlled text inputs
- Query a button with specific text
- Center a text in the screen with react native
- Write to a text or JSON file in react with node
- Simulating text entry with reactJs TestUtils
- React-Select, Multi Select and Text Overflow
- Using css modules with Extract Text Plugin
- React Create a Horizontal Divider with Text In between
- Error: Unable to find an element with the text when I try a test with Jest in React
- How to limit the text filed length with input type number in React JS and prevent entry of E,e, -, + etc
- How to enable Ctrl + Z when you change an input text dynamically with React?
- Material-ui: write text in exactly 2 lines with ellipsis
- How to format text and embed a video with Quill?
- React - restrict to numeric/alphanumeric/hexadecimal symbols in text field with max length
- How select part of text in a Textfield on onFocus event with material-UI in React?
- How to create button with text under icon by reactjs?
- Adjacent JSX elements must be wrapped in an enclosing tag with line break tag
- React/Momentjs date formatting with line break
More Query from same tag
- How to detect window size in Next.js SSR using react hook?
- How can I update a nested state with arrays in React?
- Redux Error: A case reducer on a non-draftable value must not return undefined
- problem in updating an index of state in reactjs
- An error thrown by a React component, being caught in an unrelated promise's catch block
- Running pixel stream in react component?
- how to add type annotation for mock function
- How to set icons on the right side of an Appbar using material UI
- Uncaught TypeError: this.state.data.map is not a function
- change reference of this keyword after importing file
- currencyDisplay must be either "code", "symbol", or "name" - Safari issue
- While Loading my site on the client's web page there occurs css property clash issues
- Link not active in next.js even when I am on the page
- Cannot read Property of undeifned Cards material ui
- First time working with an API in React - Openweather API - TypeError: Cannot read property 'temp' of undefined
- Transpiling next.js server code
- Use of React router v6 history/Navigate in redux
- Dynamic components: Calling element by ref
- Map API data with this.state in ReactJS
- React custom checkbox input component not rerendering
- Clear form after using addDoc in react
- NGINX Setup to Match Proxy Middleware Configuration
- How to modify data after waiting for it to be fetched react axios
- "Uncaught SyntaxError: Unexpected token l in JSON at position 0", but still works, why?
- react js webpack bundling error for jsx files
- Run sequental graphql queries using Apollo Client
- Why does setState cause too many re-rendering when pushing a new element to an array state?
- Using react-scroll (Link) while using react-boostrap Nav.Link?
- Styling react-select with CSS modules works on Sandbox but not on local machine
- Antd Tree : I want to disable checking childs by default