I'm trying to align text to the right in a small area. It becomes left align when the container is small. Is there anyway to force it right align?
div
{ float: right;
width: 100px;
height: 50px;
text-align: right;
border: thin solid black;
}
I'm trying to align text to the right in a small area. It becomes left align when the container is small. Is there anyway to force it right align?
div
{ float: right;
width: 100px;
height: 50px;
text-align: right;
border: thin solid black;
}
If you add direction: rtl;
it will do that
div {
float: right;
width: 100px;
height: 50px;
text-align: right;
border: thin solid black;
direction: rtl;
}
<div>
1testtesttesttesttesttesttesttesttest2
</div>
You can try direction: rtl;
, but this might mess up your text.
If your content has a fixed size like in your example. You can also use position:absolute;right:0;
like this:
.container { float: right;
width: 100px;
height: 50px;
border: thin solid black;
position:relative;
}
.content {
text-align: right;
position:absolute;
right:0;
}
<div class="container"><div class="content">
testtesttesttesttesttesttesttesttest
</div>
</div>