How to fix div height and cut down extra text from it - html

I am using bootstrap cards to display my content. I want every bootstrap card height to be equal. Everything else is fine but issue comes when I display discription as it is of variable length.
Sometimes it occupies two lines and sometimes three.
I want to fix description div height and cut down extra text from it.
Note Card are being displayed through loop
This is what I tried:
$('address').height(30);
var txt= $('address').text();
if(txt.length > 155)
$('address ').text(txt.substring(0,50) + '.....');
This is working perfectly fine for one card. But when there are multiple cards running in loop, same description text appears along every card due to this line: var txt= $('address').text();
How to make it work separately for each card?

Your current select is targetting all the address element. You need to filter out the elements based on if condition. You can use jquery filter function for this.
Then iterate over those objects and modify the text.
var $addressToChange= $('address').filter(function(){
return $(this).text().length > 155;
});
$addressToChange.each(function(){
$(this).text($(this).text()..substring(0,50) + '.....')
})

I am thankful to #Milind Anantwar for his answer as his answer gave me a clue. I little modify his answer and achieved my desired result by using this piece of code:
$('address').height(40);
$('address').each(function(i){
if ($(this).text().length > 40)
{
$(this).text($(this).text().substring(0,50) + '.....')
}
});

Related

Additional whitespace appearing at bottom of auto-resizing textarea element

I have a textarea which I have added an onChange listener to in order to update the field's height whenever a new line is required (or if a line is no longer required). The issue I'm having is that, when the cursor approaches the end of the (current) final line of the textarea, additional whitespace is created which does not actually "exist" (i.e. it consists of no characters - sort of an "empty line").
My description probably isn't sufficient to explain the issue I'm having, but the same effect can be observed in the JSFiddle below (I'm using an identical implementation for my own form):
https://jsfiddle.net/d9fqaest/
As you can see, when the end of the first line is reached, a new line is added without issue:
But when the end of the second line (or any following lines) is reached, a new "empty" line is added too soon (with any following lines requiring fewer and fewer characters before adding the erroneous line):
I suspect the issue lies somewhere in the way the row count is calculated:
handleChange(e) {
const oldRows = e.target.rows;
e.target.rows = 1;
const newRows = ~~(e.target.scrollHeight/lineHeight);
if (newRows === oldRows) {
e.target.rows = newRows;
}
this.setState({
value: e.target.value,
rows: newRows
});
}
I've tried a few different flows of logic here, including simply setting the element's height to its scrollHeight, but I haven't been able to produce the desired behaviour (the aforementioned approach somewhat worked, but I was unable to figure out how to remove lines as text was deleted). I'm aware of several external libraries which would solve this problem, but I'd like to avoid using those if at all possible.
Thanks!
So it turns out all that was needed was overflow-y: hidden on the textarea to prevent the scrollbar from being included in the height calculation. Simple fix!

Bootstrap grid layout: force specific cells to always be in the same row

Using Bootstrap Grid Layout to show various forms. Cells are assigned width (e.g. 3 of 12 columns) and all of it is configurable. The problem is Label and Field width are supposed to be configured separately. E.g. labelA is width 2, fieldA is width 4, labelB is width 2, fieldB is width 4. This way user will see "2 column" layout: labelA-fieldA-labelB-fieldB.
However there's a problem if user decides to set label and field width to some other value, for example to span all row. User sets label B width to 4 and field B width to 8 expecting it to take whole row. However, in this case he'll get labelA-fieldA-labelB-[empty space for 2 columns] on the first row and fieldB on the second row. Obviously the intended solution would to have labelA-fieldA-[empty space for 6 columns], then labelB-fieldB on the next row. Again, this is all configurable so I need solution for all cases.
A perfect solution would be to have some way to force those cells (label and field) to be non-breakable. Can't find the way to do that.
Another way would be to create a container component with width=label.width+field.width. But then I'll have problems with setting label and field width inside of those containers because I can only set label/field width relative to direct parent and I need to set width relative to the parent's parent. I've heard there are ways to change number of columns in component on render and it'd work if I set number of columns to label.width+field.width. But as far as I understand it's a dirty solution.
The code is in React and this is what's generated for each label and field. InpComp may be any component, doesn't matter in the end. labelWidth and fieldWidth are set by configuration.
const labelWidth = this.getLabelWidthFromConfiguration();
const fieldWidth = this.getFieldWidthFromConfiguration();
return (
<div className={'component-container'}>
<div className={'col-md-${labelWidth}'}><b>{this.field.attributes.label}</b></div>
<div className={'col-md-${fieldWidth}'}>
<InpComp />
</div>
</div>);
What can I do to this code so that those label and field always end up on the same row?
what about an if-statement? ;)
you can do something like this:
if (lableWidth + fieldWidth !== 6) {
fieldWidth = 12 - lableWitdh;
}
This solution only works for one case (LA+FA = LB+FB = 6). You could set a condition for each case by your own using if/else or switch-case.
Like Troyer said, we're not here to show ideas or do your work, we are here to fix code problems. Next time you should try to solve your Problem by your own until you get in stuck and then provide your Code.

How to avoid css overlapping?

I'm using FullCalendar with the resource library that you can see in my JSFIDDLE
How you can see the problem of the resource (first column, second column) is the overlapping. Seems infact if the resource have a long name go to overlap the near column and this is bad for me. What I want is cut the resource name if exceeds a certan lenght, anyway, the label must not overlap the next cell.
Issue image:
Final result
Something like: First col | Second col
You seem to want to hide the overflow.
Your calendar's table header elements are overflowing into each other.
CSS:
#calendar tr th div.col-label{
overflow-x: hidden;
}
This will make the overflowing text not draw instead of drawing on the next cells.
EDIT: Fixed this making the events disappear
EDIT 2: Fixed messing up the Date Label
Another way to solve your problem is by setting a min-width property on your columns in order to ensure that each one will have enough space available to store it's data. And then use width:100%; property on your labels. Maybe use some padding as well in order to make it look nice. Let me know if this helped :)

Limit what is seen inside a div

I have 3 div's images are below. They pull the entire column and display it. I need it to only display say 255 characters. And then I have a Read More link where they can click to go to the full article.
You see how the box on the left has the Read More I would like all 3 boxes to display part of the content and then have the read more link. The only reason the first box works is because the content is super small to begin with.
The site is HTML5 with CSS and some CSS3.
The information is being pulled in from Entity/LINQ I assume I will need to limit the content there?
Here is one example:
db.TPGForums.Where(m => m.boardID == 11)
.SelectMany(m => m.TPGForumTopics)
.SelectMany(m => m.TPGForumPosts)
.OrderByDescending(p => p.dateCreated)
.FirstOrDefault();
Everything is wrapped in a <div class="news-block">content</div>
How can I achieve this?
EDIT:
Another issue that may cause problems is the content being pulled in is HTML Decoded. So only pulling part of it may cause some HTML Errors on the page with the possibility of some things not being closed properly. So I think my only option now is to limit it through the size of the div and hide the over flow.
You would need to limit the content where it is being pulled in. Alternatively you could set a max height with overflow hidden and use some sort of a gradient to keep the bottom edge from looking janky. Or you could use text-overflow: ellipsis.

Tab index on floating inputs

I have a page with a for layout where one half of the page is dynamic width an the other is fixed. This is achieved by floating the fixed width side to the right. It all displays fine but because the fixed width markup comes before the dynamic width markup the tab ordering gets thrown off.
See here: http://jsfiddle.net/BaMqG/
How can i overcome this without resorting to putting tabindex properties on the inputs?
You can use jQuery to dynamically set the tabindexes with a loop and counter variable. Check it out. http://jsfiddle.net/BaMqG/22/
$(document).ready(function() {
var i = 1;
$('.wrapper').each(function(){
$(this).children('.dynamic').children('input').each(function(){
$(this).attr("tabindex",i);
i++;
});
$(this).children('.fixed').children('input').each(function(){
$(this).attr("tabindex",i);
i++;
});
});
});​
The initial value for i can be set to whatever tabindex number you want to start from.
I have managed to get the same looking form with no tab index to work by using tables.
See here: http://jsfiddle.net/ymSGM/
I would still be interested if it can be done any other way.