im new in this community, and a very newbie coder.
I want to set a space between this two columns, I tried a few codes but didn't work...
This is what I did:
<div class="container">
<div class="main row">
<div class="col-md-3">
<div class="col-md-12">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et excepturi eligendi tempore consequuntur voluptas obcaecati dignissimos culpa deserunt aspernatur, ipsa veritatis alias labore laboriosam commodi, quasi fuga quo ab, neque sunt odio voluptatibus nisi? In cupiditate dignissimos est nostrum itaque excepturi, amet aspernatur, atque, quam quasi dolore enim, illo natus tempora explicabo. Soluta quibusdam in exercitationem hic veniam alias, dolores error possimus, quidem, sequi ea tenetur repellendus, doloribus delectus necessitatibus dolorem. Quibusdam atque quae explicabo impedit aperiam repudiandae laborum iure, consequuntur ipsum eaque dolore saepe nam in. Maxime aliquid possimus reprehenderit cumque illum mollitia quos. Placeat quasi eveniet, expedita ex!
</p>
</div>
</div>
<div class="col-md-9">
<div class="col-md-12">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam id aut vero facere recusandae molestiae, iste assumenda, non ad dolor error atque illo possimus blanditiis, voluptatum eligendi ipsam nobis. Suscipit non esse neque magni, maiores impedit. Explicabo nam modi maiores officiis, dolorem dolor sapiente maxime commodi tempore inventore rerum obcaecati ratione possimus repellat similique illo delectus incidunt animi error consequuntur debitis! Ad corporis blanditiis eaque consequatur omnis perspiciatis, et culpa officiis, minus impedit quisquam unde nemo earum quae. Magnam, facere incidunt tenetur voluptatum nostrum odio laboriosam numquam! Autem, itaque molestiae, dignissimos recusandae debitis dolorem voluptatibus dolorum quam error, sit distinctio.
</p>
</div>
</div>
</div>
</div>
And i got this:
http://i.imgur.com/0dhqCZO.png
How I can set a space of X pixels between? :S
And another question to not make another post:
How I can set the 2 columns the same height? ( I know its a awesome newbie question haha )
First of all, actually there is a space between this two columns (30px due to Bootstrap padding included in col- classes. You don't see this 30px gap because you set background to col- classes. In order to see it you have to have another div inside col- class.
CODEPEN EXAMPLE
Secondly, read about grid system in Bootstrap, you can't have col-md-12 directly after col-md-3 (you have to use another row if you want to nest columns in another column).
You can change the gap by changing col- classes padding. Default for Bootstrap is 15px on each side. For example:
.col-md-3,
.col-md-9 {
padding-left: 60px;
padding-right: 60px;
}
CODEPEN EXAMPLE
Columns of the same height, the easiest example is this:
.column-1,
.column-2 {
height: 300px;
}
CODEPEN EXAMPLE
Use CSS's margin.
<div class="container">
<div class="main row">
<div class="col-md-3" style="margin: 10px">
<div class="col-md-12">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et excepturi eligendi tempore consequuntur voluptas obcaecati dignissimos culpa deserunt aspernatur, ipsa veritatis alias labore laboriosam commodi, quasi fuga quo ab, neque sunt odio voluptatibus nisi? In cupiditate dignissimos est nostrum itaque excepturi, amet aspernatur, atque, quam quasi dolore enim, illo natus tempora explicabo. Soluta quibusdam in exercitationem hic veniam alias, dolores error possimus, quidem, sequi ea tenetur repellendus, doloribus delectus necessitatibus dolorem. Quibusdam atque quae explicabo impedit aperiam repudiandae laborum iure, consequuntur ipsum eaque dolore saepe nam in. Maxime aliquid possimus reprehenderit cumque illum mollitia quos. Placeat quasi eveniet, expedita ex!
</p>
</div>
</div>
<div class="col-md-9" style="margin: 10px">
<div class="col-md-12">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam id aut vero facere recusandae molestiae, iste assumenda, non ad dolor error atque illo possimus blanditiis, voluptatum eligendi ipsam nobis. Suscipit non esse neque magni, maiores impedit. Explicabo nam modi maiores officiis, dolorem dolor sapiente maxime commodi tempore inventore rerum obcaecati ratione possimus repellat similique illo delectus incidunt animi error consequuntur debitis! Ad corporis blanditiis eaque consequatur omnis perspiciatis, et culpa officiis, minus impedit quisquam unde nemo earum quae. Magnam, facere incidunt tenetur voluptatum nostrum odio laboriosam numquam! Autem, itaque molestiae, dignissimos recusandae debitis dolorem voluptatibus dolorum quam error, sit distinctio.
</p>
</div>
</div>
</div>
</div>
Of course, change 10px to however many pixels you want.
Since we are using margin which affects all borders, 10px is half the amount of space that will be between the columns.
You can use margin-right: 10px on the first instead, if you want exactly 10px space between the columns, and no extra margin around them.
margin: Defines the margin around all borders of the object
margin-top: Defines the margin at the top border
margin-bottom: Defines the margin at the bottomborder
margin-right: Defines the margin at the right border
margin-left: Defines the margin at the left border
You should use bootstrap gutter for the separate columns. You will find good example and some information about it here
http://arnique.net/web-design/58/a-quick-guide-to-changing-bootstraps-gutter-width/
And you can use .row-eq-height to get the col-height equal.
.row-eq-height{
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
<div class="row row-eq-height"></div>
Full information is available here.
http://getbootstrap.com.vn/examples/equal-height-columns/#
If width of content boxes is not a problem you can use col-md-offset-* where * can be 1,2,..,12 as per your choice.
<div class="col-md-offset-1 col-md-8">
<div class="col-md-12">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam id aut vero facere recusandae molestiae, iste assumenda, non ad dolor error atque illo possimus blanditiis, voluptatum eligendi ipsam nobis. Suscipit non esse neque magni, maiores impedit. Explicabo nam modi maiores officiis, dolorem dolor sapiente maxime commodi tempore inventore rerum obcaecati ratione possimus repellat similique illo delectus incidunt animi error consequuntur debitis! Ad corporis blanditiis eaque consequatur omnis perspiciatis, et culpa officiis, minus impedit quisquam unde nemo earum quae. Magnam, facere incidunt tenetur voluptatum nostrum odio laboriosam numquam! Autem, itaque molestiae, dignissimos recusandae debitis dolorem voluptatibus dolorum quam error, sit distinctio.
</p>
</div>
</div>
For setting two columns to the same height you can set min-height css to some predefined length.
Related
As you can see the code below, div is the outermost scrolling container and the core in this topic section is a containing block with spans set as white-space: pre;.
One section is extremely simple and is just a block. The other .floated is set float: left;.
But the computed width of them is different: the former is just as wide as its containing block div i.e. 100px in this case, in contrast to the latter is as wide as its contents, around 1287.47px(given by Firefox). To make this difference more observable, I set a background color for both of them.
So the question comes:
My understanding is that the width of a block with width: auto; depends on its contents. Why is the first section not?
The expected effect is achieved by using float: left;, as .floated shows, but why and how does it work? What exactly does the float do? A new BFC? But if I change float to display: flow-root; which also creates a new BFC, it still doesn't work.
Thanks in advance for your help!
div {
border: 1px solid red;
width: 100px;
overflow: auto;
}
section {
background-color: teal;
}
span {
white-space: pre;
}
.floated {
float: left;
}
<div>
<section>
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis quis earum totam sequi, optio iusto neque sed! Reiciendis fugit, dolor.</span>
<span>Molestias consequuntur ipsam quod eligendi, temporibus a quos accusamus aliquid molestiae est blanditiis voluptatibus minus ipsum nisi odio tempora sed!</span>
<span>Suscipit, similique. Dolor possimus non doloribus voluptatibus necessitatibus, quas, consequatur hic provident quo neque sequi? Nesciunt, ratione laudantium rem quis!</span>
<span>Voluptate delectus, quis laboriosam animi esse, et perspiciatis, cupiditate, porro itaque officiis laudantium quidem. Quos culpa facilis, nesciunt itaque officiis.</span>
<span>Expedita ex error a explicabo deserunt, consectetur illum quod veritatis. Odio pariatur quae minima quasi, minus itaque architecto illo delectus.</span>
</section>
</div>
<div>
<section class="floated">
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis quis earum totam sequi, optio iusto neque sed! Reiciendis fugit, dolor.</span>
<span>Molestias consequuntur ipsam quod eligendi, temporibus a quos accusamus aliquid molestiae est blanditiis voluptatibus minus ipsum nisi odio tempora sed!</span>
<span>Suscipit, similique. Dolor possimus non doloribus voluptatibus necessitatibus, quas, consequatur hic provident quo neque sequi? Nesciunt, ratione laudantium rem quis!</span>
<span>Voluptate delectus, quis laboriosam animi esse, et perspiciatis, cupiditate, porro itaque officiis laudantium quidem. Quos culpa facilis, nesciunt itaque officiis.</span>
<span>Expedita ex error a explicabo deserunt, consectetur illum quod veritatis. Odio pariatur quae minima quasi, minus itaque architecto illo delectus.</span>
</section>
</div>
Online Demo
My understanding is that the width of a block with width: auto; depends on its contents.
It doesn't. The width of a block level element should respect this formula:
'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
As you can see, the content play no role in defining the width of your element and it will end with a width equal to its containing block (parent element). That's why you have the logical result of 100px. After defining the width, the content should try to fit that width but you have disabled line breaks with white-space: pre so all you will get is an overflow.
When, you make the div floated you need to consider another part of the Specification that describe the width of floating elements and you can read:
If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width.
Then the shrink-to-fit width is: min(max(preferred minimum width, available width), preferred width).
The content is considered in the "shrink-to-fit" algorithm.
In your case, since you are using white-space: pre you are not allowing any line break so the "preferred minimum width" will be the winner and you will end have a width equal to the longest sentence
If you disable the white-space, you will force line breaks and your content will try to fit the "available space" and both cases will give the same result even if we have different algorithm involved
div {
border: 1px solid red;
width: 100px;
overflow: auto;
}
section {
background-color: teal;
}
.floated {
float: left;
}
<div>
<section>
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis quis earum totam sequi, optio iusto neque sed! Reiciendis fugit, dolor.</span>
<span>Molestias consequuntur ipsam quod eligendi, temporibus a quos accusamus aliquid molestiae est blanditiis voluptatibus minus ipsum nisi odio tempora sed!</span>
<span>Suscipit, similique. Dolor possimus non doloribus voluptatibus necessitatibus, quas, consequatur hic provident quo neque sequi? Nesciunt, ratione laudantium rem quis!</span>
<span>Voluptate delectus, quis laboriosam animi esse, et perspiciatis, cupiditate, porro itaque officiis laudantium quidem. Quos culpa facilis, nesciunt itaque officiis.</span>
<span>Expedita ex error a explicabo deserunt, consectetur illum quod veritatis. Odio pariatur quae minima quasi, minus itaque architecto illo delectus.</span>
</section>
</div>
<div>
<section class="floated">
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veritatis quis earum totam sequi, optio iusto neque sed! Reiciendis fugit, dolor.</span>
<span>Molestias consequuntur ipsam quod eligendi, temporibus a quos accusamus aliquid molestiae est blanditiis voluptatibus minus ipsum nisi odio tempora sed!</span>
<span>Suscipit, similique. Dolor possimus non doloribus voluptatibus necessitatibus, quas, consequatur hic provident quo neque sequi? Nesciunt, ratione laudantium rem quis!</span>
<span>Voluptate delectus, quis laboriosam animi esse, et perspiciatis, cupiditate, porro itaque officiis laudantium quidem. Quos culpa facilis, nesciunt itaque officiis.</span>
<span>Expedita ex error a explicabo deserunt, consectetur illum quod veritatis. Odio pariatur quae minima quasi, minus itaque architecto illo delectus.</span>
</section>
</div>
<!--Top Navbar / Search-->
<div class="grid grid-rows-1 grid-cols-3 h-20">
<div class="col-span-1 h-full w-64 bg-purple-200">
Logo Area
</div>
<div class="col-span-1 h-full w-full bg-purple-100">
Search Area
</div>
<div class="col-span-1 h-full w-full bg-purple-100">
Profile Area
</div>
</div>
<!-- Sidebar / Content-->
<div class="grid grid-rows-1 inline-grid grid-cols-2 h-screen">
<div class="col-span-1 h-full w-64 bg-purple-200">
Sidebar Area
</div>
<div class="col-span-1 h-full w-full bg-purple-100">
Content Area
</div>
</div>
The above is the code I am using, I can get this working easily in vanilla CSS.
I am using the above to begin building the Grid structure of a admin-esk design.
However, I am unable to get this working correctly, visable on the print-screen:
The width of the columns, specifically the content column isn't filling the width.
The height seems to break, and add overflow to the page, adding the scrollable extra.
I can't seem to get the search area to fit next to the Logo area.
This is so much easier in vanilla CSS, Tailwind has made this harder.
It's gets much easier when you play around with Tailwind. See a working demo on tailwind play.
Keep me posted in the comments below if your expectations were different than the code I wrote.
<div class="flex min-h-screen max-h-screen">
<!-- Left Navigation -->
<div class="flex flex-col w-64">
<!-- Logo -->
<div class="h-20 flex justify-center items-center bg-purple-300">Logo Area</div>
<!-- Sidebar -->
<div class="flex flex-1 bg-red-200 overflow-y-auto">
Sidebar Area
<br />
<br />
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nulla at aperiam sunt, quae voluptates blanditiis sed natus nostrum facilis in, rerum ipsa molestiae maxime veniam, accusantium quo facere totam deserunt! Fugit, molestias? Veritatis aspernatur consectetur ipsum fugit molestias reiciendis voluptatem, atque quisquam molestiae error sunt voluptatibus eum, quae blanditiis doloribus? Adipisci, impedit? Eaque earum est officiis excepturi non necessitatibus perferendis. Dolor iusto perferendis incidunt nesciunt sit officiis, dolorum possimus et tempora itaque laudantium ipsa non porro ratione omnis ducimus, voluptatem quos. Voluptatum consectetur officiis magni veritatis, possimus nesciunt quidem cumque! Cumque quisquam maxime libero suscipit veritatis qui a culpa voluptate quos modi repellendus sed est commodi ea, nihil rem laboriosam unde. Voluptatibus corrupti est quia quaerat officiis, eos deleniti deserunt. Optio aperiam velit molestiae, quasi repellendus voluptate sequi? Omnis, repudiandae suscipit perferendis ullam dignissimos labore aut! Veniam fugit earum dignissimos quos quasi, nam obcaecati laboriosam ut placeat recusandae ullam. Hic.
</div>
</div>
<!-- Right Component -->
<div class="flex flex-1 flex-col">
<!-- Header -->
<div class="h-20 flex">
<div class="flex flex-1 justify-center items-center bg-indigo-200">Search Area</div>
<div class="flex flex-1 justify-center items-center bg-blue-200">Profile Area</div>
</div>
<!-- Content -->
<div class="flex flex-1 overflow-y-auto bg-green-200">
Content Area
<br />
<br />
Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita repellat odit quas, ipsum sapiente recusandae, exercitationem illo dolorem nulla aut, porro ea. Optio, omnis eum? Beatae dolorem odit quae fugiat. Quod nobis tempore mollitia minima repellendus atque quisquam? Quae maiores neque deserunt ad enim impedit rerum, dolorum dolor nulla porro ea ducimus officia repellat assumenda dicta in reprehenderit amet hic? Officiis incidunt quis ipsum nesciunt eum eos aspernatur modi, temporibus ut nisi! Optio quaerat odit, suscipit, quisquam et laboriosam adipisci labore quidem reprehenderit eum earum temporibus odio, omnis mollitia cum. Facilis libero officiis deleniti aperiam veniam aliquam saepe consequuntur quae facere provident illum asperiores, delectus ad animi, possimus fugit aspernatur error perferendis! Quia rem laudantium nemo vero magnam, in iusto. Adipisci tempore pariatur accusantium autem soluta, repellendus eum sequi quae a. Soluta rerum vitae perspiciatis consequuntur quas? Accusantium saepe, alias aliquid voluptatibus repellendus harum expedita vel libero praesentium adipisci dignissimos? Iusto harum inventore soluta magnam esse amet? Obcaecati aliquam reprehenderit saepe ullam, doloribus natus nobis! Quaerat similique, quo voluptatibus deserunt recusandae ratione earum sequi dicta quas iste incidunt totam nam. Doloremque perspiciatis quam distinctio, vitae voluptatibus quos odit aliquam necessitatibus ipsa hic ea error in. Totam in aliquam quo voluptatem non magni earum doloribus nostrum unde! Nisi expedita temporibus ratione. Incidunt eum sint illum ullam asperiores beatae nihil eos? Dolore voluptate molestias dignissimos fuga dicta. Doloribus accusamus distinctio quia deleniti enim officia, culpa quidem, fugiat animi fuga ad iure perferendis! Ab provident sequi deserunt id eos maxime odit totam fugiat ratione. Magnam sint excepturi dicta nesciunt culpa ratione delectus voluptatem repudiandae. Veritatis minima ratione aliquid ipsum quibusdam hic dolorum nihil. Ipsum, repellendus sed mollitia deleniti voluptatum natus tenetur officiis ea non quas expedita, aperiam ducimus sequi eius voluptatibus laboriosam magnam nulla. Corrupti voluptate porro sapiente pariatur velit cum eaque beatae. Eos provident inventore nostrum libero dolores veniam dicta sunt ratione aspernatur expedita, minus iusto est atque ex. Fugit consectetur explicabo, maiores maxime possimus, perspiciatis sequi quaerat beatae obcaecati porro quibusdam? Reiciendis harum repellat nisi esse atque sit, aperiam, quas ipsa error quisquam adipisci excepturi quod earum ducimus. Illo unde similique modi qui! Fugiat ipsam magni quas praesentium non, repellat eaque? Doloribus officiis consectetur iste dolor hic distinctio ipsa aperiam nostrum provident recusandae earum minima delectus magnam, at quod, fugiat tenetur soluta quam excepturi eos est obcaecati, numquam inventore repellendus? Incidunt. Omnis, repellendus rem praesentium autem dolorum voluptas! Accusantium odio eum magnam quis, dolor ipsum suscipit mollitia blanditiis laboriosam in dicta dignissimos doloremque minus, facere deleniti harum enim ut nostrum placeat! Omnis laboriosam excepturi necessitatibus nihil eum! Dicta quam unde consequuntur eveniet provident quidem eaque recusandae cumque magnam iste. Dicta quisquam perspiciatis sint sapiente labore. Corrupti ipsa nostrum voluptatem asperiores tenetur? Corporis quasi necessitatibus iste! Laboriosam possimus tenetur dolorum unde maiores, vel et voluptas perspiciatis perferendis, ratione nam dignissimos, nesciunt amet incidunt voluptatem tempora maxime. Doloribus facere vitae commodi nam assumenda. Molestiae dolorem eos officiis nam dicta vero? Minus incidunt vero magni atque inventore eveniet sequi veniam? Deserunt exercitationem dolores quia provident mollitia dolor odio, nam cupiditate atque voluptas itaque rem! Fugiat, corporis totam porro modi eos magni expedita placeat maxime rerum. Blanditiis mollitia nemo, itaque laboriosam autem illo laborum facilis incidunt vel nulla distinctio nam molestias voluptas quaerat numquam soluta. Nam voluptatem expedita doloremque placeat, voluptate, accusantium consectetur voluptas nulla possimus, corporis at delectus tempore odio autem unde quas hic temporibus error quisquam exercitationem consequatur a saepe. Dolore, blanditiis laborum? Voluptate error, repellat neque porro quod fugiat aspernatur voluptas quidem voluptates dolores maiores, deleniti incidunt. Ullam mollitia esse beatae illo consequatur sed iusto provident, incidunt aliquam dolores a, nulla laudantium.
</div>
</div>
</div>
<div class="mdc-card problem">
<section class="mdc-card__primary">
<h1 class="mdc-card__title mdc-card__title--large">title here</h1>
<h2 class="mdc-card__subtitle">subtitle here</h2>
</section>
<section class="mdc-card__supporting-text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam nostrum nisi optio iusto excepturi sequi itaque. Vitae laudantium fugiat, id eius voluptates placeat labore magnam est saepe sapiente et molestias quaerat numquam excepturi illum dolores quam error, eaque rerum ea vero ipsum sequi. Sapiente adipisci reiciendis quod officia aliquam quidem praesentium cupiditate facere, magni nemo, asperiores, reprehenderit eveniet corporis eligendi et. Numquam voluptatem, consectetur. A harum quas, veritatis blanditiis, officia impedit voluptas laborum itaque delectus dolore explicabo aut, culpa iste sapiente repellat voluptate voluptates commodi dignissimos similique repudiandae. Nulla expedita atque dolore alias, facilis ipsam qui doloribus, iure quo animi.
</section>
<section class="mdc-card__actions">
<button class="mdc-button mdc-button--compact mdc-card__action">action 1</button>
<button class="mdc-button mdc-button--compact mdc-card__action">action 2</button>
</section>
</div>
.problem {
height: 350px;
width: 350px;
}
demo - the demo first row is full width no issues, the problem with second row with large supporting text, and third one with small supporting text
mdc-card - docs
how to deal with the width and height of the cards.
what the best way to handle this kind of issues
add only width demo
or
if all cards what to be in same height - add height, overflow: hidden; to mdc-card__supporting-text class demo
as of now ended like this
When the following CSS property is added to an image, the image still occupies the same space that it did when it was sized at 100%? Is there a way to make the text fill the space around this image?
transform: scale(0.2);
height: auto;
float: right;
That's not how transform works as I understand it. It only changes the appearance visually; the actual dimensions of the original object are maintained.
You would have to adjust the width/height of the image rather than use transform.
Demo in jsFiddle & StackSnippets:
div {
background: #bae5fc;
overflow: hidden;
margin-bottom: 25px;
width: 40%;
float: left;
margin: 2%;
padding: 4px;
}
img {
float: right;
display: block;
transition: all 0.5s ease;
max-width: 50%;
}
.trans:hover img {
transform: scale(0.5);
}
.dimen:hover img {
max-width: 25%;
}
<div class="trans">
<img src="https://picsum.photos/400/200" alt="" />
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas sequi fugit quis ipsam veniam dicta sint aliquid magnam deleniti doloribus rerum laudantium eveniet expedita ipsa ducimus vero fuga optio dolor hic adipisci minima dolorem nemo mollitia?
Autem repellat minus aliquam odit magni deserunt quibusdam voluptas repellendus ipsum recusandae rem nisi dolor sunt veritatis quas sapiente maiores consectetur sequi laudantium saepe. Recusandae deserunt quidem rerum quia enim possimus sed iure aliquid
a consectetur magnam molestias voluptas vero nisi adipisci sequi libero natus illum facere praesentium deleniti tempora nam quas ducimus corporis maiores placeat expedita est cupiditate ipsam modi cumque quos eveniet totam illo nemo harum commodi
odio aliquam quo eaque pariatur. Minima eum deleniti impedit!
</p>
</div>
<div class="dimen">
<img src="https://picsum.photos/400/200" alt="" />
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas sequi fugit quis ipsam veniam dicta sint aliquid magnam deleniti doloribus rerum laudantium eveniet expedita ipsa ducimus vero fuga optio dolor hic adipisci minima dolorem nemo mollitia?
Autem repellat minus aliquam odit magni deserunt quibusdam voluptas repellendus ipsum recusandae rem nisi dolor sunt veritatis quas sapiente maiores consectetur sequi laudantium saepe. Recusandae deserunt quidem rerum quia enim possimus sed iure aliquid
a consectetur magnam molestias voluptas vero nisi adipisci sequi libero natus illum facere praesentium deleniti tempora nam quas ducimus corporis maiores placeat expedita est cupiditate ipsam modi cumque quos eveniet totam illo nemo harum commodi
odio aliquam quo eaque pariatur. Minima eum deleniti impedit!
</p>
</div>
Is there any way to stick a footer to the bottom of the browser screen or right after the content (depending on which is longer) using CSS without knowing the size of the footer in advance?
Right now I am using the absolute positioning in a container that holds the footer and the content with container's min-height as 100%, but if I change the footer I find I must change the padding at the bottom of the container to match its height.
http://pixelsvsbytes.com/blog/2011/09/sticky-css-footers-the-flexible-way/
Summary:
For a site with a header, content area, and footer:
Set html, body {height: 100%;}
Set your body (or a wrapper div) to display: table; width: 100%; height: 100%;
Set your header, footer, and content area to display: table-row;. Give your header and footer height: 1px;, and give your content area height: auto;
The header and footer will both expand to fit their content. The content area will expand to fit the larger of its content, or the available space.
https://jsfiddle.net/0cx30dqf/
If you're willing to jump into the HTML5 future, you can use flexbox...
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1;
}
My more detailed answer to the same question: How to make a fluid sticky footer (full example: http://jsfiddle.net/n5BaR/)
Solved by flexbox: http://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/
What is Flexbox from MDN: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes
Try this!
Uses Flex!
NO FIXED HEIGHT, JAVASCRIPT OR TABLES
Expands when more content, and when there isn't it sticks to bottom
Note: Does not work with IE 9 & Below
*{
margin: 0;
padding: 0;
}
html, body{
height: 100%;
}
body{
min-height: 100%;
display: flex;
flex-direction: column;
}
.content{
flex: 1;
background: #ddd;
}
<body>
<header>
Header
</header>
<div class='content'>
This is the page content
<br>
PS. Don't forget the margin: 0 and padding: 0 to avoid scrollbars (this can be also put into the body css)
</div>
<footer>
Footer
</footer>
</body>
For an app with a responsive footer (i.e. changes height on resize), you can use jquery to dynamically adjust the padding of the bottom for the parent element. Adding onto this post: Keep Footer at Bottom
HTML:
<div class=”main-container”>
<header>
this is a header
</header>
<section>
this is content
</section>
<footer>
this is a footer
</footer>
</div>
CSS:
html,
body {
height: 100%;
position: relative;
}
.main-container {
min-height: 100vh; /* will cover the 100% of viewport */
overflow: hidden;
display: block;
position: relative;
padding-bottom: 100px; /* height of your footer */
}
footer {
position: absolute;
bottom: 0;
width: 100%;
}
CoffeeScript:
footerEventListener = ->
$(window).on "resize", ->
setFooterHeight()
setFooterHeight = ->
// get footer height in px
bottomPadding = $("footer").css("height")
$(".main-wrapper").css("padding-bottom", "#{bottomPadding}")
// init footer events
setFooterHeight()
footerEventListener()
Check out the CodePen here.
since no one knows the answer for sticky footer w/o knowing the height of it, using css (crosbrowser solution), i was forced to calculate it
jquery:
if( $(document).height() < $(window).height() )
{
$('#content').height
(
$(window).height - $('#footer').height()
);
}
html structure:
<div id="content"></div>
<div id="footer"></div>
I think the best way is just add a class to your footer. Javascript will do the rest.
//This Pen is By Mohammad Abdus Salam
//portfolio.codeexposer.com
var footerHeight = $('footer.fixed_footer').height();
if($('footer').hasClass('fixed_footer')){
$( "section" ).last().css({
"margin-bottom": footerHeight + 'px'
});
}
#import url('https://fonts.googleapis.com/css?family=Raleway:400,700,800');
body{
margin: 0;
padding: 0;
text-align:center;
font-family: 'Raleway', sans-serif;
line-height: 30px;
}
section{
padding-top: 80px;
padding-bottom: 80px;
border-bottom:1px solid #ddd;
background: #ffffff;
z-index: 9;
}
h1{
font-size: 48px;
font-weight: 800;
text-transform: capitalize;
}
a{
text-decoration: none;
}
.container{
width: 700px;
display: inline-block;
box-sizing:border-box;
padding-left: 30px;
padding-right: 30px;
}
.logo{
height: 80px;
width: 80px;
display: inline-block;
}
.footer_top{
border-bottom: 1px solid #777;
padding-bottom: 60px;
}
.logo img{
width: 100%;
height: 100%;
}
.footer_bottom {}
.footer_bottom p{
color:#aaa;
}
.footer_top{
padding-top: 100px;
}
.footer_bottom p a{
color:#158;
}
footer{
width: 100%;
left: 0;
bottom:0px;
z-index: -1;
background: #222222;
}
.fixed_footer{
width: 100%;
position:fixed;
left: 0;
bottom:0;
z-index: -99;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section>
<div class="container">
<h1>This is Banner</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dicta fugiat amet explicabo illum, soluta quisquam minus consectetur totam omnis non veniam possimus atque nisi earum aperiam quasi ut, quas temporibus minima eius, rem repellat. Sed eius quae eum qui odio molestiae porro. Aut ab impedit recusandae odit at? Quas ab laboriosam culpa, rerum nobis consequatur voluptate nemo expedita voluptatem porro aliquid dolorum maiores autem dolorem unde mollitia quae nam fugit. At quibusdam error consequatur suscipit? Necessitatibus asperiores, doloribus accusamus odit quidem deserunt cum reiciendis aliquid ipsam alias distinctio recusandae earum nam nulla ratione quia architecto beatae nihil expedita blanditiis animi sit, exercitationem tempora placeat. Accusamus ad odio natus, pariatur sed tenetur debitis. Soluta distinctio velit beatae asperiores eligendi? Neque quasi doloremque cumque placeat ea sapiente recusandae harum veritatis corrupti! Ad, alias, at cum debitis sit obcaecati vitae nesciunt aliquam nulla laudantium ut sunt veniam distinctio mollitia sed neque qui sint repudiandae adipisci deserunt perspiciatis consectetur optio blanditiis? Unde distinctio dolorum laboriosam dolorem ex in, porro facilis ad velit beatae excepturi ut aspernatur! At sunt tempora, placeat veritatis excepturi hic repellendus pariatur dolores deserunt cupiditate exercitationem laborum itaque sapiente nostrum non, quibusdam explicabo velit dolorum cum. Maiores, accusamus! Iusto, rem doloribus?
</p>
</div>
</section>
<section>
<div class="container">
<h1>This is About</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dicta fugiat amet explicabo illum, soluta quisquam minus consectetur totam omnis non veniam possimus atque nisi earum aperiam quasi ut, quas temporibus minima eius, rem repellat. Sed eius quae eum qui odio molestiae porro. Aut ab impedit recusandae odit at? Quas ab laboriosam culpa, rerum nobis consequatur voluptate nemo expedita voluptatem porro aliquid dolorum maiores autem dolorem unde mollitia quae nam fugit. At quibusdam error consequatur suscipit? Necessitatibus asperiores, doloribus accusamus odit quidem deserunt cum reiciendis aliquid ipsam alias distinctio recusandae earum nam nulla ratione quia architecto beatae nihil expedita blanditiis animi sit, exercitationem tempora placeat. Accusamus ad odio natus, pariatur sed tenetur debitis. Soluta distinctio velit beatae asperiores eligendi? Neque quasi doloremque cumque placeat ea sapiente recusandae harum veritatis corrupti! Ad, alias, at cum debitis sit obcaecati vitae nesciunt aliquam nulla laudantium ut sunt veniam distinctio mollitia sed neque qui sint repudiandae adipisci deserunt perspiciatis consectetur optio blanditiis? Unde distinctio dolorum laboriosam dolorem ex in, porro facilis ad velit beatae excepturi ut aspernatur! At sunt tempora, placeat veritatis excepturi hic repellendus pariatur dolores deserunt cupiditate exercitationem laborum itaque sapiente nostrum non, quibusdam explicabo velit dolorum cum. Maiores, accusamus! Iusto, rem doloribus?
</p>
</div>
</section>
<section>
<div class="container">
<h1>This is Service</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dicta fugiat amet explicabo illum, soluta quisquam minus consectetur totam omnis non veniam possimus atque nisi earum aperiam quasi ut, quas temporibus minima eius, rem repellat. Sed eius quae eum qui odio molestiae porro. Aut ab impedit recusandae odit at? Quas ab laboriosam culpa, rerum nobis consequatur voluptate nemo expedita voluptatem porro aliquid dolorum maiores autem dolorem unde mollitia quae nam fugit. At quibusdam error consequatur suscipit? Necessitatibus asperiores, doloribus accusamus odit quidem deserunt cum reiciendis aliquid ipsam alias distinctio recusandae earum nam nulla ratione quia architecto beatae nihil expedita blanditiis animi sit, exercitationem tempora placeat. Accusamus ad odio natus, pariatur sed tenetur debitis. Soluta distinctio velit beatae asperiores eligendi? Neque quasi doloremque cumque placeat ea sapiente recusandae harum veritatis corrupti! Ad, alias, at cum debitis sit obcaecati vitae nesciunt aliquam nulla laudantium ut sunt veniam distinctio mollitia sed neque qui sint repudiandae adipisci deserunt perspiciatis consectetur optio blanditiis? Unde distinctio dolorum laboriosam dolorem ex in, porro facilis ad velit beatae excepturi ut aspernatur! At sunt tempora, placeat veritatis excepturi hic repellendus pariatur dolores deserunt cupiditate exercitationem laborum itaque sapiente nostrum non, quibusdam explicabo velit dolorum cum. Maiores, accusamus! Iusto, rem doloribus?
</p>
</div>
</section>
<section>
<div class="container">
<h1>This is Portfolio</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dicta fugiat amet explicabo illum, soluta quisquam minus consectetur totam omnis non veniam possimus atque nisi earum aperiam quasi ut, quas temporibus minima eius, rem repellat. Sed eius quae eum qui odio molestiae porro. Aut ab impedit recusandae odit at? Quas ab laboriosam culpa, rerum nobis consequatur voluptate nemo expedita voluptatem porro aliquid dolorum maiores autem dolorem unde mollitia quae nam fugit. At quibusdam error consequatur suscipit? Necessitatibus asperiores, doloribus accusamus odit quidem deserunt cum reiciendis aliquid ipsam alias distinctio recusandae earum nam nulla ratione quia architecto beatae nihil expedita blanditiis animi sit, exercitationem tempora placeat. Accusamus ad odio natus, pariatur sed tenetur debitis. Soluta distinctio velit beatae asperiores eligendi? Neque quasi doloremque cumque placeat ea sapiente recusandae harum veritatis corrupti! Ad, alias, at cum debitis sit obcaecati vitae nesciunt aliquam nulla laudantium ut sunt veniam distinctio mollitia sed neque qui sint repudiandae adipisci deserunt perspiciatis consectetur optio blanditiis? Unde distinctio dolorum laboriosam dolorem ex in, porro facilis ad velit beatae excepturi ut aspernatur! At sunt tempora, placeat veritatis excepturi hic repellendus pariatur dolores deserunt cupiditate exercitationem laborum itaque sapiente nostrum non, quibusdam explicabo velit dolorum cum. Maiores, accusamus! Iusto, rem doloribus?
</p>
</div>
</section>
<section>
<div class="container">
<h1>This is Banner</h1>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dicta fugiat amet explicabo illum, soluta quisquam minus consectetur totam omnis non veniam possimus atque nisi earum aperiam quasi ut, quas temporibus minima eius, rem repellat. Sed eius quae eum qui odio molestiae porro. Aut ab impedit recusandae odit at? Quas ab laboriosam culpa, rerum nobis consequatur voluptate nemo expedita voluptatem porro aliquid dolorum maiores autem dolorem unde mollitia quae nam fugit. At quibusdam error consequatur suscipit? Necessitatibus asperiores, doloribus accusamus odit quidem deserunt cum reiciendis aliquid ipsam alias distinctio recusandae earum nam nulla ratione quia architecto beatae nihil expedita blanditiis animi sit, exercitationem tempora placeat. Accusamus ad odio natus, pariatur sed tenetur debitis. Soluta distinctio velit beatae asperiores eligendi? Neque quasi doloremque cumque placeat ea sapiente recusandae harum veritatis corrupti! Ad, alias, at cum debitis sit obcaecati vitae nesciunt aliquam nulla laudantium ut sunt veniam distinctio mollitia sed neque qui sint repudiandae adipisci deserunt perspiciatis consectetur optio blanditiis? Unde distinctio dolorum laboriosam dolorem ex in, porro facilis ad velit beatae excepturi ut aspernatur! At sunt tempora, placeat veritatis excepturi hic repellendus pariatur dolores deserunt cupiditate exercitationem laborum itaque sapiente nostrum non, quibusdam explicabo velit dolorum cum. Maiores, accusamus! Iusto, rem doloribus?
</p>
</div>
</section>
<footer class="fixed_footer">
<div class="container">
<div class="footer_top">
<a class="logo" href="portfolio.codeexposer.com">
<img src="https://lh3.googleusercontent.com/-a700z77yIxk/AAAAAAAAAAI/AAAAAAAAABM/RzvY_qm9KQY/s512-p/photo.jpg" alt="">
</a>
</div>
<div class="footer_bottom">
<p>
All Rights Reserved By Mohammad Abdus Salam
</p>
</div>
</div>
</footer>
Take a look at this, cssstickyfooter, it works great in any browser.
Update: This is from 2010, might not be relevant with current standards