I have a block of text in paragraph element with the following css:
p {
text-align: justify;
text-align-last: left;
margin: 0;
padding: 0;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
}
Here is the text:
DRG is Boston-based organization dedicated to supporting the unique needs of the defense and intelligence community. Founded in 2011 on the belief that innovative, high-quality solutions could be delivered quickly and affordably. With over a decade of field experience DRG is uniquely positioned to help customers succeed in today’s operational and fiscal environment.
The result looks like this:
What I dislike is the spacing between 'today's operational and fiscal' line. I want to move the 'a' down a line and the 'help' down a line to spread out the word density.
The problem:
When add a <br /> before the word 'a' and the word 'help' I get the following:
Now the left edge of the text block is not flush.
The Question:
How can I force the words to be on the next lines without adjusting the size of the text block?
Browsers are crap at fine-tuned typography. Full justification makes text HARDER to read for users and, in general, should be avoided.
Different browsers and operating systems will render the text slightly differently and there is no guarantee that the text will wrap where you expect it anyway. You may end up fixing it for yourself and braking it elsewhere. Trying to micro-manage this is a fruitless exercise.
See: http://nedbatchelder.com/blog/200806/bad_web_typography_full_justify.html
I found a solution based on a comment by Jongware.
I used (word at end of one line)<nobr> (word at start of next line).
It stuck the two words together and both words were added to the second line, looks great.
A better solution would be to use multiple elements. Take the places you want line breaks and separate those sections into individual sections.
Once they are separate sections, they can be displayed in a column to look like they are all one element.
Text unaltered:
p {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
}
.text {
width: 400px;
text-align: justify;
text-align-last: left;
}
<p class="text">DRG is Boston-based organization dedicated to supporting the unique needs of the defense and intelligence community. Founded in 2011 on the belief that innovative, high-quality solutions could be delivered quickly and affordably. With over a decade of field experience DRG is uniquely positioned to help customers succeed in today’s operational and fiscal environment.</p>
Using line breaks:
p {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
}
.text {
width: 400px;
text-align: justify;
text-align-last: left;
}
<p class="text">DRG is Boston-based organization dedicated to supporting the unique needs of the defense and intelligence community. Founded in 2011 on the belief that innovative, high-quality solutions could be delivered quickly and affordably. With over <br/>a decade of field experience DRG is uniquely positioned to <br/>help customers succeed in today’s operational and fiscal environment.</p>
Using separate sections:
p {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
}
.text {
width: 400px;
text-align: justify;
text-align-last: justify; /* not really the last line */
}
/* The last line of the last p, should use left alignment */
.text.last {
text-align-last: left;
}
<p class="text">DRG is Boston-based organization dedicated to supporting the unique needs of the defense and intelligence community. Founded in 2011 on the belief that innovative, high-quality solutions could be delivered quickly and affordably. With over</p><p class="text">a decade of field experience DRG is uniquely positioned to </p><p class="text last">help customers succeed in today’s operational and fiscal environment.
Related
I need help centering the second line of my paragraph. I don't know what to do because I'm new to HTML and CSS but I did try to create two "p" and give the second one a "text-align: center" however it was too far from the first line and I feel like there must be a better way to achieve what I want.
This is the HTML sheet:
.p_music2 {
color: #000;
font-family: "PT Sans Narrow", sans-serif;
font-size: 2rem;
margin: 2.5rem 6rem;
}
<p class="p_music2">
Upgrade today to get your favorite music, movies, TV shows, and
podcasts. You can join youTunes and stream — or download and play
offline — over 70 million songs, ad‑free.
</p>
Wrap the text that you want to center in a <span></span> and then set that span to display: block; text-align: center;.
display: block; will cause that block of code to break out of the flow of the rest of the sentences, and allow you to center it.
.p_music2 {
color: #fff;
font-family: "PT Sans Narrow", sans-serif;
font-size: 2rem;
margin: 2.5rem 6rem;
background: #000;
}
.p_music2 span {
display: block;
text-align: center;
}
<p class="p_music2">Upgrade today to get your favorite music, movies, TV shows, and <span>podcasts. You can join youTunes and stream — or download and play</span> offline — over 70 million songs, ad‑free.</p>
I would recommend to create a parent <div> element class with the property text-align:center and inside that element add your <p> HTML elements with the corresponding text. Then set the styles properties of those two elements separately one for the parent music2 and another for all your <p> elements so you can have control over the margins of the <p> elements.
html{background:blue; color: #fff;font-family: "PT Sans Narrow", sans-serif;font-size: 2rem;padding:50px;}
.music2 {
text-align:center;
}
.music2 p{
margin: 0px;
}
<div class="music2">
<p>
Upgrade today to get your favorite music, movies, TV shows, and
podcasts. You can join youTunes and stream — or download and play
offline — over 70 million songs, ad‑free.
</p>
<p>
second paragraph..... offline — over 70 million songs, ad‑free.
</p>
</div>
Once in a while, a novel (book, story, short story, etc.) will have a block of centered text to display something external from the main subject, either a sign that is being read, an abstract text, etc.
Would it be proper (semantically correct) to use the blockquote element in these cases? For example:
section {
width: 350px;
font: 14px/1.3em Charter, sans-serif;
text-align: justify;
}
p {
margin: 0;
}
section>p+p {
text-indent: 1.5em;
}
blockquote {
text-align: center;
}
<section>
<p>I stepped back as far as I could and bent to peer under the door. There was nobody there; the stall must have been locked from the inside.</p>
<p>Cursing, I lowered my face and saw a piece of wet paper lying on the floor in front of the stall. It must’ve been glued to the door and fallen off. It informed:</p>
<blockquote>
<p>Closed for maintenance.</p>
<p>Sorry for any inconvenience.</p>
</blockquote>
<p>I fixed my eyes on the space between the floor and the door. It wasn’t so small, maybe […]</p>
</section>
I have a multi-line address in my footer and need lines to break at certain screen widths.
I have each line set in a <span> tag with a class and then allocated either block or inline-block in CSS.
For some reason a couple of lines are no longer behaving as they should and I cannot work out why.
Regardless of what I set a particular line to, it always appears in a line on its own, which is not what I want. And another 2 lines break when they should, 768px, but a gap between the lines appears.
HTML
<span class="address">FEAST THAILAND</span>
<span class="address1">10 NAEBKHEHART ROAD HUA HIN</span>
<span class=“address2”>(Inside The Memory Hua Hin) </span>
<span class="address3">PRACHUAP KHIRI KHAN, 77110 THAILAND</span>
<span class=“address4”>+66 (0) 32 510 207</span>
<span class="address5">OPERATED BY FOOD DISCOVERY (THAILAND) CO., LTD.</span>
<span class="address6"><strong>PRIVACY POLICY</strong> <strong>TERMS & CONDITIONS</strong></span> <span class="address7"><strong>WAIVER & RELEASE OF LIABILITY</strong></span>
<span class="address8"><strong>©2017</strong> ALL RIGHTS RESERVED</span>
<span class="address9">TAT License No. 14/02344</span>
CSS
.address,
.address1,
.address2,
.address4,
.address6,
.address7 {
font-size: 11px;
font-weight: normal;
font-family: Lato, sans-serif;
letter-spacing: 1.5px;
text-align: center;
display: inline-block;
color: #000000;
}
.address3,
.address5,
.address8,
.address9 {
font-size: 11px;
font-weight: normal;
font-family: Lato, sans-serif;
letter-spacing: 1.5px;
text-align: center;
display: block;
color: #000000;
}
Obviously that's just the standard CSS without the media query, but .address4, which has display: inline-block; should be sitting alongside .address3, which has display: block; Any suggestions why it is not?
When the media query comes into play at 768px, .address7 drops down below .address6, which is what I want, but a line of space appears between the 2. Again, any ideas why?
Is this the best way to handle breaking lines where required, or is there a better way? I have even tried using with a class added as well as trying another method found here:
CSS
#media only screen and (max-width: 414px){
.address2 {
font-size: 10px;
font-family: Lato, sans-serif;
letter-spacing: 1.5px;
text-align: center;
color: #000000;
display: block;
}
.address2:after {
content:"\a";
white-space: pre;
}
}
This last part with the .address2:after I thought should have moved the line after .address2 to the next line at 414px, yet it did not.
Any suggestions as to the best way to handle breaking the lines where I want?
cheers
One issue with display:block is that those elements always are displayed on a line of their own, no matter what the surrounding elements look like; be it display:inline or not.
So to answer your questions: an inline-block span next to a block span will not sit next to it on the same line. And two block spans with in between will each be on their own line, with another line in between where the are (this will look like a blank line).
To solve the whole issue, I'd start with simplifying it down to this:
div.addressblock {
text-align: center;
}
div.addressblock span {
font: normal 11px 'Lato', sans-serif;
letter-spacing: 1.5px;
display: inline-block;
color: #000000;
}
div.addressblock a {
font-weight:bold;
padding:0 .5em}
<div class="addressblock">
<span>FEAST THAILAND</span>
<span>10 NAEBKHEHART ROAD HUA HIN</span>
<span>(Inside The Memory Hua Hin) </span>
<span>PRACHUAP KHIRI KHAN, 77110 THAILAND</span><br>
<span>+66 (0) 32 510 207</span>
<span>OPERATED BY FOOD DISCOVERY (THAILAND) CO., LTD.</span><br>
<span>PRIVACY POLICY
TERMS & CONDITIONS
WAIVER & RELEASE OF LIABILITY</span>
<span><b>©2017</b> ALL RIGHTS RESERVED</span><br>
<span>TAT License No. 14/02344</span>
</div>
With actual breaks where you want the line breaks to be, and all the spans turned into inline-blocks to avoid unwanted breaks inside them, and let the page flow do the rest.
If you then want other things to happen at certain screen widths, you can always add some extra CSS.
This is my first time here, so please go easy on me. I have been doing coding at university for a couple of months now in one of my modules, and am just finishing off a project and beginning to test it on different browsers. It all runs fairly smoothly apart for one page on Internet Explorer.
On the image below, you'll see that the text that is supposed to go underneath the 'Public Observing' and 'Meetings' section shifts to the edge of the screen and falls off in Internet Explorer.
I've been googling for over an hour now with no luck, I was hoping some of you geniuses will be able to assist me!
Here is some of my HTML and CSS regarding those elements. Thank you very much for shedding any light on this issue!
.observing {
text-align: left;
font-size: 30px;
width: 21%;
padding-bottom: 2%;
}
.observingp {
text-align: left;
font-size: 17px;
width: 40%;
align-content: left;
float: left;
}
.meetings {
text-align: left;
font-size: 30px;
width: 21%;
padding-bottom: 2%;
margin-left: 42.5%;
margin-top: -5%;
}
.meetingsp {
text-align: left;
font-size: 17px;
width: 30%;
align-content: left;
float: left;
margin-left: 3%;
}
<div id="activities-info">
<div id="public-observing">
<h4 class="observing">Public Observing</h4>
<p1 class="observingp">
Public Observing takes place at ‘The New Inn’ at Eccup (LS168AU). Sessions are held regularly during most months, however they stop over Summer when the sunset is too late. Start times vary according to the sunset, and inconsistent dates are due to avoiding
the full moon, which makes observing difficult.
<br><br> Please dress warmly, as observing takes place on an open field. Also, ensure that all children are supervised by a responsible adult. The Society cannot be responsible for accidents on the field.
</p1>
</div>
<div id="meetings">
<h4 class="meetings">Meetings</h4>
<p1 class="meetingsp">
Meetings are held on the second Wednesday of each month at the Quaker Meeting House (LS29DX) between 7pm and 10pm. Meetings usually involve a lecture or presentation of an astronomical topic given by guest speakers or society members. <br><br> Informal
meetings take place two weeks later, on Wednesdays. Here members have an opportunity to express and discuss their interests with personal presentations.
</p1>
</div>
</div>
i recommend to use normalize.css - it is a project to make all borwsers render pages consistently. Just include it as another css befoer your own css file and you will have silmilar results on all browsers.
https://necolas.github.io/normalize.css/
When presenting preformatted text on the web (e.g. code samples), line wrapping can be a problem. You want to wrap for readability without scrolling, but also need it to be unambiguous to the user that it is all one line with no line break.
For example, you may have a really long command line to display, like this:
c:\Program Files\My Application\Module\bin\..> Some_really_long_command line "with parameters" "that just go on and on" " that should all be typed on one line" "but need to be wrapped for display and I'd like the text style to indicate that it has wrapped"
(Stackoverflow forces a line like this not to wrap.)
Is there a way of styling with CSS to give the same treatment as you see in books? i.e. to wrap the line, but include an image or glyph that indicates a line continuation.
Obviously I am looking for a style that can be applied to all text, and let the browser's XHTML/CSS rendering engine figure out which lines have wrapped and therefore need the special treatment.
The Solution so far..
Adding line continuation glyphs
Thanks to Jack Ryan and Maarten Sander, have a reasonably workable solution to add continuation glyphs to either the left or right of wrapped lines. It requires an image with repeating glyphs in the vertical, which is offset so that it is invisible if only one unwrapped line. The main requirement of this technique is that every line needs to be within a block (e.g. p, span or div). This means it cannot easily be used manually with existing text that is just sitting in a pre block.
The fragment below summarises the essential technique. I posted a live example here.
.wrap-cont-l {
margin-left: 24px;
margin-bottom: 14px;
width: 400px;
}
.wrap-cont-l p {
font-family: Courier New, Monospace;
font-size: 12px;
line-height: 14px;
background: url(wrap-cont-l.png) no-repeat 0 14px; /* move the background down so it starts on line 2 */
text-indent: -21px;
padding-left: 14px;
margin: 0 0 2px 7px;
}
.wrap-cont-r {
margin-left: 24px;
margin-bottom: 14px;
width: 400px;
}
.wrap-cont-r p {
font-family: Courier New, Monospace;
font-size: 12px;
line-height: 14px;
background: url(wrap-cont-r.png) no-repeat right 14px; /* move the background down so it starts on line 2 */
text-indent: -28px;
margin: 0 0 2px 28px;
padding-right: 14px;
}
To be used like this:
<div class="wrap-cont-l">
<p>take a long line</p>
<p>take a long line</p>
</div>
<div class="wrap-cont-r">
<p>take a long line</p>
<p>reel him in</p>
</div>
But wait, there's more!
I recently discovered syntaxhighlighter by Alex Gorbatchev. It is a fantastic tool for dynamically and automatically formatting text blocks. It is principally intended for syntax highlighting code, but could be used for any text. In v1.5.1 however, it does not wrap lines (in fact it forces them not to wrap).
I did a little hacking around though, and was able to add a simple line wrap option syntaxhighlighter and also incorporate the continuation glyph idea.
I've added this to the live examples and included a few notes on the hacks required (they are trivial). So with this as the text in the page:
<textarea name="code" class="java:wraplines" cols="60" rows="10">
public class HelloWorld {
public static void main (String[] args)
{
System.out.println("Hello World! But that's not all I have to say. This line is going to go on for a very long time and I'd like to see it wrapped in the display. Note that the line styling clearly indicates a continuation.");
}
}
</textarea>
This is a snapshot of the formatted result:
screenshot http://tardate.com/syntaxhighlighter/line-continuation-example.jpg
Here is one (unpleasant) way of doing this. It requires a number of bad practices. But SO is about solutions to real problems so here we go...
First each line needs to be wrapped in some sort of containing block. Span or p are probably the most appropriate.
Then the style of the containing block needs to have line height set. and a background image that contains a number of newLine glyphs at the start of every line except the first one. As this is code it would be resonable to expect it to not wrap more than 5 times. So repeating 5 times is probably enoygh.
This can then be set as the background image, and should display at the beginning of every line except the first one. I guess the resulting CSS might look like this:
p.codeLine
{
font-size: 12px;
line-height: 12px;
font-family: Monospace;
background: transparent url(lineGlyph) no-repeat 0 12px; /* move the background down so it starts on line 2 */
padding-left: 6px; /* move the text over so we can see the newline glyph*/
}
I've found a solution very similar to Jack Ryan's, but with the 'continuation' character at the end of the line. It also indents the continued lines.
The CSS:
p {
font-family: Arial, Sans-Serif;
font-size: 13px;
line-height: 16px;
margin: 0 0 16px 0;
}
.wrap-cont {
font-family: Courier New, Monospace;
margin-bottom: 16px;
width: 400px;
}
.wrap-cont p {
background: url(wrap-cont.gif) no-repeat bottom right;
text-indent: -32px;
margin: 0 0 0 32px;
padding-right: 16px;
}
The HTML:
<p>For example, you may have a really long command line to display, like this:</p>
<div class="wrap-cont">
<p>c:\Program Files\My Application\Module\bin\..> Some_really_long_command line "with parameters" "that just go on and on" " that should all be typed on one line" "but need to be wrapped for display and I'd like the text style to indicate that it has wrapped"</p>
<p>c:\Program Files\My Application\Module\bin\..> Some_really_long_command line "with parameters" "that just go on and on" " that should all be typed on one line" "but need to be wrapped for display and I'd like the text style to indicate that it has wrapped"</p>
</div>
<p>Stackoverflow forces a line like this not to wrap.</p>
This cannot be done with CSS. Sorry. :(
If you want it to be unambiguous, you'll have to add markup. I'd suggest using an <ol> with one list item per line of code, because that way you get line numbering for free. If this is too much work to do across the site, you could always add it using Javascript.