How to indent text from the right side? [duplicate] - html

This question already has answers here:
css text-indent equivalent on the right side
(6 answers)
Closed 4 years ago.
Consider this example:
How to indent text from the right side ? As seen from the example, this is indented from the left side, but how to make it opposite without affecting any other elements ?
I tried to play with text-indent, but could not figure it out.
I also refered here, but also could not get it working.
I managed to do it with float: right and padding, but they become block elements in that case, which should not happen.
text-align does this, but it moves all of it to the right side. I want to keep it on the left, but with reverse alingment. It also should not affect anything on the right or left side of it.

It seems as though you want the text to be right-aligned with some padding so it's not right up against the side of the box.
p {
text-align:right;
padding-right: 5em;
}
<p>test</p>
<p>test test</p>
<p>somethin grandom</p>
<p>test again</p>
<p>this is the last test</p>
An alternative is to use direction:
p {
direction:rtl;
text-indent: 5em
}
<p>test</p>
<p>test test</p>
<p>somethin grandom</p>
<p>test again</p>
<p>this is the last test</p>

Use display: inline-block with text-align. It will expand the container just enough and will not change the display to block:
.foo {
display: inline-block;
text-align: right;
background: papayawhip;
}
<div class="foo">
test<br>
test test test<br>
test test
</div>

Make the element inline-block and then use text-align:
.text {
display: inline-block;
text-align: right;
}
p {
margin: 0;
}
<div class="text">
<p>some text</p>
<p>text</p>
<p>some text text and more</p>
<p>some text</p>
</div>
Or use float:left and clear float after if you want to have a line break after:
.text {
float: left;
text-align: right;
}
p {
margin: 0;
}
<div class="text">
<p>some text</p>
<p>text</p>
<p>some text text and more</p>
<p>some text</p>
</div>
<div style="clear:left;">
lorem ipsume dolret lorem ipsume dolret lorem ipsume dolret lorem ipsume dolret lorem ipsume dolret lorem ipsume dolret lorem ipsume dolret
</div>

Consider using text direction direction:rtl;, and then applying the indentation. This way your text will appear to be indented from the right.

Add padding-right: 20px; to the stylesheet. Of course you can change the value.

Related

Card layout in css, using grid

I want to create a card-layout for my html elements. I came across this beautiful exposition by Jen Simmons, but it implements the idea using columns. The thing is that columns do not allow control over the width of each column, meaning equal width for each column.
Since in my webpage I want to keep control over the column width, I turned into grid:
main {
display: grid;
grid-template-columns: 60% 40%;
}
And here comes my question: How can I achieve this desired card layout using grid?
The desired visual effect is that each box (element) would appear after the one above it without taking into account the height of the box to its right or left.
The following image demonstrates:
Any help about it?
My code:
body {
margin: 10px;
width: 500px;
}
main {
display: grid;
grid-template-columns: 60% 40%;
}
section {
margin: 10px;
border: 1px solid black;
}
<main>
<section class="A">
<h3>Header 1</h3>
<p>Short text</p>
</section>
<section class="B">
<h3>Header 2</h3>
<p>Some Very long and boring text that lasts over a few lines.</p>
</section>
<section class="C">
<h3>Header 3</h3>
<p>Some text. Lorem ipsum dolor sit amet.</p>
</section>
</main>
The way I would do it, would be to re-structure your page, as the grid elements in the same row, are all one block, so if you separate them into the left column and right column, you can achieve this effect.
All I did was group the divs into the left and right columns to determine the heights of each one individually, based on columns and not rows.
body {
margin: 10px;
width: 500px;
}
main {
display: grid;
grid-template-columns: 60% 40%;
}
section {
margin: 10px;
border: 1px solid black;
}
.B {
height: 60%;
}
<body>
<main>
<div class="rContainer">
<section class="A">
<h3>Header 1</h3>
<p>Short text</p>
</section>
<section class="C">
<h3>Header 3</h3>
<p>Some text. Lorem ipsum dolor sit amet.</p>
</section>
</div>
<div class="rContainer">
<section class="B">
<h3>Header 2</h3>
<p>Some Very long and boring text that lasts over a few lines.</p>
</section>
</div>
</main>
</body>

What's an effective way of laying out the main text and photos on a web page? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm currently using Flexbox to lay out the main text and images on my web pages.
They way I have it set up works pretty well, with text on the left, photos on the right in wide viewports, and a single column of content on small viewports. But there are downsides: in a small viewport, all the images wind up piled at the bottom instead of intermingled with the text. In wide viewports, I don't have much control over where the images appear vertically, whether they correspond well to the text on the left. Plus, the same ol' two-column layout gets a little repetitive on a large site.
My current approach is this: I created two columns, the first using a flex-basis of 66%, the other 33%. I put the main text in the first flex item, then images in the second. In a wide viewport, I set the flex-direction to row so the text appears on the left, photos appear on the right. In a small viewport, the flex basis on both flex items is set to 100% and the flex-direction is set to column so they stack in a single column.
I'm sure there's a better approach than this
Make a container around all the content, set up each section to have both the text and the image inside it.
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
max-width: 75vw;
}
.item {
display: flex;
flex-direction: column;
margin: 2rem 0;
}
.item .text {
margin: 1rem;
}
.item .image {
margin: 1rem;
}
.item .image img {
max-height: 120px;
}
#media all and (min-width: 650px) {
.item {
flex-direction: row;
}
}
<div class="container">
<div class="item">
<div class="text">
<p>lorem ipsum more text lorem ipsum more text lorem ipsum more text lorem ipsum more text</p>
</div>
<div class="image">
<img src="https://i.ytimg.com/vi/MPV2METPeJU/maxresdefault.jpg">
</div>
</div>
<div class="item">
<div class="text">
<p>lorem ipsum more text lorem ipsum more text lorem ipsum more text lorem ipsum more text</p>
</div>
<div class="image">
<img src="https://i.ytimg.com/vi/MPV2METPeJU/maxresdefault.jpg">
</div>
</div>
<div class="item">
<div class="text">
<p>lorem ipsum more text lorem ipsum more text lorem ipsum more text lorem ipsum more text</p>
</div>
<div class="image">
<img src="https://i.ytimg.com/vi/MPV2METPeJU/maxresdefault.jpg">
</div>
</div>
</div>

Why bottom toolbar(footer) overlaps my content?

I want to create sticky bottom toolbar that always stays at the bottom. It always should be visible on a screen. I tried to use position: fixed, bottom: 0 which definitely helped, but it overlaps my content. Here is how it overlaps (look at the bottom of the page):
Yes, I understand that it should overlap, but the problem is that I cannot scroll to bottom to see remaining text.
Here is my code:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
.bottom-toolbar {
position: fixed;
bottom: 0;
width: 100%;
background-color: yellow;
}
</style>
</head>
<body>
<div class="container">
<div class="article">
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
</div>
<div class="bottom-toolbar">
<p> My toolbar </p>
</div>
</div>
</body>
</html>
How can I solve this problem?
The footer is on top of the layer with the article text, so you can solve it by "making room" with some padding:
.article {
padding-bottom: 40px;
}
40px; is just enough in a codepen, but add however much you want.
position: fixed; always relative to viewport
or, you can also use margin bottom to .article or padding-bottom: 60px (or your fotter-bar height) to .container.
if choose to give margin, do in .article
or, if choose to give padding, do it in .container or body (bcz fixed positioned is relative to viewport & after container if any other div comes)
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
.bottom-toolbar {
position: fixed;
bottom: 0;
width: 100%;
background-color: yellow;
}
.article {
margin-bottom: 60px;
}
</style>
</head>
<body>
<div class="container">
<div class="article">
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
<p>Lorem ipsum... Lorem....(a lot of text here)</p>
</div>
<div class="bottom-toolbar">
<p> My toolbar </p>
</div>
</div>
</body>
</html>

Position text at bottom, but letting it stay in document flow

I have the following problem:
There's an image floating left and a margin to the right.
Next to it, there is a div containing a headline and a text (I don't know any height-values of both, because it will be inserted dynamically).
The headline must align to the top and the text to the bottom. I thought it's enough to position the text absolute, but if the height of the image is smaller than the height of the headline + the text, the text flows into the headline....
I haven't found any solution to position the text at the bottom but letting it stay in document flow.
I am not allowed to use any table-elements (on the otherhand, display: table and so on is allowed, but I haven't figured out any solution with that as well)
<<<HTML
<div>
<h4>A headline, that isn't involved</h4>
<div class="clearfix">
<div> <!-- float left, margin-right -->
<img>
</div>
<div> <!-- float left -->
<h5>The headline aligning to the top</h5>
<p>
Some text aligning to the bottom
</p>
</div>
</div>
</div>
HTML
Please help me, I just can't figure out any solution!
/EDIT:
Both the imnages' and text-/headline-containers' height may vary, so no fixed height.
What i got so far is (by assuming, the text wont have more than 4 lines (but thats not the best way). The next Problem is: Firefox adds the margin-bottom of .box to the bottom: 0; of the text (like: bottom: -35px; But shown as bottom: 0; ... Chrome does interpret that the right way):
<style>
.box {
width: 488px;
float: left;
margin-bottom: 33px;
margin-right: 22px;
padding-top: 5px;
}
.table {
display: table;
}
.box.wide .box-content {
display: table-row;
}
.box.wide .box-content > div {
display: table-cell;
position: relative;
width: 233px;
}
.box.wide .box-content > div:first-child {
margin-right: 22px;
}
.box.wide .box-content div h5 {
padding-bottom: 88px;
}
.box.wide .box-content div p {
position: absolute;
bottom: 0px;
}
</style>
<div class="box wide width-488">
<div>
<h4>Überschrift</h4>
<div class="table">
<div class="box-content">
<div>
<img alt="" height="401" width="233" src="res/dummy/233-130.jpg">
</div>
<div>
<h5>Überschrift Lorem ipsum dolor sit amet, con sectetuer adipiscing eliÜberschrift Lorem ipsum dolor sit amet, con sectetuer adipiscing elit</h5>
<p>
Lorem ipsum dolor sit amet, con sectetuer adipiscing elit. Aenean commodo ligula eget dolor. Lor em ipsum dolor amet.
mehr
</p>
</div>
</div>
</div>
</div>
</div>
try using display: inline-block; on both floating elements and the text element that you want aligned to the bottom.
Then put the property vertical-align: bottom; on the text element you want aligned to the bottom.
I assumed you can make the right column a fix height, since the left column & right are the same in your image example.
I made a jsfiddle for your convenience: http://jsfiddle.net/hLPXM/
Alternately, here is what I did, based on your original code:
<h4>A headline, that isn't involved</h4>
<div class="clearfix">
<div class="left"> <!-- float left, margin-right -->
<img src="http://placehold.it/150x350" alt="placeholder" />
</div>
<div class="right"> <!-- float left -->
<h5>The headline aligning to the top</h5>
<div class="bottom-text">
<p>
Some text aligning to the bottom
</p>
</div><!-- .bottom-text -->
</div>
</div>
Note I added a .bottom-text class around the <p> that you want to align bottom.
Here is the CSS for the divs to float properly, etc. Note the position:relative; :
.left {float:left; margin-right:20px;}
.right {float:left; background:#eeddff; /*background to see div*/}
.left, .right {height:350px; position:relative;}
And more importantly the text starting from the baseline:
.bottom-text {
position:absolute;
bottom:0;
}
​
​
Here is a solution for you, using display: table, relative and absolute positioning:
<div>
<h4>A headline, that isn't involved</h4>
<div style="display:table;">
<div style="display:table-row;">
<div style="display:table-cell;padding-right: 20px;">
<img style="display:block" src="http://baconmockup.com/300/200">
</div>
<div style="display:table-cell;background:green;position:relative;vertical-align:top;">
<p style="">Some text aligning to the top</p>
<p style="position:absolute;bottom:0;">Some text aligning to the bottom</p>
</div>
</div>
</div>
</div>​
It does not rely on any fixed heights, and adopts to the height of the image automatically.
jsfiddle.net/EUvXh/
I don't know if you have already fixed this but the easiest way is to add margin-top: auto; to your p tag.

bottom-align a link in a div

I have something similar to this
.col {float: left; width:190px;border: 1px solid red;}
<div class="col">
<p>some text goes here some ass sasass here </p
</div>
<div class="col">
<p>some text goes here</p>
Link
</div>
So the text on the first div is quite long where as the text in the second div is not. So the first div gets taller than the second div.
What I want to achieve is leave the text in the second column as it is but vertical align the link to the bottom to match the left's div height.
Does that make sense?
Thanks
Look at this example:
http://www.ejeliot.com/samples/equal-height-columns/example-6.html
added:
you should take out the element that you want to put on the bottom.
<div class="col">
<p>Lorem ipsum dolor 1</p>
</div>
<div class="bottom"></div>
<div class="col">
<p>Lorem ipsum dolor 2</p>
</div>
<div class="bottom">
link
</div>