I have the following 2 HTML statements. I want the "p" tag to NOT wrap to the next line. But I do want it to wrap in subsequent lines. (so I can't use the nowrap style). I want to create two CSS classes to treat each class differently.
<b class= "mscFlapSumBold" id='flapSum0'>This is the Flap Summary</b>
<p class= "mscFlapText" id='flap0'>This is the Flap text </p>
EDIT:
OK. I'm using James suggestion and it's working except that I can't seem to change the line spacing between my lines. When I use margin or line-height, they get ignored. So, James' suggested code is working mostly....
<p>
<strong class="mscFlapSumBold" id="flapSum0">...</strong>
<span class="mscFlapText" id="flap0">...</span>
</p>
Furthur edit: My issue surrounds the fact that I am using jQuery Mobile. So, depending on the viewport, your solution works only sometimes (with certain viewports). Driving me CRAZY. If you have any ideas, I would sure appreciate them.
Simply wrap both in the same p element and place .mscFlapText within a span instead:
<p>
<strong class="mscFlapSumBold" id="flapSum0">...</strong>
<span class="mscFlapText" id="flap0">...</span>
</p>
JSFiddle demo.
It's worth noting that the specification defines p as Grouping Content and b is Text-level Semantics; they aren't designed to go inline with each other.
You can use:
p.mscFlapText {
display: inline;
}
But actually, you should use <span> instead, better not mess up with default behaviour of HTML element.
Besides that, a good habit and small tip is to use <strong> rather than <b> since it's can improve your SEO ranking.
Related
I have a HTML fragment, a list item of a long ordered list
<li>
<p class="nw">Abɩlɩsa ba tɔwɛ asɩn mʋ.</p>
<p class="English">The elders discussed the matter.</p>
</li>
How do the CSS rules look like to keep the two paragraphs in the list item together when printing the document? This means that they either appear together at the end of a page or then are moved together to the next page.
How do I keep the paragraph <p class="nw"> and the paragraph <p class="English"> together so that no page breaks occurs?
I use
.nw {page-break-after:avoid;}
but does not work. There are in fact page breaks between the nw and English paragraphs. This should not be the case as far as I understand the rule. To check it I use the print preview function of Firefox.
The answer How do I avoid a page break immediately after a header was helpful to find a solution. It refers to this bug in the Mozilla bug database.
A solution is the following.
li {
page-break-inside: avoid;
}
It works fine in Firefox.
There are multiple factors in play, first in importance: The user's printer.
There is no bullet-proof way of achieving what you want (Notice how a printer will even cut images in two if it decides to).
You could use a query indicating that if it is on print, that particular piece of text moves somewhere safe on your page, but this could cause other problems, like breaking the normal flow of your layout, etc.
I suggest you read this: http://davidwalsh.name/css-page-breaks
And this :
http://www.w3schools.com/cssref/pr_print_pageba.asp
Do you mean to have no break between the p class?
You can try grouping everything in one <p> element, and then identifying each class with a <span> element. For example,
<li>
<p>
<span class="nw">Abɩlɩsa ba tɔwɛ asɩn mʋ.</span>
<span class="English">The elders discussed the matter.</span>
</p>
</li>
Or if you are trying to just remove the space between the two <p> elements, you can look here - remove spaces between paragraphs
Is this what you meant?
According to your edit, you mean in terms of printing. This removes the paragraph space in a web document, but not while printing - Just a note to anyone searching this question in the future. R Lacorne seems to know the answer to the edited question.
Should paragraphs breaking point be set with the width of the container, or using br's?
Example:
<div style="width: 30px;">
<p>
Foo bar test
</p>
</div>
Or
<p>
Foo<br>
bar<br>
test
</p>
http://jsfiddle.net/APcU3/
I've always assumed that it should be by setting a width on the container. But I'm not frontend and quite a lot of the HTML templates I've been given to complete have used the BR method.
It depends on specifically what you're trying to accomplish. If you're trying to get words to wrap to fit a specific width on the page then the first example is how you should approach it (as a general rule you should try to adjust layout issues using css, not markup).
However, if there is a logical reason why the lines need to break at those specific places, then the <br /> method is appropriate (for instance, if you want to make sure that each word is on its own line regardless of the word-length, then using markup (<br>) is fine. However, even in these circumstances you may want to rely on more meaningful semantic markup unless there is a real logic to specifically using a break character. I.e:
<p class='thin_column'>
<span>Foo</span>
<span>Bar</span>
<span>test</span>
</p>
and include css rules:
.column {width:50px;}
.column span {display:block;}
This way you can still use CSS to radically adjust the layout but you'll force line-breaks after each word.
Don't ever mix style and structure (or in this example content)! The width-method (used in an css-class and not inline) is the one and only way to achieve this.
the <br> element is only used to force a line break on a specific position. but that is content-dependend not a styling issue.
I want to use <p> instead of <br><br> since it takes less space and I can change how big of a gap it will create (changing the top margin of p).
However when using a floating image using <p> will make the row appear below the image instead of beside it.
I was think about setting the display property to inline but that makes the <p> not changing row at all.
So, how can i make p behave like br?
You don't 'make <p> behave like <br>', you use the right element for the job. If you're wrapping paragraphs of text, you use a <p> tag.
Outside of HTML emails, I don't ever see a use for a <br><br>.
p { height:(designated height of space); }
note that this only works if the line is very short and not breaking; or you will end up with a mess.
Its not really good practice to change the br tag...I mean that's why standards exist. like #hunter said before.
Easy question, it is valid to have overlapping spans in html?
Example:
<span id="1">This is <span id="2"> some text </span> some other text </span>
^ ^
End1 End2
Edit:
I see now that the spans closing tag would be ambiguous about which one it is closing, and that first </span> would close span id = 2, not 1 like I intended.
My problem is, I have a block of text which I'm trying to highlight based on what the mouse hovers over. This block of text is composed of sections, some of which "overlap" eachother. I'm trying to use some jQuery and HTML to present this document so when I hover over the sections, the appropriate one will be highlighted.
So, in my example above, the first span is meant to be ended with the first span close tag, and the second span is meant to be ended to with the second span close tag. This is because of the semantics of my document, these are two overlapping segments.
I want it so when I hover to the left, it will only highlight up to span id = 1 and the first span close, if I hover between the two "overlapping" spans, it will highlight both of them, and if I hover to the right, it will highlight from span id=2 to the last span close.
However, I'm starting to think this isn't possible. Is there any way I can distinguish segments of text in HTML that allows overlapping? So my jQuery script that highlights when I hover over different spans will highlight the correct portions.
Should I alternate between div's and spans? Would that disambiguate what I'm closing then and allow me the do the proper highlighting with my jQuery hover script? I'm wondering about more than 2 segments overlapping now. Sigh, I wish I could just be explicate about what I'm closing.
No tags can overlap in HTML - they must be properly nested. The HTML you have posted is valid, but may not semantically be what you are expecting. A </span> is going to terminate the previous <span> in the same scope. You haven't identified which <span> you are expecting to be closed with each </span>
<span id="span1">This is <span id="span2"> some text </span> (ends span2) </span> (ends span1)
This would certainly make a big difference in this case:
<span>This is <span> some text </span> and more text </span>
The content of a SPAN element is allowed to contain any "inline" element. SPAN is one of these "inline" elements. See the DTD declaration for the SPAN element for more details.
Yeah, that is legal. You might do that to specify a different style for the outer and inner spans (if you were to specify a class or style, etc.).
BTW - The more common term for this is "nesting" not "overlapping."
This is legal (foo is red; bar is blue; spam is red again as it's nested):
<span style="color: red">foo<span style="color: blue">bar</span>spam</span>
This isn't:
<div style="color: red">foo<span style="color: blue">bar</div>spam</span>
But it may be worth noting that in MediaWiki and some other sanitization engines in blogs etc that is legal, as it converts the above to this:
<div style="color: red">foo<span style="color: blue">bar</span></div>
<span style="color: blue">spam</span>
It could be argued this encourages bad behavior, but not everybody who writes a blog is as technical as the people like us who use stack overflow (posting as community wiki as this will probably get voted down :-P)
I know, its too late to answer the question. But, this could help someone.
Yes! Its totally correct that no tags can overlap in html. I had exact scenario, mentioned as in above question. But, everything has a solution! We can solve this problem using html tag versioning!
The html snippet, mentioned in the above problem can be break like,
<span id="1_1">This is </span><span id="1_2"><span id="2_1"> some text </span></span><span id="2_2"> some other text </span>
Now, you have to add a custom handlers for your mouse hovers. Through handler callbacks, you need to pass span id to JavaScript. In JavaScript controller, you need to preserve a appropriate map of parent id with all child ids ( e.g. for version 1.x; {'1': ['1_1', '1_2', '1_3']} etc ). Now, whenever you hovers a mouse over any span, you would be able to find all of its siblings. Here is the trick! Post this, you just need to add a custom CSS class for all versions. (e.g. if you hovers mouse on id 1_1, all 1_x versions will get highlighted ).
It worked smoothly for me, for all the edge cases.
No.
When we hit the first closing /span it is ambiguous which of the two opening span's you want to close.
Most people, and a computer, since it is the only legal option, will conclude you intended to close the latter span. But considering the additional context of your question I suspect you actually intended to close the former span; which is not 'legal'.
The people correcting you with "you meant nested, not overlapping" are making the same deduction; you couldn't have mean 'overlapping' because that would be illegal. I think you did indeed mean 'overlapping', but that's ok, your secret is safe with me.
I understand your problem, and apparently there is no elegant solution. If you only care about the visual result, one solution would be to close and reopen tags properly. Instead of:
<span id="1">This is <span id="2"> some text </span> some other text </span>
use something like:
<span class="hl1">This is <span class="hl2"> some text </span></span><span class="hl2"> some other text </span>
if you use just color or background properties for highlight (e.g. using rgba color, to allow for multiple highlighting), this should do it. If you use outline/border then it won't, since you will have also intermediate borders where tags close.
IMHO, a tag or other structure (I see it more like an anchor), that allows overlapping and indicates where it closes would be something to consider for implementation.
I've been wondering if I can use <p> </p> (just space in paragraph) instead of <br />
Because I love to keep my code semantic and thought if this is right has been bothering me for a while now. I have seen WYSIWSG editors (TinyMCE) use this, but I still rather ask then do it wrong.
That is not "semantic", an empty paragraph is something that more or less cannot exist, semantically. It contains no information, i.e. no semantic content. All it does is change the visual layout, i.e. the presentation.
You're far better off using styling to change the margins, borders or padding to achieve the effect you're after.
What's wrong with using the margins of the paragraphs for vertical-spacing instead?
<p>Hello World</p>
<p>This is much cleaner than using empty tags with non-breaking spaces.</p>
The right way to do it is with CSS: use the margin-top or margin-bottom.
<p> </p> is pretty horrible... I'd rather see <br> than that (even though it may be less "correct").
<p> </p> is not semantic, so I don't know how that helps you.
You should set the space between the paragraphs with css.
I advocate wrapping items in block-level tags, such as divs and ps. This way I don't need either. If you want to space out elements, you should be using margins. You can be more accurate with margins anyway.
In a situation where you're forced to have a line break, use <br />: it, unlike empty paragraph tags, actually does mean 'line break'. There's almost always a better way to do things though.
It's HTML. You can use whatever it wants as long as you're sure it will render the way you wanted on all the browsers you're gonna use. I don't understand what you mean by "keep my code semantic" so I'm not sure what your issue with <br> is. But if you're talking about formatting and such, turn to CSS.