How do I wrap words at a defined position? [duplicate] - html

This question already has answers here:
How to word wrap text in HTML?
(20 answers)
Closed 3 years ago.
I want to wrap words at a defined position.
In Germany, we have sometimes very long words which are composed out of several nouns. I would like to wrap such long composed words at the boundaries of two words if the word is too long and a word wrap is necessary.
For example, we have the word "Unternehmenskunden" which means corporate (Unternehmens) customer (Kunde). I want that this word would break into "Unternehmens" and "kunde". I tried to wrap the two word parts into there own spans but that did not affect the wrap. The CSS classes word-break and word-wrap doesn't have a value for that.
I tried to wrap a space into its own span and remove it with display: none or shrink it with width: 0;
Is there maybe some kind of hidden character which marks a word break but doesn't
Here is a fiddle which could help illustrate what I try to achieve and what I tried so far: https://jsfiddle.net/nbk9ptay/3/

Thanks to #GrumpyCrouton I found a solution for an arbitrary word wrap.
The solution is to use either a soft hyphen (­) if you want to have a hypen in case of a word wrap How to word wrap text in HTML?:
<div style="width: 120px; border: 1px solid red;">Unternehmens­kunde</div>
<div style="width: 200px; border: 1px solid red;">Unternehmens­kunde</div>
Or to use html entity ​ if you don't want a hypen in case of a word wrap How to word wrap text in HTML?:
<div style="width: 120px; border: 1px solid red">Unternehmens​kunde</div>
<div style="width: 200px; border: 1px solid red">Unternehmens​kunde</div>

Use inline-block spans to wrap sub words.
Then you have a delineation you can control. It's up to you how the separation gets styled. Using inline-block, just by the nature of HTML you will get a complete long word when there's enough width, and a split double-line when broken down.
Also, if it helps, here's a post touching on truncation and scaling font-size.
Codepen
.container {
width: 250px;
}
.subword {
display: inline-block;
}
<div style="width: 800px; border: 1px solid black; margin-bottom: 4em;">
<span class="subword">Unternehmens</span><span class="subword">kunde</span>
</div>
<div style="width: 100px; border: 1px solid black;">
<span class="subword">Unternehmens</span><span class="subword">kunde</span>
</div>

Related

FIXED: HTML format paragraph so its pleasing to the eye

I have a html code where I want to store long paragrapsh of information. The only issue is that in my code I don't want hundreds of sentences on just one line. Id rather see it formatted like:
<div id ="sidebar">
<div><b> Things to take into account: </b></div>
<div>
<p>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
</p>
</div>
</div>
However, when I do it this way and run my website the words run outside the container they are in
Can you help give me a way to display it this way in the code while keeping the words inside it's container?
my css:
#sidebar {
"background-color: #eee;
height: 200px;
width:350px;
float:left;
margin-top: 30px;
margin-left: 30px;
border: 1px solid black;
border-radius: 5px;
display: block;
}
UPDATE: changed X to words and fixed it. Weird but ok lol
Your issue is that xxxxxxxxxxxxxx is considered one word and by default the browser won't break this word.
adding
word-wrap:break-word;
Will fix this, but I would guess once you use actual text in there it will break more naturally since it won't be a single word of so many characters.
fiddle: http://jsfiddle.net/ktbypbtt/
Here is another fiddle without the word-wrap, but with actual text.
http://jsfiddle.net/ktbypbtt/1/
Notice how it breaks itself since the browser will naturally wrap the word after each word if it hits the end of the div, but needs to be specifically told to break words.
Just add a <br> tag where ever you want the text to go to the next line
<div id ="sidebar">
<div><b> Things to take into ACCOUNT: </b></div>
<div>
<p>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
</p>
</div>
</div>
Helpful? Let me know :)
add some css.
#sidebar{
display: block;
}
or add a class to your wrapping div and do the same thing with setting display as block
edited
You could cut off the overflow:
#sidebar{
overflow: hidden;
}
http://jsfiddle.net/5deyo1tb/

css make <br> element appear at start of new line

The 'invisible' <br> element always appears at the end of the line you wrote it for.
With styling, you can give it a visual appearance. I want to make it appear at the start of the next line instead, so the visual appearance would indicate the start of that line.
abc<br style="border:1px solid"/>abc
would give
abc|
abc
but i want
abc
|abc
if you want to show tag before or after every paragraph for any purpose. you should use pseudo selectors.. like :before and :after
<html>
<p>hello1</p>
<p>hello2</p>
<p>hello3</p>
<p>hello4</p>
<css>
p:after{
content: "";
border-right: 1px solid red;
margin-left: 5px;
}
“indicate a selected character, including line breaks”
Line breaks are non-printed characters. Most software (e.g. MS Word) uses a replacement character to display line breaks. You should do the same to highlight any line-breaks.
Or you can wrap the line break into another tag which then is styled accordingly:
HTML
abc<mark class="line-break-wrapper"><br></mark>abc
CSS
.line-break-wrapper {
background: #990;
padding: 0 .25em;
}
you can simply use
abc<br/><span style="border-left:1px solid ">abc</span>
to achieve this
But i don't think this is the good method
I think giving border is more better see this http://jsfiddle.net/46jyt4d7/
<p>abc<br/></p><p class="a">abc</p>
.a{
border-left:1px solid;
}
You can't actually style a <br /> tag to become visible. But to achieve what you want to achieve all you have to do is put another element that creates the line like this:
abc<br /><span></span>abc
And with the styling:
span {
border: solid 1px black;
margin-right: 2px;
}
Here is an example fiddle:
http://jsfiddle.net/tmqk0ppe/

Text not aligning with large font-size

I'm building a periodic table in HTMl/CSS and I cant get the text inside the large .element-symbol to align left with the .atomic-weight, .element-name and .atomic-symbol without an arbitrary text-indent. I guess this is just to do with the width of the letters, but is there a way of having the first letter in .element-symbol start hard left? i.e against the red border
Markup:
<div class="cell">
<div class="atomic-number"><span>2</span></div>
<div class="element-symbol">
<abbr>He</abbr>
</div>
<div class="element-name"><span>Helium</span></div>
<div class="atomic-weight">4.002602</div>
</div>
CSS: (red borders to show alignment issue)
* {
padding: 0;
margin: 0;
box-sizing: border-box;
line-height: 1;
}
.cell {
border: 1px solid black;
font-family: sans-serif;
width: 280px;
height: 280px;
margin: 20px auto;
padding:10px;
background-color: #4DBCE9;
}
.element-symbol {
font-size: 173px;
border: 1px solid red;
font-weight: 400;
/*text-indent: -12px; dont want to use this*/
}
.atomic-number, .atomic-weight, .element-name {
font-size: 25px;
border: 1px solid red;
}
Example in codepen
Each glyph in a font, sits within a bounding box. The glyph is usually not hard up against any of the edges of that box, and each glyph (or letter) will have differing amounts of space around it to help space it naturally when it is combined with other glyphs to form words.
Have a look at http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html to get a feel for some of the intricacies of type design.
I'm not aware of any text or font properties in CSS that can eliminate that space, and in any case that space will be different for each glyph, and different between the same glyphs in different fonts.
You're right - it's simply because of the size of the letters.
In most fonts, each character has a small amount of whitespace to either side of it, to separate it from adjacent letters. Without this space the letters would just run in to each other. At large font sizes, this space gets to be fairly significant, and produces the effect you're seeing. The only other option would be to find (or create) a font that doesn't have that space (or perhaps only has trailing space after each letter and no leading space).

Border, that overlaps near cells

That's how cell selection looks in MS Excel:
Is it possible to have the similar border in regular HTML <table> so that the border overlaps near cells (if you look closely you'll see that the border is extended for about 1px each side over near cells)?
Yes, to a certain extent. I've only tested in Chrome, but this works: http://jsfiddle.net/q4Lcc/
td {
width: 120px;
height: 50px;
border: 1px solid gray;
}
td#test_td {
border: 3px solid black;
}
I don't know of a way to do it purely with tables, but one approach would be to use another div or text input that gets absolutely positioned over the table of data.
Here's a live example: http://jsbin.com/edehoc
I personally like this approach because it lets you use a familiar form element that has an expected style when it gains focus.

How to underline blank space in CSS?

I am making a report that should be printable from the web browser. At the bottom is a field for the recipient to fill in, so it's underlined. I would rather not have to eyeball a certain number of underscores, and they seem to have gaps in them anyway.
What I am going for is...
Amount Paid: $ ___________________
So far, I have managed this CSS:
<div>
<p style="border-bottom: 1px solid black;">
Amount Paid: $
</p>
</div>
That draws a line to the edge of the parent div - which I want. However, it also draws a line under "Amount Paid: $", which I don't want. Every combination of ps, spans, etc. I've thought of has failed:
If I put the text in a span that nukes the border, it doesn't matter, I suppose since it's still part of the p and the border is still drawn.
I can add the underline to a span after text, but that doesn't work. It only seems to want to underline the blank space when the border style is in the p element.
Likewise, if I replace the p with a span it doesn't get the memo that it should extend the border all the way:
<p>
<span>Amount Paid: $ </span>
<span style="border-bottom: 1px solid black;"> </span>
</p>
Does nothing. The line is never drawn. If I add a letter to the second span, it's drawn under that, but no more. And if I replace the p with anything else like divs or spans, it doesn't seem to work either...
Any ideas? Thanks in advance.
Change the display (CSS) of the second span to inline-block and set its width (CSS).
upd:
Or try something like:
<p style="width: 200px; display: table;">
<span style="display: table-cell; width: 100px;">Amount Paid: $ </span>
<span style="display: table-cell; border-bottom: 1px solid black;"></span>
</p>
This works in the year 2014.
Amount Paid: $ <span style="text-decoration: underline; white-space: pre;"> </span>
Another one solution using disply: flex; and flex-grow:
.container {
width: 200px;
}
.row {
display: flex;
}
.underline {
flex-grow: 1;
border-bottom: 1px solid black;
margin-left: 5px;
}
<div class='container'>
<div class='row'>
<div class='label'>Count:</div>
<div class='underline'></div>
</div>
<div class='row'>
<div class='label'>Amount Paid:</div>
<div class='underline'></div>
</div>
</div>
If you don't mind manually specifying the width of the line, you can do this:
<span style="border-bottom: 1px solid black; padding-left: 50px"> </span>
If you're not worried about support for older browsers (IE6 generation), there's always using the min-width property to get a default amount of blank space that expands as necessary.
<p>
<span>Amount Paid: $ </span>
<span style="border-bottom: 1px solid black; min-width: 100px;"> </span>
</p>
Note that for IE7, you'd have to add an overflow: visible to the min-width element so that it treats min-width properly, as opposed to it's default (buggy) behavior of treating it as width.
Or just add non-breaking space characters like so:
<h1>STRONG   </h1>
css:
h1 {
text-decoration: underline;
}
add as many as you like to increase width of your underline.