Increase the width of paragraph by adding white-space padding

I am attempting to control the number of characters in a paragraph to a specific limit. If the text is shorter, I want to add whitespace padding, and if it exceeds the limit, I will truncate it with an ellipsis. All containers containing paragraphs should have the same size.

Utilizing a responsive grid means my container will adjust dynamically based on the paragraph length. Although I tried integrating pre-wrap into the p element, the divs remain unresponsive. It seems like the extra whitespace is being ignored.

p
{
white-space: pre-wrap;
}

Here is a JSFiddle that demonstrates my issue: http://jsfiddle.net/RFBza/4/

Answer №1

Oh my goodness. However, if for any reason you want to replicate it exactly like that, consider inserting a series of   codes separated by spaces. For example, where there were originally five spaces, now insert      . Nevertheless, this is still not a good idea.

Answer №2

white-space is not intended to extend divs or add padding to fill in space. Its purpose is simply to control how text wraps within the containing div. If you want the text to overflow the div, you can achieve this using white-space

http://www.w3schools.com/cssref/pr_text_white-space.asp

If you are striving for uniformity among all divs, a quick solution is to set a minimum height for the containing divs.

http://jsfiddle.net/RFBza/6/

However, keep in mind that as the wording changes dynamically, the actual height may vary (especially on responsive designs). There are various techniques available to achieve this effect, but most involve JQuery, HTML changes, or even PHP (to limit string length and display ellipsis if necessary).

You could also apply this to the p selector in your CSS, but exercise caution as it will affect every paragraph. Consider using more specific selectors for targeted styling.

p
{
   white-space:pre-wrap;
   min-height:192px
}

http://jsfiddle.net/RFBza/7/

Another approach is to use PHP to determine the character limit and display an ellipsis if exceeded. For instance, limiting to 50 characters:

echo mb_strimwidth("Your paragraph goes here", 0, 50, '...');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using AJAX and Perl to dynamically update HTML content

Currently, I am attempting to dynamically update a div on my website using ajax and perl. The current implementation I have sort of works but needs improvement. HTML: <h2 id="cpu">--</h2> JS/ajax call: $.ajax({ type: 'GET&apos ...

Text does not wrap correctly when placed between elements with the property white-space: nowrap

When applying the white-space: nowrap property to all children of an element, an issue arises in Webkit (and blink) where white space doesn't break between elements as expected: View example on jsFiddle .pairs { width: 180px; overflow: hidde ...

Establish a table containing rows derived from an object

I am currently dealing with a challenge in creating a table that contains an array of nested objects. The array I have follows this schema: array = [ { id: 'Column1', rows: { row1: 'A', row2 ...

What is the best way to ensure a font-face is displayed consistently across different browsers?

Having some issues with Helvetica Neue - when I set the font-size to 15px it looks fine, but if it goes above 16px, it starts to look a bit strange. Check out how it should look here: And here is the problem I am facing: Any suggestions on how to fix th ...

Vertical Orientation in HTML

Would appreciate some assistance on creating a vertical text with HTML similar to the example in the linked screenshot. It needs to be straightforward and vertically oriented. Check out the screenshot for reference ...

How can you correctly include a link to a plain text sitemap file in an HTML document?

Could this code effectively inform Google to index my sitemap (or acknowledge its presence)? <link rel="sitemap" href="./sitemap.txt" type="text/plain" title="Sitemap" /> Google's guidelines allow plain t ...

Mysterious attributes of angular 6's <table mat-table> tag

This particular question regarding the angular material table has not been duplicated in any other discussions. Other similar questions pertain to angular versions 2-5, not version 6 The issue I am encountering is as follows: Can't bind to 'dat ...

What is the best way to adjust the width of a column to perfectly fit its contents when using IE9 compatibility mode?

Within my HTML code, I've included the table displayed below. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <style type="text/css"> table, td, tr, th{ border:1px; } .onepx{ ...

Is there a way to modify the variable in order to switch the font of the heading every second using CSS and JavaScript?

I'm trying to create a heading that changes fonts every second, but I'm having trouble changing the variable to set it to another font. Check out my code here. Despite watching tutorials, everything seemed too confusing. var root = document.q ...

Turn off the extra space inserted by DataTables

Help needed with centering table header text. <table class="table table-bordered table-hover center-all" id="dataTable"> <thead> <tr> <th scope="col" style="text-align: center">Nam ...

What is the method for extracting the initial H1 tag from a URL?

As I get ready for an upcoming interview, I am reviewing questions from a website. One question stumping me is: how can I write a function to extract the value of the first H1 element from a specified URL? The possible scenarios include: An H1 elemen ...

Toggle between fading in and out by clicking the button using a div

I'm having trouble getting my fade menu div to work properly. I want it to fade in when the menu button is clicked and fade out when the menu button is clicked again. Despite following various tutorials and researching other questions, I can't se ...

Is it possible to dynamically convert percentages to pixels in real-time?

I am working on a project with a fluid percentage-based horizontal grid and I want to have the same vertical margins as my horizontal ones. This is the code I have: .block_12_24{ display:inline-block; vertical-align:top; width:48%; margin-right:2%; margi ...

- Convert text style and include bullet points: • Alter

Is there a way to convert the script from a Mail_Object to HTML in order to properly format lines 3 and 4 into bullet points, as well as change the font on line 5? I have no knowledge of HTML. The code below functions but does not apply any formatting or ...

How to conceal the bottom bar in JQuery Colorbox iframe

I have implemented colorbox to showcase an Iframe of the registration page on my website. Here is how it looks... https://i.sstatic.net/z1RGK.png Upon closer inspection, I noticed a white bar at the bottom of the Iframe where the close 'X' butt ...

Differentiate various collections of shapes

My application has a specific workflow: 1) Next to the name of Patient X, there is a "Check In" button. Once clicked, this action is recorded on the server side. 2) Upon clicking the "Check In" button, a dropdown menu appears with various locations for t ...

When a button is clicked, I would like to direct the user to a webpage using a parameter retrieved from a separate function

Currently, I am facing difficulties with my course project. My program involves tracking user clicks on a series of images, with the variable 'n' representing the number of clicks, capped at a maximum of 3. I aim to redirect the user to a differe ...

Is there a way to update a PHP include file without needing to refresh the page?

I've been learning as I go, so some of my questions may seem basic or beyond my current knowledge level. However, I find that peer explanations, examples, and advice are the most effective way for me to learn. Thank you in advance for your help. Usin ...

What is the method for aligning a glyph vertically?

Can anyone help with aligning the glyph vertically to the text? Currently, it seems more like it's attached to the bottom. Here is an example: <a href="#">Zoom</a> a { font-family: 'Open Sans', sans-serif; font-weight: ...

This issue with ng-include not functioning properly in Chrome but working fine in Firefox

My code is running only in Firefox and not working in Chrome. HTML Code <div ng-controller="myController1"> Select View: <select ng-model="employeeview"> <option value="1.html">1</option> < ...