Align right with indentation - css

I have text which has to be right aligned, and when this text takes up more than one line and wraps around, that new line has to be distinguishable from the line after, so I'm trying to get it to indent on the right side, but I can't find a solution which works.
I've tried what was suggested on [the htmlhelp forums thread #8327] and [codingforums thread #58451] as well as a combination of the two to no avail (Can't post links. Sorry.). Is there any other way of accomplishing this?
My attempts:
div.poem li:after
{
content: " ";
display: inline-block;
width: 10px;
}
Does something, but I don't want it to indent if the text only takes up one line.
div.poem li::first-line::after
{
content: "asdf";
}
Does nothing
div.poem li:first-line
{
color: red;
margin-right: 200px;
padding-right: 200px;
}
Text on the first line turns red (so that I know what's going on) but the margin and padding doesn't do anything.
HTML:
<div class='poem'>
<ul class='poem'>
<li>Here's one line of the poem</li>
<li>This is the second line of the same stanza, which is long and will wrap around</li>
<li>Part of the line above is now on line 3, and looks like it's supposed to be a line of its own.</li>
</ul>
</div>

Here you go:
p {direction:rtl;padding-right:100px;text-indent:-100px;}
This sets the css direction to be from right to left.
Then add right padding to indent the whole thing from the right
Then use a negative indent that causes the first line to be "outdented"
Your content and text-flow is still left to right (i.e. breaks on the right), it just interprets the css (e.g. paragraph text-indent) on the other side.
Here's my code:
http://jsbin.com/ukese5/7

I found an examples here, where it is explained how to create a left indented list of links. It only seems to work on left aligned text though since the method includes using text-indent. In your case (left-aligned) it would look like this:
div.poem li { padding-left: 2em; text-indent: -1em; }
div.poem { text-align: right; }
I tried right aligning it but that didn't work. Is the text being read from Right-To-Left? In that case this should work:
div.poem li { padding-left: 2em; text-indent: -1em; }
div.poem { direction: rtl; }
I assumed his HTML markup:
<div class="poem">
<ul>
<li>This text goes on for sometime.This text goes on for sometime.This text goes on for sometime.This text goes on for sometime.This text goes on for sometime.This text goes on for sometime.This text goes on for sometime.This text goes on for sometime.</li>
</ul>
</div>
Updated answer based on the your <li> structure:
div.poem li:nth-child(3) { padding-right: 2em; }
div.poem { text-align: right; }
Please note that these are CSS3 selectors and that much older browsers don't support :nth-child(). Since the reading of the english text still works you can use that solution also. To learn more you visit the specification page.
Another thought: If you create these <li> using code, you can add a class on the <li> that you want indented. And then use more browser friendly CSS to indent it.
The only thing left is to sort out if you want the bullet points or not. Those can be taken away with:
div.poem ul { list-style: none; }

Related

Unindented code with spans has strange wrapping behavior

I have text in spans which is wrapping strangely. Ive worked out that if I indent the html it fixed the issue.
This is fine:
<div class="value">
<span>56959 bqCYXFYS</span>
<span>MBIaLbJm</span>
<span>SW6 6PN</span>
</div>
This is not:
<div class="value"><span>56959 bqCYXFYS</span><span>MBIaLbJm</span><span>SW6 6PN</span></div>
This CSS is just for illustrative purposes:
.value {
background: grey;
}
span:first-of-type {
color: red;
}
span:nth-of-type(2) {
color: green;
}
span:nth-of-type(3) {
color: gold;
}
In the screenshots below ive manually shrunk div.value to make the text wrap. The top screenshots of the indented code is correct, and the 2nd screenshots of unindented code are wrapping in the strange way that I need to prevent.
How can I solve this with CSS only? I cant change the HTML structure at all.
Unindented code example: http://jsfiddle.net/67u7d/7/
Indented code example: http://jsfiddle.net/67u7d/6/
Wrapping occurs when there's whitspace, but since you do not have whitespace (even newline and tabs) between your spans, it's all one "word" that will not break.
As far as breaking, these are identical:
<div class="value"><span>56959 bqCYXFYS</span><span>MBIaLbJm</span><span>SW6 6PN</span></div>
<div class="value">56959 bqCYXFYSMBIaLbJmSW6 6PN</div>
To solve it and keep your spans as true inline elements, you can add a space after the spans using a :after pseudo element:
span:after {content:' ';}
Here's your new fiddle: http://jsfiddle.net/rgthree/67u7d/9/
If you add display: inline-block to your span tag, it will wrap correctly.

Css text paragraph align

i want to display text where text begins first line for second line also, but it is going left side under numbers pls help
1 Text line paragraph and and and and and and and
and and and and and
2 Text line paragraph and and and and and and and
and and and and and
3 Text line paragraph and and and and and and and
and and and and and
Note: without using list class i want this type of display text with css please help.
I assume you mean that for text consisting of numbered items where the numbers are part of the content, each item should start on a new line and the second and subsequent lines of an item should be left-aligned to the same point where the text proper (after number, period, and space) of the first line starts. I also assume that “without using list class” means that the element for a numbered list, ol, must not be used, for some reason.
The simplest (and most robust) solution is then to use a table. Example:
<style>
table.list { border-collapse: collapse; }
table.list td { padding: 0; vertical-align: top; }
table.list td:first-child { text-align: right; padding-right: 0.25em; }
</style>
<table class=list>
<tr><td>1.</td><td>Text line paragraph and and and and and and and and and and and and</td></tr>
<tr><td>2.</td><td>Text line paragraph and and and and and and and and and and and and</td></tr>
<tr><td>3.</td><td>Text line paragraph and and and and and and and and and and and and</td></tr>
</table>
If you need avoid using table markup, then you need to simulate it somehow, e.g. using div and span markup and CSS table formatting (display: table etc.) – works in modern browsers, but not in old versions of IE.
Live Demo
If it's just the indentation you are after you could just do this:
p {
padding-left: 1em;
text-indent: -0.75em;
}
Depending on font you may have to adjust the text-indent value a bit.
http://jsfiddle.net/h7KvC/
Use text-indent and clear both in css hope it will solve your issue.
Make a ol out of it..
<ol>
<li>Text</li>
<li>Text</li>
<li>Text</li>
</ol>
Result :
Text line paragraph and and
and and and and and and and and and and
Text line paragraph and and
and and and and and and and and and and
Text line paragraph and and
and and and and and and and and and and
You can make paragraphs into list items in this way:
HTML
<div class="list">
<p>Paragraph one</p>
<p>Paragraph two</p>
<p>Paragraph three</p>
</div>
CSS
.list {
counter-reset: pcount;
}
.list p:before {
counter-increment: pcount;
content: counter(pcount, decimal) ' ';
}
Result
1 Paragraph one
2 Paragraph two
3 Paragraph three
http://jsfiddle.net/bQWau/1/

how to remove the gap between the inline-block elements

.item-list {
letter-spacing: -0.3em;
}
.item-list a {
letter-spacing: 0;
display: inline-block;
}
<div class="item-list">
a
a
a
a
</div>
only in win ie6,the gap between a is still exit ,the style letter-spacing:-0.3em will make effective when delete the style of a { letter-spacing:0 }
why? can i figure out this problem?
wow this one stumped me for a while...believe it or not here is your answer:
font-size:0; must be added to parent element
In the case of your example, I would define the font-size of the a tags separately, and add "font-size:0;" to the parent div element
In other words:
css:
.item-list{letter-spacing:-0.3em; font-size:0;}
.item-list a{letter-spacing:0;display:inline-block; font-size:SOMETHING HIGHER;}
(also your DOCTYPE declaration must be correct or display inline-block can have problems working in IE, at least I had trouble with it with IE7)
This should end any extra margin frustration you're experiencing from display:inline-block;
It has to do with how you're typing your HTML. Because you're formatting it nicely in your IDE, a la, with spaces and new lines, those spaces and newlines show up when displayed on the page. So instead of
<div class="item-list">
a
a
a
a
</div>
type it out as one line and they will go away:
<div class="item-list">aaaa</div>
You can add this CSS
a{float:left}
Gap will Remove
I always use:
line-height: 2.2; //or whatever value you want
I took from facebook layout and works amazing for me

Incorrect html alignment during hover

I have a menu on a web page and I want to add some emphais onto the element that my mouse is hovering over.
Before I hover my mouse the menu looks good and the alignment looks good. To add emphsis, I added a small arrow (or '>' sign). The problem is that now the text jumps to the right by 2 characters.
I want to add the '>' character without my menu text jumping the right. The correct behavior is that the text remains in p
lace and the arrow appears 2 spaces to the left of the hovered menu item.
Note I tried to change my alignment and the whole thing looks like crap. Only text-align: left gives it the correct alignment.
#leftMenu {
position: absolute;
top:28%;
left:24%;
height: 20%;
width: 20%;
font-weight:400
font-size:0.5em;
}
#leftMenu a:hover:before {
content: "> ";
}
How can I add the arrow without the text jumping to the right?
Just have the ">" already exist, just not visible. This way it will take up the real estate on the menu, so nothing will move when it appears. Here is a small example:
CSS:
#leftMenu {
position: absolute;
top:28%;
left:24%;
height: 20%;
width: 20%;
font-weight:400;
font-size:0.5em;
}
.marker{
visibility:hidden;
}
#leftMenu li:hover .marker{
visibility:visible;
}
#leftMenu ul{
list-style:none;
}
HTML:
<div id="leftMenu">
<ul>
<li><span class="marker">></span>Link 1</li>
<li><span class="marker">></span>Link 2</li>
<li><span class="marker">></span>Link 3</li>
</ul>
</div>
I'm not really sure of the exact layout of your menu, but I think the above gets across the general idea.
You could add a padding-left for normal entries that takes exactly the width the arrow would have later and remove it when hovered in favor of the arrow.
However this could be quite a mess since the arrow may not have the same width in every browser (even with same font and font-size).
An other possibility is to use positioning properties to move the arrow to the right location. If you for example use position: absolute; on it, it will no longer move other things around. Be aware that it then will be positioned absolutely inside the next parent that does not have standard position (static).

How to underline every line of text, to the end of a block

So, here's my question, I'm doing a newsletter for a customer, which will look like a postalcard.
I want my layout to look like writing on lines
Can anyone help me achieve what I'm trying to do?
Putting my text in TD tags doesn't work since I don't know the length of each sentences.
Let me know if you need more info!
Thanks :)
I just ran into this issue where a client "needed" to have a notes section on a print-out with user-entered note text underlined as if on spiral-bound paper. (I've learned to stop asking why.) Why didn't I use a background image? It won't print out, so not an option.
Here's the structure (IDs for clarity):
<p id = "p">
<span id = "span1">
<span id = "span2">
sadfa sdfhkas dfjkahsd fhjklasdg f askjldfh jklas djklfh aljks hfjkl hasjdklfg hjlashdjlfgh jlkashdjkl gfhloashdfgh jkladshjkgl haskl dhfiu hajkl fghuasbhfljbahuk bfkljabwehrf bajkls bflaskdjf ljakdfk
</span>
</span>
</p>
The following styles are applied:
#p {
border-bottom: 1px solid black;
text-align: justify;
}
#span1 {
display: block;
margin-bottom: -1px;
}
#span2 {
border-bottom: 1px solid black;
}
Let's start from the inside here...
#span2 is given a bottom border in order to create the bulk of the lined-paper look. If we stop here, however, we have a problem: The lines don't extend all the way to the right margin, as has been mentioned previously. This issue we'll get to in a moment.
#span1, wrapping #span2, is 50% of the solution to this too-short line problem. I've given it a display property of block, which will allow me to apply a -1px bottom margin, effectively "covering up" the last overhanging line of #span2 with the bottom edge of #span1. The effect of this isn't worth much until we get to...
#p Here the styles we've applied to #span1 pay off. First, we have text-align: justify which takes care of most of the bottom-border lines reaching the right margin, save of course for the last line, which now looks really out of place. To take care of this, we apply border-bottom: 1px solid black to #p which -- because of the -1px bottom margin on our block-styled #span1 -- overlaps the last, short bottom border and completes the illusion.
Yes, it's sort of kludgy, but when it comes down to the wire and the client's demands can't be adjusted, sometimes a kludge is what you need.
(Note: I wouldn't expect this to work for email formatting... Like I said before, it's something I needed for mimicking that lined-paper look on a printed page.)
Unless I am mistaken, you want something like this:
http://jsfiddle.net/eB6tY/
CSS:
#postcard .line
{
width: 100%;
border-bottom: 1px solid #000;
}
HTML:
<div id="postcard">
<div class="line">Line 1</div>
<div class="line">Line 2</div>
<div class="line">Line 3</div>
</div>
in your lines that you need to underline add a style="border-bottom: 1px solid #000"(probably on your containing td)
Maybe Im missing the point but could you not do
<u> my text here </u>
assuming DIV as your relevant selector
div{text-decoration:underline}
or inline if you are emailing this...
<div style='text-decoration:underline'>
You could use a background image with the height of one line of text (plus margin-bottom) and width 1 pixel. The content will be "transparent plus a dot for the place where the line should go"...
This came up in my search so I will post my solution to my problem. I needed to underline an a tag that had padding to the end of line that; problem was the underline would start at begining of the element and not the text.
Problem:
Solution:
menu .heading a {
color: #414142 ;
}
.menu .heading a:after {
/* to get a nice underline that starts at padding-left offset */
border-bottom: 2px solid #414142;
content: '';
display: block;
position: relative;
bottom: -0.5em;
}

Resources