Reputation: 1910
I'm a beginner in CSS and I don't manage to do what I need.
I want to display some text on the left and on the right on the same line, and then only on the right on a second line.
Here's a JsFiddle :
HtML :
<div class="myDiv">
<p class="alignleft"> Text on the left.</p>
<p class="alignright">Text on the right.</p>
<p class="alignright2">Text on the right 2.</p>
</div>
<div class="myDiv">
<p class="alignleft"> Text on the left.</p>
<p class="alignright">Text on the right.</p>
<p class="alignright2">Text on the right 2.</p>
</div>
CSS :
.myDiv{
margin: 0 25% 10px 25%;
border-style: dashed;
border-width: 1px;
}
.alignleft {
float: left;
}
.alignright {
float: right;
}
The "Text on the right2" should be under "Text on the right".
It should be very simple but like I said I'm a beginner...
Upvotes: 1
Views: 3116
Reputation: 1114
Instead of adding any more extra tags in your HMTL, alternate solution for your code.
Just change you css:
.myDiv{
margin: 0 25% 10px 25%;
border-style: dashed;
border-width: 1px;
display:inline-block; // Newly added...
}
.alignleft {
float: left;
}
.alignright {
float: right;
}
.alignright2 {
float:right;// Newly added...
}
Upvotes: 0
Reputation: 593
Add this to your css:
.alignright2 {
text-align:right;
clear:right;
}
Upvotes: 0
Reputation: 122
Try adding
.alignright2 {
display:inline-block;
margin-left:50%;
}
You can change the margin according to your text or you need to change your html by surroding right2 paragraph into a div.
Upvotes: 0
Reputation: 33218
Try this:
html
<div class="myDiv">
<p class="alignleft"> Text on the left.</p>
<p class="alignright">Text on the right.</p>
<div style="clear:left;"></div>
<p class="alignright2">Text on the right 2.</p>
<div style="clear:right;"></div>
</div>
<div class="myDiv">
<p class="alignleft"> Text on the left.</p>
<p class="alignright">Text on the right.</p>
<div style="clear:left;"></div>
<p class="alignright2">Text on the right 2.</p>
<div style="clear:right;"></div>
</div>
css
.myDiv{
margin: 0 25% 10px 25%;
border-style: dashed;
border-width: 1px;"
}
.alignleft {
float: left;
}
.alignright {
float: right;
}
.alignright2 {
float:right;
}
Upvotes: 3
Reputation: 4354
This works fiddle
.alignleft {
text-align:left;
}
.alignright {
text-align:right;
}
.alignright2 {
text-align:right;
}
Upvotes: 4
Reputation: 27092
Try this if it works as you need.
.alignright2 {
float: right;
clear: right;
}
Upvotes: 5