CSS, HTML: How can i make the div or <p> width dynamic as the text line increses/decreses - ruby-on-rails

There is a line of text inside a <div></div> or inside <p></p>.
The text length changes when clicking some links.
If the text length decreases the div or p will decrease.
If the text length increases the div or p will increase.
How can i do this ?
The problem is the div or p width looks fixed and the length of text is 30% of that div or p.
The div or p has a background color. So whole div or p is colored. But what i'm trying to do is to color the portion of background of div or p, the portion that contains text of line.

Wrap the text in a <span></span> and style that instead?

It sounds to me like you're struggling with the difference between an inline and block level element, but forget about that a second and let's get to what you want. Without seeing your code... an easy way to fix that is to make your block level elements p and div float to the left. From what you've said, this should be close to what you want (check the jsFiddle).
div {
float:left;
background:red;
}
Ok, so what is a block level element? A div and p are block level elements. As per the Mozilla Developer Network "Their most significant characteristic is that they typically are formatted with a line break before and after the element (thereby creating a stand-alone block of content)." This is why with default styling it expands to the entire line. This sounds like exactly what you didn't want. Where as a span will shrink down to fit just the content that it contains.
If you want a more complicated "real-world" example, I've thrown together this jsFiddle that might help you down your path.

Ah, you're doing Rails! Ok, here's your real answer. Just check to see if the flash[:notice] exists before displaying it to the screen.
<% if flash[:notice] %>
<p class="customnotice"><%= flash[:notice] %></p>
<% end %>

Related

Multi line text in LitRenderer in vaadin grid

Does anyone maybe have an example of a LitRenderer with multiple lines of potentially wrapped text in a vaadin grid please?
All the examples in the documentation just have a bold line and a small single line of text underneath. I have tried to create a bold line and then a multi line text paragraph underneath it, but I cant get the grid to render this properly.
The text should ideally change width responsively with flex grow, wrap accordlingly and potentially truncate if no space is available.
Edit:
I think I got this working as follows:
grid.addColumn(TemplateRenderer.<SubProductTypeOption>of("""
<vaadin-vertical-layout style="line-height: var(--lumo-line-height-m); height: 175px; cursor: pointer;">
<span> [[item.name]] </span>
<span style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color); white-space:normal;">[[item.description]]</span>
</vaadin-vertical-layout>
""")
.withProperty("name", SubProductTypeOption::getName)
.withProperty("description", SubProductTypeOption::getDescription)
).setFlexGrow(1);
Seems to work so far...

Blogger - Aligning whole template to right of screen?

I recently saw a site that had the blog aligned to the right hand side of the screen (so any extra space was on the left of the main column. Unfortunately, it was Wordpress and all I can seem to find when I search for aligning blog templates to the right is stuff about right aligning pictures.
I suppose could add padding (trial and error) on that side to bump it across, but that wouldn't display properly on other computers.
My sidebar is 325 wide and the main column is 625, leaving ~240 on the left.
I'm just using the Simple template as a base. I don't know that it's worth the time that it would take to do it from scratch. Or that I have the skills :. The Blogger help areas are practically abandoned.
Is this possible? Or are there any other ideas that could work across different computers/resolutions?
Whatever element you want to align to the right , enclose it in a div and make it float right ? Wouldn't this work?
...
<div style="float:right">
<div class='sidebar'>...</div>
<div class='main-column'>...</div>
</div>
...

Flex 3 htmlText calculates height way wrong and strips span tags

I currently have two problems with Flex 3 htmlText.
1) When I am setting my text's htmlText:
myText.htmlText = <html text stored in my mysql database>
It calculates the height way wrong. In most cases, a ton of padding (or whitespace) is added above and below the text. I am not sure what happens, but it calculates the textHeight way higher than normally.
2) If I put <span> tags in my html, it automatically strips them out (instead of just ignoring them). I am using the span tags to be able to dynamically find certain pieces of my text. For instance:
<span class="salutation">Dear,</span> <span class="tag">[First Name]</span>
is inserted in my htmlText, and I use them to parse out the salutation and tag of my variable data.
Does anyone know of any solutions for these two issues? Any alternative ideas on how to parse out pieces of html? Any way to improve htmlText? How to correctly measure textHeight and/or remove padding?
Thanks!
Basically, the tag needs width and height explicitly set in order for flex to calculate the height correctly on these elements. Also, you can use:
invalidateSize();
validateSize();
To force size validation to occur, which will at times help!
Add these two lines before you use any XML:
XML.ignoreWhitespace = true;
XML.prettyPrinting = false;
This should take care of the added lines above and below your text.
ignoreWhitespace strips leading and trailing whitespace from your text nodes.
prettyPrinting, when set to true, formats the XML output, indenting nodes and adding newline characters to make it more readable - but also affecting text output. For example, when you have a structure like this:
<p><span class="test">This is a test.</span></p>
Flash will output:
<p>
<span class="test">
This is a test.
</span>
</p>
This leads to your TextField displaying:
(newline)
(newline)
This is a test.
(newline)
(newline)
The Flash plugin will remove any HTML tags, if the styleSheet property isn't properly set. So in your case, it will remove the <span> tags and add its own <P> and <FONT> tags instead, according to any font information you've specified using defaultTextFormat or setTextFormat (try tracing htmlText after you've set it - you'll see). You have to set the TextField's styleSheet property to an actual StyleSheet, if you want to keep your own tags.
Parsing out the information you need by using HTML tags is a valid way to go. I usually use numbered placeholders like {0} and string.replace () to insert dynamic values.

Qt4.6: QTextDocument <HR> tag prints only very thin, almost invisible hair lines

When printing a QTextDocument with doc->print() I almost cannot see the horizontal rules inserted by <hr>. When printing to PDF these are clearly visible. But when printed to a printer these lines are very very thin lines, almost invisible on the paper.
How do I fix this? I currently helped myself by inserting an <img> with a black pixel but this is very cumbersome as I have to exactly figure out the proper pixel width by trial and error.
<hr> tag supports the width attribute, which can be specified as an absolute or relative (%) value. E.g.:
<hr width=3>

How do i get sIFR 3 to align right and use the full width

Well like i stated in the title, i cant get sifr to align right and use the full width of the containing h3 tag. Aligning text to the right works well, but i want the text to be on 1 or 2 lines instead of 3 and how it looks the text should perectly fit on 1 or 2 lines :/.
Link: http://hendriks.adena.nl/preview/html/?p=kerst
Anyone got any thoughts on this problem?
Niels
The issue is that the width of the sifr elements is determined based on the width of the original text content that is in the a tags within the h3 tags (check your page with javascript off to see the difference in width).
So one simple solution should be to give these a and/or h3 an explicit width - my guess is that sifr will use that with. (Maybe you can also use 100%, I'm not sure about that)

Resources