How to push this image upwards into a paragraph - html

I am developing an application that lets businesses post to a noticeboard. Each post is a div of 320px width. The content of the post is in paragraphs and at the foot of the post, I am putting the business' logo, as follows:
<div class="post">
<p>Lorum ipsum ...</p>
<p>Lorum ipsum ...</p>
<img src="...">
</div>
The logo doesn't look very good just plonked at the bottom of the post, so now I am trying to visually integrate it better. I would like to float it to the right, and push it up, say, 30px, and have the text flow around it.
I have tried floating right and setting a negative top margin, but this just put the image under (or over) the paragraph text. I tried putting it inside the ending p tag, with similar results. I also tried changing the display to inline-block (instead of floating it), but got similar results again.

By definition of floats that is not possible.
Thus you have two options:
A. To reorder DOM elements (by JS) and so you will have rest of the text wrapping around that floating image:
<div class="post">
<img src="..." float="right">
<p>Lorum ipsum ...</p>
<p>Lorum ipsum ...</p>
</div>
B. Drop the text wrapping requirement. In this case you can use you markup as it is now:
<div class="post">
<p>Lorum ipsum ...</p>
<p>Lorum ipsum ...</p>
<img src="...">
</div>
but with these styles:
.post { position: relative; }
.post > p { margin-right: XXXpx; /* room for the image */ }
.post img { position:absolute; right:0; top:0 } /* move it to top/right corner */
There are no other options with modern CSS : either to reorder DOM or to drop text wrapping.

You are probably going to need to move the image up to the top. Once you do that getting things to fall into place will be a snap. I added a code snippet below. I used a square div to stand in for an image but the concept is the same for real images.
.img {
display: block;
width: 50px;
height: 50px;
float: left;
background: blue;
margin: 0 10px 10px 0;
}
<div>
<div class="img"></div>
<p>This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth.</p>
<p>This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth.</p>
</div>
Alternatively, if you must have the image last for some reason there will not be a good way to have the text wrap under the image. But you can djust the img to the top like so:
.container {
position: relative;
}
p {
margin-left: 60px;
}
.img {
background: blue;
width: 50px;
height: 50px;
position: absolute;
top: 0;
left: 0;
}
<div class="container">
<p>This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth.</p>
<p>This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth.</p>
<div class="img"></div>
</div>
On an aside, you can also use js to reposition the image after the document has already loaded as well.

Try applying .css to the image directly using a class tag.
<img class="imgleft" src="image.jpg">
and in your .css file something like this:
.imgleft {
float: left;
border: 1px solid #90b905;
margin: 5px 10px 10px 15px;
padding: 5px;
}

If the size of the image is known before hand, you can reserve space for the image with a pseudo element
.post {
width: 320px;
border: 1px solid red;
position: relative;
}
.post:before {
content: "";
width: 80px;
height: 80px;
float: right;
background-color: lightgreen;
}
.likeimg {
width: 40px;
height: 40px;
background: red;
top: 20px;
right: 20px;
position: absolute;
}
<div class="post">
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 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."</p>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 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."</p>
<div class="likeimg"></div>
</div>
The green box is the pseudo element (made green just for demo purposes), that in the dom is in the appropiate place to make it float. (before the ps)
Then, the image if absolutely positioned in the reserved place

.post {
width: 320px;
border: 1px solid red;
position: relative;
}
p
{
text-align:justify;
word-break:break-all;
}
.post:before {
content: "";
width: 80px;
height: 80px;
float: right;
}
.likeimg {
width: 40px;
height: 40px;
background: red;
top: 20px;
right: 20px;
position: absolute;
}
<div class="post">
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 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."</p>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 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."</p>
<div class="likeimg"></div>
</div>
i hope this may help you

This is the simple one I think. Just place your image inside the first <p> tag, as in:
<div class="post">
<p><img src="..."> Lorum ipsum ...</p>
<p>Lorum ipsum ...</p>
</div>
Then floating it to the right and push it up and have the text flow around it.
But before it, add new class selector inside the image
, say, .imgfloat. so, that will be like this:
<div class="post">
<p><img class="imgfloat" src="...." alt=""/> Lorum ipsum ...</p>
<p>..Lorum ipsum ......</p>
</div>
Next, add the property and the value of the selector, like this:
.imgfloat{
float:right;
margin-left:17px;
margin-top:1px;
margin-right:1px;
margin-bottom:7px;
text-align:justify;
}
So, the display would be like this:
For Demo, visit Here.
Hope this helps you.

Float the image right, and everything else left.
.post p {
float: left;
clear: left;
}
.post img {
float: right;
}
See Fiddle
If your logos are relatively small, it might be enough just to float the last non-image element left, e.g.
.post p:last-child {
float: left;
}

You could try floating the image (I've used a div to simulate the image in the sample below) before the last paragraph and then adding float:none to the last paragraph:
<div style="width:320px;">
<div style="float:left; width:30%; height:100px; background:#ebebeb; margin:10px 10px 0 0"></div>
<p style="float:none">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis feugiat sem quis erat tincidunt facilisis. In posuere urna at ex porttitor, id maximus ex aliquam. Morbi orci lectus, dapibus venenatis suscipit ac, mattis in lectus. Integer a feugiat ex.
Donec non nibh sit amet mi lacinia dignissim. Mauris nulla turpis, volutpat a iaculis ac, elementum vel ipsum. Nulla sed sem sagittis, posuere neque eget, fermentum ex. Etiam mollis pharetra lorem, id tincidunt nisi scelerisque in. Integer et leo
laoreet, facilisis sapien a, vulputate urna. Vestibulum at interdum est, sit amet tincidunt neque. Donec luctus justo vel justo pellentesque, in congue.</p>
</div>

The layout you want to achieve can be done only using Javascript, as in this example where we use jQuery WrapLines to divide paragraph in lines that have class line and CSS:
.post p:last-of-type .line:nth-last-of-type(2):before {
content: ' ';
display: block;
width: 105px;
height: 35px;
float: right;
}
.post img {
float: right;
position: relative;
bottom: 45px;
}
JS part is simple:
$(".post p").wraplines({
lineClassPrefix: 'line line_'
});
It is still not perfect, because after adding the block the text may expand for one line more.
If you want a pure CSS solution, than simply float last paragraph left, as in this example using following CSS:
.post p {
overflow: hidden;
margin: 0 0 10px;
}
.post p:last-of-type {
float: left;
width: calc(100% - 105px);
}
but text does not wrap around and this may look good only if paragraph is short or if the logo is higher. Here is an example with square logo on the left.

Using this post as a reference, maybe this is what you're looking for:
#content {
position: relative;
}
.text {
float: left;
width: 400px;
text-align: justify;
}
.floatingBox {
width: 50px;
height: 50px;
background-color: blue;
}
#lfb {
float: right;
margin: 10px 0px 0px 10px;
}
And in the html:
<div id="content">
<div class="text">This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth.<div id="lfb" class="floatingBox"></div>This is some text and so on and so This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth. This is some text and so on and so forth.</div>
</div>

I've got a semi-solution, which works by moving the image down relative from the top of the last paragraph.
body {
width: 320px;
margin: 0 auto;
}
.offset-image {
float: left;
height: 80px;
width: 1px;
margin-left: -1px;
}
img {
display: block;
float: right;
clear: left;
}
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi numquam, dignissimos odit expedita. Blanditiis repudiandae expedita quos reiciendis natus consequuntur deleniti harum quisquam quidem, dignissimos accusamus laudantium, facere ullam commodi!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi numquam, dignissimos odit expedita. Blanditiis repudiandae expedita quos reiciendis natus consequuntur deleniti harum quisquam quidem, dignissimos accusamus laudantium, facere ullam commodi!</p>
<div class="offset-image"></div>
<img src="http://placehold.it/140x100">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi numquam, dignissimos odit expedita. Blanditiis repudiandae expedita quos reiciendis natus consequuntur deleniti harum quisquam quidem, dignissimos accusamus laudantium, facere ullam commodi!
</p>
We use an extra div.offset-image to push the image down. By styling it with float: left; width: 1px; and margin-left: -1px; to make sure the div itself isn't visible. On the image element, we provide a clear: left; so it's actually forced to move the height of the div.offset-image down.
The last paragraph item comes after the div.offset-image and the image element in the hmtl structure and will therefore naturally flow around these two floated elements.
You could improve this by adding a little bit of javascript into the mix. Set the height of the div.offset-image to the height of the last paragraph minus an x amount of pixels, to always render your image at the same distance from the bottom of the last paragraph.

Another fix can be to move the image before the paragraphs in the document flow, assign it float:right and a fixed dimension,
and you're done!!
.post {
width: 320px;
border: 1px solid magenta;
position: relative;
}
.likeimg {
width: 66px;
height: 66px;
background: yellow;
float:right;
display:inline-block;
margin:15px;
}
<div class="post">
<div class="likeimg"></div>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 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."</p>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing 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."</p>
</div>

Related

Nested divs height and overflow

Suppose I have some fixed-size container and I want all elements to fit inside, but I don't know all heights of inside elements. Some element has lots of text, so I set overflow: hidden. But this element ignores the height of container and just stretches to fit contents. How do I do it right?
Edit: if I set overflow on my container, overflowing text will be hidden, but bottom padding will be ignored (see 2nd snippet). How do I cut text 5px from the bottom border, so all sides look equal?
.outer {
width: 200px;
height: 200px;
}
.inner {
padding: 5px;
background-color: #ccc;
height: 150px;
border: 1px solid black;
}
.text {
overflow: hidden;
}
<div class="outer">
<div class="inner">
<span style="color: red">Some element so we can't make text 100% height</span>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing 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>Some other text</div>
</div>
.outer {
width: 200px;
height: 200px;
}
.inner {
padding: 5px;
overflow: hidden;
background-color: #ccc;
height: 150px;
border: 1px solid black;
}
.text {
overflow: hidden;
}
<div class="outer">
<div class="inner">
<span style="color: red">Some element so we can't make text 100% height</span>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing 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>Some other text</div>
</div>
You can nest an additional div inside of .inner (I used .inner2 in this example, you can come up with a more meaningful name! :) ).
Basically, you need to separate the background/border from the container that will control the overflow (as you're right, overflow goes to the edge of the element, it doesn't care about padding).
Just an example, but I added a second div (.inner2) inside of .inner and moved the the height and overflow rules to that one instead. The background/padding/border stay put.
Edit: Added a lime border to inner2 to better illustrate what's happening.
.outer {
width: 200px;
height: 200px;
}
.inner {
padding: 5px;
background-color: #ccc;
border: 1px solid black;
}
.inner2 {
height: 150px;
overflow: hidden;
border: 1px solid lime;
}
.text {
}
<div class="outer">
<div class="inner">
<div class="inner2">
<span style="color: red">Some element so we can't make text 100% height</span>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing 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>
<div>Some other text</div>
</div>

Div overlaps text in mobile preview

I have a div block which contains an image and text:
<div style="position: relative; margin-bottom: 90px;"><img src="https://cdn2.hubspot.net/hubfs/4022333/Blog/TOFU/quote.png" style="width: 112px;">
<div style="position: absolute; top: 50px; left: 78px;">
<p style="font-family: AvenirLight; color: #74818a; font-size: 36px; line-height: 45px; font-style: italic;">“Enabling understanding means being able to communicate effectively”</p>
</div>
</div>
I've applied margin-bottom: 90px; on the parent div to create a gap between the div and any p tags which may be below it.
It works fine on full display, but on mobile, it looks like this:
As you can see, it's overlapping the following p tags after the div. How can I fix this? Ideally I want a 20px gap between the parent div and anything outside the div.
Edit:
I feel like my approach is wrong. I.e. if I remove margin-bottom: 90px; from the code above, the div will still overlap any following p tags:
The reason why other elements are overlapping your quote element, is because the element which is primarily deciding the height of the element (the div which contains the paragraph) is having an absolute position. An absolute positioned element is no longer part of the parent (unless the parent has a relative position). So, in this case, because the div with the paragraph is no longer 'part' of the parent, the parent will only have a height based on the static/relative positioned elements. Which is the image.
As a solution you can switch the absolute position of your p element to the img element. You know the width and the height of the image, so you can set a padding for your paragraph element. In this case the height of the parent div (which is called .quote-wrapper in my example) will have the correct height so elements above or below .quote-wrapper won't overlap your element.
.quote-wrapper {
padding: 40px 0;
}
.quote-wrapper .quote-image {
width: 120px;
height: 100px;
position: absolute;
}
/* Set position to relative so the element won't be overlapped by the image */
.quote-wrapper > p {
font-family: AvenirLight;
color: #74818a;
font-size: 36px;
line-height: 45px;
font-style: italic;
padding: 80px 0 0 80px;
margin: 0;
position: relative;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing 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.</p>
<div class="quote-wrapper">
<img src="https://cdn2.hubspot.net/hubfs/4022333/Blog/TOFU/quote.png" class="quote-image" />
<p>
“Enabling understanding means being able to communicate effectively”
</p>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing 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.</p>
You can put margin-top inside the tag p. I recommend that you put an id or class for each tag (div,p...), to make the structure easier and that labels do not overlap.
Try editing your html code this way and add this media query to your code.
<div style="position: relative; margin-bottom: 90px;"><img src="https://cdn2.hubspot.net/hubfs/4022333/Blog/TOFU/quote.png" style="width: 112px;">
<div style="position: absolute; top: 50px; left: 78px;" class="quotation">
<p style="font-family: AvenirLight; color: #74818a; font-size: 36px; line-height: 45px; font-style: italic;">“Enabling understanding means being able to communicate effectively”</p>
</div>
</div>
#media screen and (max-width: 767px) {
.quatation {
position: static !important;
}
}
The problem is that is position absolute on title. i recommended following structure for free hesitate for all resolutions and devices.
.block-quote {
display:block;
margin:0;
padding:20px 0 0 70px;
background:url(https://cdn2.hubspot.net/hubfs/4022333/Blog/TOFU/quote.png) 0 0 no-repeat;
}
h2 {
font-family: 'AvenirLight';
color: #74818a;
font-size: 36px;
line-height: 45px;
font-style: italic;
}
<div class="block-quote">
<h2>“Enabling understanding means being able to communicate effectively”</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sollicitudin vulputate vehicula. Morbi fermentum elit lobortis nibh molestie, nec facilisis elit tempor. Nullam porta lectus erat, et hendrerit diam dictum at. Vestibulum sed enim turpis. Sed vehicula venenatis cursus. Mauris sit amet venenatis velit. Nullam ut purus erat. Nam posuere lorem at est ultrices luctus.</p>
</div>

Make div expand to occupy available height of parent container

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:
http://jsfiddle.net/v8Lhxk2v/
and I get this layout
but I need to get something like next image, without using js.
Can that be solved?
Depending on browser support you can use flex.
The container would need:
display: flex;
flex-flow: column;
Here's a quick demo with example markup:
http://jsbin.com/xuwina/3/edit?html,css,output
Look at this
http://jsfiddle.net/v8Lhxk2v/4/
playing with border-bottom and overflow:hidden on the parent element.
.tile{
height: 300px;
width: 200px;
background: #cecece;
float: left;
margin: 0 10px 0 0;
border-bottom: 22px solid #cecece;
overflow: hidden;
}
.tile h3{
min-height: 25px;
max-height: 61px;
display: inline-block;
overflow: hidden;
}
.tile .content{
margin: 0 10px;
}
I would say try to position the content absolute to the bottom of the tile.
In that case you can set the space where the content should end. Still you need to add an extra class to your content with the smaller title to be it larger than the other tile with the larger title.
Your HTML would be:
<div class="tile">
<h3>short</h3>
<!-- Added an extra class to the div -->
<div class="content small">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>
Within your CSS I changed this:
.tile .content{
height: 162px;
background-color:grey;
overflow: hidden;
margin: 0 10px;
position: absolute;
bottom:30px;
}
.tile .small{height:216px;}
And then you get this result: JSFIDDLE
Let me know if this is a solution that works for you.
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
<div id="container"><!-- container to align .tile boxes in flexbox row;
(this flexbox is optional) -->
<div class="tile">
<h3>short</h3>
<div class="content">Lorem ipsum dolor sit amet ... </div>
</div>
<div class="tile">
<h3>longLongLong longLongLong longLongLong</h3>
<div class="content">Lorem ipsum dolor sit amet ... </div>
</div>
</div><!-- end #container -->
CSS
#container {
display: flex; /* establish flex container;
aligns flex items (child elements) in a row by default; */
}
.tile {
display: flex; /* establish (nested) flex container */
flex-direction: column; /* override default row alignment */
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 {
flex: 1; /* tells flex item to use all available vertical space in container */
height: 162px;
overflow: hidden;
margin: 0 10px 40px 10px; /* added bottom margin for spacing from container edge */
}
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), but text-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:
.move{height:100px;}
it workd, you are done :)
PS: make it with both of your h3s :)
well, there is a code:
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;
}
.move{height:100px;}
html:
<div class="tile">
<div class="move">
<h3>short</h3>
</div>
<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">
<div class="move">
<h3>longLongLong longLongLong longLongLong</h3>
</div>
<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>
I would try another aproach. Using jquery you can calculate on window load the height of the highest h3 and then, apply that height to all your h3 inside your tiles.
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:
var maxHeight = -1;
$('.tile h3').each(function() {
if ($(this).height() > maxHeight)
maxHeight = $(this).height();
});
$('.tile h3').each(function() {
$(this).height(maxHeight);
});
As you can see in this JSFIDDLE (notice I removed the fixed max-heightyou added to the header and add a third tilewith a "very long text" so you can check the exmaple better.
Try this use extra div with wrap. h3 & div.content tag are wrapped by extra div and some css to be change as following:
.tile > div {
height: calc(100% - 20px);
margin: 10px;
overflow: hidden;
line-height: 22px!important;
}
.tile {
height: 300px;
width: 200px;
background: #cecece;
float: left;
margin: 0 10px 0 0;
}
.tile h3 {
min-height: 20px;
display: inline-block;
overflow: hidden;
margin: 5px 0;
}
.tile .content {
margin: 0;
}
<div class="tile">
<div>
<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>
<div class="tile">
<div>
<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>
</div>
How about a fixed height:
.tile h3 {
height: 65px;
display: inline-block;
overflow: hidden;
}
Or accompanied by js (jQuery):
// Height handler
var headHeight = 0;
// Iterate throug all H3s an get highest
jQuery( 'h3' ).each( function() {
// Get current height
var currentHeight = jQuery( this ).height();
// If higher as handler set as handler
if( currentHeight > headHeight ) {
headHeight = currentHeight;
}
} );
// Set the height of all H3s
jQuery( 'h3' ).css( 'height', headHeight );
This would be a pretty robust solution ...
you can resolve by the flexbox Flexible Box Layout Module:
.tile{
...
/* add the following line */
display: flex;
flex-direction: column;
justify-content: space-between;
...
}
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/

How to wrap image around the long text?

If text is long then text moves to next line after image. How to wrap text around image?
CSS:
img {
float: left;
width: 200px;
height: 200px;
}
.description {
border: 1px solid #000;
display: inline;
}
http://jsfiddle.net/qw4fxdwb/
Thanks in advance.
You can do like this demo:
.wrapper-text{
word-wrap: break-word; /*fixes the text to go below*/
overflow: auto; /*fixes the whole text preventing to go below the image*/
}
Use this, if this is what you want
.wrapper-text {word-wrap:break-word;}
Fiddle
This is done by floating elements. See the fiddle
CSS:
.wrapper img
{
float:left;
margin-right:10px;
}
HTML:
<div class="wrapper">
<img src="http://placehold.it/200x200" alt="placeholder">
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing 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 div absolute surrounded by text [duplicate]

This question already has answers here:
How can I wrap text around a bottom-right div?
(9 answers)
Closed 8 years ago.
I am trying to surround div with position: absolute by text.
Always text going under div.
CSS which I am using:
.all {
display: block;
width: 250px;
min-height: 180px;
height: auto;
position: relative;
background: #fa65fc;
}
.abs {
position: absolute;
top: 80px;
left: 200px;
float: right;
width: 50px;
height: 100px;
background: #4542df;
}
Two divs:
<div class="all">
<div class="abs">ABS</div>
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>
Here is link to: JSFiddle
I would like to do something like this:
Thanks in advance.
You can achieve the result you are looking for by using css to insert a dummy element. This method means you do not need to position your <div class="abs"> within the middle of the content of that div. This may be of use if you are not able to control what the content is (in the case of content being entered in a cms).
HTML:
<div class="all">
<div class="abs">ABS</div>
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>
CSS:
.all {
display: block;
width: 250px;
min-height: 180px;
height: auto;
position: relative;
background: #fa65fc;
}
.all:before {
content: "";
float: right;
height: 80px;
width: 0;
}
.abs {
clear: both;
float: right;
width: 50px;
height: 100px;
background: #4542df;
}
Link to JSFiddle.
.all:before inserts a dummy element which is floated right, no width and 80px high at the very beginning of <div class="all">.
Because .abs is floated right (but not positioned absolute), it will now try and stay floated right at the top of the div. Adding clear: both forces it drop below any other floated elements, so it ends up moving 80px down to clear the dummy float before it.
You cannot do that with position absolute. However you can achieve what you show on your image using static position and float: right; with some margins.
Here is an updated jsFiddle: http://jsfiddle.net/U5Pg5/2/
HTML:
<div class="all">
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
<div class="abs">ABS</div>
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>
CSS:
.all {
display: block;
width: 250px;
min-height: 180px;
height: auto;
position: relative;
background: #fa65fc;
}
.abs {
float: right;
width: 50px;
height: 100px;
background: #4542df;
margin-left: 15px;
margin-top: 10px;
margin-bottom: 10px;
}