I have this code:
html:
<div class="tile">
<h3>short</h3>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
<div class="tile">
<h3>longLongLong longLongLong longLongLong</h3>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
css:
.tile{
height: 300px;
width: 200px;
background: #cecece;
float: left;
margin: 0 10px 0 0;
}
.tile h3{
min-height: 20px;
max-height: 61px;
display: inline-block;
overflow: hidden;
}
.tile .content{
height: 162px;
overflow: hidden;
margin: 0 10px;
}
fiddle:
and I get this layout
but I need to get something like next image, without using js.
Can that be solved?
Solving this problem is pretty simple with flexbox.
By creating a column flex container the flex items stack vertically. You can then apply
flex: 1
to the text box (.content
) which makes it expand the full available height of the container.HTML
CSS
DEMO
Note that flexbox is supported by all major browsers, except IE 8 & 9. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add all the prefixes you need, use Autoprefixer. More browser compatibility details in this answer.
Using Ellipsis (...)
If you want to apply ellipsis to a single line of text, CSS makes that somewhat easy with the
text-overflow
property. It's still a bit tricky (due to all the requirements), buttext-overflow
makes it possible and reliable.If, however, you want to use ellipsis on multi-line text – as would be the case here – then don't expect to have any fun. CSS doesn't provide a single property for doing this, and the workarounds are hit and miss. For details and methods see my answer here: Applying Ellipsis to Multiline Text
Well, pretty easy... make
<div class="move"></div>
and put your h3 into it like:<div class="move"><h3>Short</h3></div>
now style that move div like so:it workd, you are done :)
PS: make it with both of your h3s :)
well, there is a code:
css:
html:
Try this use extra
div
with wrap.h3
&div.content
tag are wrapped by extradiv
and some css to be change as following:you can resolve by the
flexbox
Flexible Box Layout Module:http://jsfiddle.net/57yLgxsx/
This example works on Chrome you can check for the browser compability on caniuse.com and then add the correct prefixes.
It depends on who you want to ensure compatibility ( last 2 vorsion of all browser, mobile or desktop or both ).
keep in mind that there are two versions of flexbox, the "old" and the "new". What I wrote above is the new.
This link can clarify some ideas https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Depending on browser support you can use
flex
.The container would need:
Here's a quick demo with example markup:
http://jsbin.com/xuwina/3/edit?html,css,output
I would try another aproach. Using jquery you can calculate on window load the
height
of the highesth3
and then, apply that height to all yourh3
inside yourtiles
.I know you asked for a pure css solution, so it's ok if I don't get any credit, but I think this answer may be usefull for other users with the same problem so that's why I wrote it.
Something like this:
As you can see in this JSFIDDLE (notice I removed the fixed
max-height
you added to the header and add a thirdtile
with a "very long text" so you can check the exmaple better.