creating set of 'cells' that have a fixed width and aligned height - css

I'm trying to basically blocks that are adjacent to each other and have a defined width. However, I want the height of the cells to line up with other cells in the row.
Please see the following codepen for the code to play around with:
http://codepen.io/thinkbonobo/pen/EKdxgP
.cm-table-frame {}
.table-frame-row {}
.table-frame-cell {
border: 1px solid lightskyblue;
/* display: table-cell; */
display: inline-block;
vertical-align: top;
width: 100px;
}
I've tried two methods:
display:table-cell - I like this method as it sets the height properly but I can't seem to figure out how to set the width.
display: inline-block - This method lets me easily set the width but I can't set the height to dynamically match the blocks in the line/row. some cells may have 1 line some cells may have 5 lines but they all should be the same height for a given row.
Your advice would be much appreciated!

if you want to use display: table-cell, the set the max-width and min-width:
.table-frame-cell {
border: 1px solid lightskyblue;
display: table-cell;
vertical-align: top;
min-width: 100px;
max-width: 100px;
}
or
if you want to use display: inline-block, you need to set the height of the elements:
.table-frame-cell {
border: 1px solid lightskyblue;
display: inline-block;
vertical-align: top;
width: 100px;
height: 100px;
}

It's generally adviseable not to use tables for layouts, and display:table-cell will validate fine, but in the end has the same issues (as also discussed in the provided link).
If using CSS Level 3 is not an issue, you can use flexboxes for this (Flexbox Browser Compatibility), like this:
.flex-container {
background-color: green;
display: flex;
}
.flex-container > div {
background-color: orange;
flex: 1;
padding: 15px 20px;
margin-right: 20px;
max-width: 120px;
}
<div class="flex-container">
<div>Very short text.</div>
<div>This is a lot of text, even though it's probably very little compared to what you're trying to do, as stack's preview window is comfortably narrow.</div>
<div>Another bit of text for flavor.</div>
</div>
The only solution that comes to mind that works in browsers without CSS3 implementation is to use Javascript or jQuery to set all boxes to the same height.

Option #1
(For old browsers support)
use display:table/table-cell along with width, something like this:
body {
margin: 0
}
.table {
width: 100%;
display: table;
}
.cell {
width: 25%;
display: table-cell;
}
.cell:nth-child(odd) {
background: red
}
.cell:nth-child(even) {
background: green
}
<div class="table">
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
</div>
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</div>
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
</div>
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</div>
</div>
Option #2
(If you don't mind NOT supporting old browsers)
you can use CSS3 flexbox
body {
margin: 0
}
.table {
width: 100%;
display: flex;
}
.cell {
width: 25%;
flex:1
}
.cell:nth-child(odd) {
background: red
}
.cell:nth-child(even) {
background: green
}
<div class="table">
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
</div>
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</div>
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
</div>
<div class="cell">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</div>
</div>

Related

CSS-Grid begin with next column

I have a 3 column css grid with content. I try to make it like that:
If content is too much, it should go to next column.
But I couldn't make it work. Do you have any hints?
.details {
background: #000;
color: #fff;
width: 100%;
height: 100%;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(1, 100%);
grid-column-gap: 2px;
grid-row-gap: 2px;
.detail {
text-align: left;
padding: 10px;
}
}
You may use column CSS and floating pseudo elements to push content at the most towards the first columns :
possible examples to run and test in fullpage :
3 columns from column-count
body {
margin: 0;
}
div {
column-count: 3;
}
div p::before {
content: '';
padding-bottom: 90vh;
float: left;
}
/* extra styling */
div {
column-rule: double gray;
margin: 1em;
border: solid;
box-sizing: border-box;
background: rgb(243, 241, 121);
}
div h1,
p {
width: 80%;
margin: 1em auto;
text-indent: 1em;
text-align: justify;
}
<div>
<h1>Column CSS</h1>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p>
or setting column-width instead column-count for a responsive behavior:
body {
margin: 0;
}
div {
column-width: 18em;
}
div p::before {
content: '';
padding-bottom: 90vh;
float: left;
}
/* extra styling */
div {
column-rule: double gray;
margin: 1em;
border: solid;
box-sizing: border-box;
background: rgb(243, 241, 121);
}
div h1,
p {
width: 80%;
margin: 1em auto;
text-indent: 1em;
text-align: justify;
}
<div>
<h1>Column CSS</h1>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p>
probably not as perfect as you imagine : codepen demo to play with

Put footer at buttom without hiding page content when resizing

I want the footer to be stuck at the buttom of the page, the I added: buttom:0px; and made it position:fixed;, but then when I resize window the footer hides other stuff (I want it stay at bottom):
enter image description here
I also tried with position:static; but then it changes the selected height:
enter image description here
here code:
footer {
font-size: 14px;
color: gray;
border-top: 1px solid #2672fb;
bottom: 0px;
width: 100%;
height: 2.5rem;
position:static;
}
<body>
<div>
...
</div>
<footer>
<p>Lorem ipsum dolor ...</p>
</footer>
</body>
There was a wrapping element that held everything except the footer. It had a negative margin equal to the height of the footer.
!-- begin snippet: js hide: false console: true babel: false -->
html, body {
height: 100%;
margin: 0;
}
.wrapper {
min-height: 100%;
/* Equal to height of footer */
/* But also accounting for potential margin-bottom of last child */
margin-bottom: -50px;
}
.footer,
.push {
width:100%;
height:100px;
}
.footer{
background-color:yellow;}
<!-- language: lang-html -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<button id="add">Add Data</button>
<div class="wrapper">
<div class="push">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>
</div>
<footer class="footer"></footer>
</body>

How do I show ellipsis for multiline text? [duplicate]

This question already has answers here:
Limit text length to n lines using CSS
(17 answers)
Applying an ellipsis to multiline text [duplicate]
(23 answers)
Closed 5 years ago.
I have this style
.ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
which renders like this:
If i remove white-space: nowrap; I get like this:
But I want the ellispes from 3rd line(or before only if text is shorter)
Well there are multiple ways to do so, check the snippet below for certain ones.
#import url(http://fonts.googleapis.com/css?family=Open+Sans);
body {
padding: 20px;
font: 1.2em/1.2em 'Open Sans', sans-serif;
}
.module {
width: 250px;
margin: 0 0 1em 0;
overflow: hidden;
}
.module p {
margin: 0;
}
.line-clamp {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
.fade {
position: relative;
height: 3.6em; /* exactly three lines */
}
.fade:after {
content: "";
text-align: right;
position: absolute;
bottom: 0;
right: 0;
width: 70%;
height: 1.2em;
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
}
.last-line {
height: 3.6em; /* exactly three lines */
text-overflow: -o-ellipsis-lastline;
}
.ftellipsis {
height: 3.6em;
}
h1 {
margin: 0 0 1em 0;
}
h2 {
font-size: 1.2em;
}
<h1>Line Clampin'</h1>
<h2>Weird WebKit Flexbox Way</h2>
<div class="module line-clamp">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>
<h2>Fade Out Way</h2>
<div class="module fade">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>
<h2>Opera Overflow Way</h2>
<div class="module last-line">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>
<h2>ftellipsis Way</h2>
<div class="module js ftellipsis" id="ftellipsis">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>
Also check out this link: https://css-tricks.com/line-clampin/

WordPress: Make sidebar match height of main content area

I'm taking an old WordPress site I designed years ago and now I'm making it responsive. Problem is I have a main content area on the site and a sidebar div and the issue is the sidebar div is not expanding down the entire height of the #contentWrap div on this site. I've already tried adding 100% heights to the #page, #contentWrap and #sidebar, all to no avail. On the old site design, I did a trick using background images, but that realistically won't work with a responsive desig.Any idea how I can make this work?
Site in question: http://destinationbeershow.com/episode-guide/
Code:
<div id="contentWrap">
<div id="content" class="narrowcolumn">
</div>
<div id="sidebar">
</div>
</div>
CSS:
#contentWrap {
width: 856px;
height: 100%;
}
#page {
background-color: #ac4f23;
text-align: left;
margin: 0px auto;
width: 856px;
height: 100%;
}
.narrowcolumn {
background-color: #ac4f23;
float: left;
padding: 0;
margin: 0;
width: 640px;
color: #FFF;
}
#sidebar {
padding: 16px 8px 10px 8px;
float: right;
width: 160px;
height: 100%;
font: 11px 'Lucida Grande', Verdana, Arial, Sans-Serif;
border-left: 10px solid #fff;
background-color: #ebd299;
}
You can make everything collapse below your 856px hard width and use percentages inside that, or you can fiddle with the math. You also don't mention how you are doing your media queries, I'm assuming mobile first, which means that IE8 won't see the columns unless you learn more about that or use desktop first responsive design, however to make the columns the same height no matter what is inside either, here's one way (display:table/display:table-cell) which stacks below the 856px width you have on your #page. Use percentages.
DEMO: http://jsbin.com/biyito/1/
CSS:
.narrowcolumn {
background-color: #ac4f23;
color: #fff;
box-sizing: border-box;
padding: 10px 20px;
}
#sidebar {
padding: 10px 20px;
border-top: 10px solid #fff;
background-color: #ebd299;
box-sizing: border-box;
}
#media (min-width:856px) {
#contentWrap {
width: 100%;
display: table;
}
.narrowcolumn {
width: 80%;
display: table-cell;
}
#sidebar {
display: table-cell;
padding: 10px;
width: 20%;
border-left: 10px solid #fff;
border-top: 0px;
}
}
HTML
<div id="contentWrap">
<div id="content" class="narrowcolumn">
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
</div>
<div id="sidebar">
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
</div>
</div>
the #contentWrap has no height... i tried I really tried to make it responsive with your content but it just doesn't work. For now if you define the height of it, the bar will be end to end.
In that page the height would be 1361px
If you can place the content in http://jsfiddle.net/ is much more easy to find and get to the problem.

Divs will not float

I been trying every way possible to try and float the sidebar to the left and have it fit beside the content div, but it seems IMPOSSIBLE for me. Please help.
HTML:
<div class="index-page">
<img src="images/hosting-header.png" width="458" height="179" alt="Hosting Header">
<h1> Welcome to Elektrik Host! </h1>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante.
Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris
placerat eleifend leo.</p>
<h1> A little about us </h1>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante.
Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris
placerat eleifend leo.</p>
</div><!-- //index-page -->
<div class="sidebar">
<img src="images/sidebar-stickers.png" width="150" height="634" alt="Sidebar Stickers">
</div><!-- //.sidebar -->
CSS:
.index-page { color: #000; width: 462px; }
.sidebar { float: right; width: 200px; }
clearfix :
.clearfix:after {
content: ".";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
I always find it easier to put the float-ing content ahead of the content that makes way for it, so I switched your sidebar to come ahead of the index-page div, and used the following CSS:
.sidebar {
width: 200px;
float: left;
}
Demo over at JS Bin.
.sidebar { float: left; width: 200px; } not right
To make them beside:
- index-page also need floatleft too index-page{ float: left;} (FF need, IE not)
- move sidebar to before of index-page
You can follow this tutorial: http://css.maxdesign.com.au/floatutorial/index.htm
CSS CODE
.floatright { float: right; }
HTML CODE
<p>
<img class="floatright" src"images/sidebar-stickers.png" width="150" height="634" alt="Sidebar Stickers">
<p>
you dont need to do just apply the class straight to the image.
PK

Resources