How to align text vertically using CSS?

<div style='height:200px;'>
SOME TEXT
</div>

How can I align “SOME TEXT” at the bottom of a div using CSS without filling?

+3
source share
4 answers

An absolutely simple way, although not quite using your sample code, would be:

div {height: 400px;
    width: 50%;
    margin: 0 auto;
    background-color: #ffa;
    position: relative;
    }

div p   {position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    }

HTML

<div id="container">
<p>SOME TEXT</p>
</div>

Wrap your text in the element, anything from <p>, <span>, <div>... everything and place the item at the bottom of its container.

+1
source

, , .
display: table; vertical-align: center,
JS/CSS.
div div:

<div style='position:relative;'>
    <div style='position: absolute; bottom:0;>
            My Text
    </div>
</div>

, , Tables - KISS ( if, ).

0

TD , DIV. .

DIV CSS. , .

If you use absolute positioning, you can vertically align the text by vertically aligning the container in which the text is located. However, absolutely positioned elements do not occupy “space” inside their container, which means that you need to set margin or padding to compensate for this space in the container.

For example:

HTML:

<div id="container">
  <span id="text">Some text, Some text, Some text, </span>
</div>

CSS

#id {
  position:relative;
  margin-bottom: 100px;
}

#text {
  position:absolute;
  bottom:0;
  height: 100px;
  overflow:hidden;
}
0
source

id {

display:table-cell; 
vertical-align:bottom;
}
0
source

Source: https://habr.com/ru/post/1716405/


All Articles