{"id":1073,"date":"2017-03-20T12:05:30","date_gmt":"2017-03-20T06:35:30","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=1073"},"modified":"2017-03-29T12:09:24","modified_gmt":"2017-03-29T06:39:24","slug":"align-content-div-bottom","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/align-content-div-bottom\/","title":{"rendered":"[ Solved -5 Answers]CSS- HTML- How to align content of a div to the bottom"},"content":{"rendered":"<p><label class=\"label label-info\">PROBLEM:<\/label><\/p>\n<p>We have the following CSS and HTML code:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">html code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">#header <br\/>{<br\/>  height: 150px;<br\/>}<br\/>&lt;div id=&quot;header&quot;&gt;<br\/>  &lt;h1&gt;Header title&lt;\/h1&gt;<br\/>  Header content (one or multiple lines)<br\/>&lt;\/div&gt;<\/code><\/pre> <\/div>\n<ul>\n<li>The header section is fixed height, but the header content may change. We would like to content of the header to be vertically aligned to the bottom of the header section, so the last line of text &#8220;sticks&#8221; to the bottom of the header section.<\/li>\n<li>So if there is only one line of text it would be like:<\/li>\n<\/ul>\n<p>Header title<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>header content (resulting in one line)<\/p>\n<ul>\n<li>And if there were three lines:<\/li>\n<\/ul>\n<p>Header title<\/p>\n<p>header content (which is so much stuff that it perfectly spans over three lines)<\/p>\n<ul>\n<li>How can this be done in CSS?<\/li>\n<\/ul>\n<p><label class=\"label label-info\">SOLUTION 1:<\/label><\/p>\n<ul>\n<li>Relative+absolute positioning<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">css code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">#header <br\/>{<br\/>    position: relative;<br\/>    min-height: 150px;<br\/>  }<br\/>  #header-content <br\/>{<br\/>    position: absolute;<br\/>    bottom: 0;<br\/>    left: 0;<br\/>  }<br\/>&lt;div id=&quot;header&quot;&gt;<br\/>  &lt;h1&gt;Title&lt;\/h1&gt;<br\/>  &lt;div id=&quot;header-content&quot;&gt;Some content&lt;\/div&gt;<br\/>&lt;\/div&gt;<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p><label class=\"label label-info\">SOLUTION 2:<\/label><\/p>\n<p>Use CSS positioning.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">css code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">\/* creates a new stacking context on the header *\/<br\/>#header <br\/>{<br\/>  position: relative;<br\/>}<br\/>\/* positions header-content at the bottom of header&#039;s context *\/<br\/>#header-content <br\/>{<br\/>  position: absolute;<br\/>  bottom: 0;<br\/>}<\/code><\/pre> <\/div>\n<ul>\n<li>you need identify the header-content to make this work.<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">html code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;span id=&quot;header-content&quot;&gt;some header content&lt;\/span&gt; <br\/><br\/>&lt;div style=&quot;height:100%; position:relative;&quot;&gt;                                              <br\/>    &lt;div style=&quot;height:10%; position:absolute; bottom:0px;&quot;&gt;bottom&lt;\/div&gt;<br\/>&lt;\/div&gt; <\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 3:<\/label><\/p>\n<ul>\n<li>This is one of the solution :<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">css code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">#header <br\/>{<br\/>  display: table-cell;<br\/>  vertical-align: bottom;<br\/>}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p><label class=\"label label-info\">SOLUTION 4:<\/label><\/p>\n<h4 id=\"html\"><span style=\"color: #800080;\"><b>Html :<\/b><\/span><\/h4>\n<p>The solution just takes one &lt;div&gt;, which we call the &#8220;aligner&#8221;:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">html code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;div class=&quot;bottom_aligner&quot;&gt;&lt;\/div&gt; ... Your content here ... <\/code><\/pre> <\/div>\n<ul>\n<li>This trick works by creating a <b>tall, skinny div, <\/b>which pushes the text baseline to the bottom of the container.<\/li>\n<\/ul>\n<h4 id=\"example-program-for-html\"><span style=\"color: #ff6600;\"><b>Example Program for HTML :<\/b><\/span><\/h4>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">html code<\/span> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">&lt;body&gt;<br\/>  &lt;div class=&quot;outer-container&quot;&gt;<br\/>    &lt;div class=&quot;top-section&quot;&gt;<br\/>      This text<br\/>      &lt;br&gt; is on top.<br\/>   &lt;\/div&gt;<br\/>   &lt;div class=&quot;bottom-section&quot;&gt;<br\/>      &lt;div class=&quot;bottom-aligner&quot;&gt;&lt;\/div&gt;<br\/>      &lt;div class=&quot;bottom-content&quot;&gt;<br\/>        I like it here<br\/>        &lt;br&gt; at the bottom.<br\/>     &lt;\/div&gt;    &lt;\/div&gt;  &lt;\/div&gt;<br\/>&lt;\/body&gt;<\/code><\/pre> <\/div>\n<h4 id=\"example-program-for-css\"><span style=\"color: #800080;\"><b>Example Program for CSS :<\/b><\/span><\/h4>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">css code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">.outer-container <br\/>{ <br\/>border: 2px solid black; height: 175px;width: 300px; } <br\/><br\/>.top-section <br\/>{ <br\/>background: lightgreen; height: 50%; <br\/>}<br\/><br\/> .bottom-section <br\/>{<br\/> background: lightblue; height: 50%; margin: 8px;<br\/> }<br\/><br\/> .bottom-aligner<br\/> { <br\/>display: inline-block; height: 100%; vertical-align: bottom; width: 3px;background: red;<br\/> }<br\/> <br\/>.bottom-content <br\/>{ <br\/>display: inline-block;<br\/> } .top-content <br\/>{ <br\/>padding: 8px; <br\/>} <\/code><\/pre> <\/div>\n<h4 id=\"sample-output\"><span style=\"color: #ff6600;\"><b>Sample Output:<\/b><\/span><\/h4>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"size-medium wp-image-1090 aligncenter\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/03\/op-300x182.png\" alt=\"\" width=\"300\" height=\"182\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/03\/op-300x182.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/03\/op.png 319w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li>Set the height of the header div. Then inside that, style your H1 tag as follows:<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">css code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">float: left;<br\/>padding: 90px 10px 11px<\/code><\/pre> <\/div>\n<p><label class=\"label label-info\">SOLUTION 5:<\/label><\/p>\n<h4 id=\"try-with\"><span style=\"color: #808000;\"><b>Try with:<\/b><\/span><\/h4>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">css code<\/span> <\/div> <pre class=\"language-css code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-css code-embed-code\">div.myclass <br\/>{ <br\/>margin-top: 100%;<br\/> }<\/code><\/pre> <\/div>\n<ul>\n<li>try changing the % to fix it. Example: 120% or 90% &#8230;etc.<\/li>\n<\/ul>\n[ad type=&#8221;banner&#8221;]\n","protected":false},"excerpt":{"rendered":"<p>PROBLEM: We have the following CSS and HTML code: The header section is fixed height, but the header content may change. We would like to content of the header to be vertically aligned to the bottom of the header section, so the last line of text &#8220;sticks&#8221; to the bottom of the header section. So [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[2238,2240,1715,2232,2239,2230,2233,2229,2228,2237,2236,2235,2234,1713,715,2231],"class_list":["post-1073","post","type-post","status-publish","format-standard","hentry","category-css","tag-align-div-to-bottom-of-div","tag-align-div-to-bottom-of-page","tag-align-div-to-bottom-of-parent","tag-align-headline-to-bottom-of-div-with-equalizer","tag-align-text-to-bottom-of-div-bootstrap","tag-aligning-an-element-to-the-bottom-of-its-container","tag-aligning-header-elements-to-bottom","tag-css-align-contents-of-div-to-the-bottom","tag-html-how-to-align-content-of-a-div-to-the-bottom","tag-html-text-align-bottom","tag-text-align-bottom-css","tag-text-at-bottom-of-div","tag-understanding-csss-vertical-align-property","tag-vertical-align-bottom-not-working","tag-vertical-align","tag-vertical-align-all-you-need-to-know"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=1073"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/1073\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=1073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=1073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=1073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}