0

How do I align the text to right. I have a container with expand and collapsing. I want to align the expand/collapse text to right. I don't want to use float:right;. Is there any other way we can achieve the same.

<div class="container">
    <div class="header"><span>Expand</span>

    </div>
    <div class="content">
        <ul>
            <li>This is just some random content.</li>
            <li>This is just some random content.</li>
            <li>This is just some random content.</li>
            <li>This is just some random content.</li>
        </ul>
    </div>
</div>

http://jsfiddle.net/eK8X5/2354/

6
  • @webkit: Actually its an icon there not text as of now. for fiddle purpose I put a text.
    – Shane
    Commented Jun 26, 2014 at 14:36
  • an icon that is a font-icon? inline image? background image?
    – webkit
    Commented Jun 26, 2014 at 14:37
  • @Shane Then this is a pointless question. You should show the code that you are having problems with, or recreate the same thing in new code. Changing an image to text changes a lot of things.
    – Ruddy
    Commented Jun 26, 2014 at 14:38
  • Don't ask questions about a different problem to the one you are having, it wastes people's time. Update your question to your actual problem. Put an icon in your fiddle and try to be as accurate as possible. Commented Jun 26, 2014 at 14:39
  • If it's an inline level element (such as an image) it will still work with text-align:right - jsfiddle.net/eK8X5/2357
    – Paulie_D
    Commented Jun 26, 2014 at 14:40

4 Answers 4

1

Have you tried adding this to your CSS?

text-align: right
0
1

Use this:

.header{
    text-align:right;
}

This will work for you sure.

1

You can try this:

Demo

.container .header {
  background-color:#d3d3d3;
  padding: 2px;
  cursor: pointer;
  font-weight: bold;
  text-align:right;
}
2
  • Is it possible to give a margin for the text.
    – Shane
    Commented Jun 26, 2014 at 14:39
  • because if your width is not fix then it will create problem Commented Jun 26, 2014 at 14:42
0

Add text-align to your header class

CSS :

.container .header {
  background-color:#d3d3d3;
  padding: 2px;
  cursor: pointer;
  font-weight: bold;
  text-align:right;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.