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>
Related
I'm writing a compiler from a high-level document to HTML. Basically, I want:
Because blah blah{{margin-note|...}}, it yada yada.
to compile to the following paragraph:
Because blah blah¹, it yada yada.
and with a box floating on the right of the paragraph in the same level as the margin note number.
The way I approached this is to compile it to the following HTML:
<p>
Because blah blah<span class="mg-note-num">1</span><span class="mg-note-box">...</span>, it yada yada.
</p>
where mg-note-box shifts the element to the right of the paragraph. This works really well, except that the margin note box couldn't support block-level elements, like ul. When I put ul inside the margin note box, the ul element will be thrown outside of the span tag.
The obvious fix is to change span to div so that ul can stay inside the div, but this is not an option either because div can't stay inside p. Doing so will break the paragraph into two. Instead of:
Because blah blah¹, it yada yada.
we would have this instead
Because blah blah¹
, it yada yada.
I guess another option is to have a collection phase in my compiler, and move all margin note boxes outside of paragraph. This is also undesirable because for a long paragraph, the position of the margin note boxes will no longer match margin note numbers.
How should I approach this?
Update: I should have mentioned that my experiments with inline-block also don't work, but perhaps I did it wrong. Here are what I did:
Let's start with a reference layout (which functions properly but doesn't support block-level elements)
<p>
before
<span style="float: right;">Hello world</span>
after
</p>
This results in
| before after Hello world |
With div and inline-block:
<p>
before
<div style="float: right; display: inline-block;">Hello world</div>
after
</p>
This results in:
| before |
| |
| after Hello world |
With span and inline-block:
<p>
before
<span style="float: right; display: inline-block;">
<ul><li>1</li></ul>
</span>
after
</p>
This results in:
| before |
| |
| - 1 |
| |
| after |
So, no, inline-block doesn't seem to work.
The requirement to handle block elements within a paragraph (this is the important part) is the root of the issue.
Nesting a block element in a paragraph is not possible. Paragraphs are block-level elements, and automatically close if another block-level element is parsed before the closing </p> tag. For example, this HTML:
<p>Before<div>Block</div>After</p>
results in:
<p>Before</p>
<div>Block</div>
<p>After</p>
which causes the break around the block element.
The only HTML structure that will achieve the result you want is to use an inline element like a <span> (without any nested block elements). Here's an example:
p {
font-family: Arial;
position: relative;
padding-right: 120px;
}
.note-num {
font-size: 10px;
margin: 0 1px 0 -3px;
}
.note-content {
position: absolute;
right: 0;
font-size: 12px;
max-width: 100px;
}
<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.
<sup class="note-num">1</sup>
<span class="note-content">
Inline Note
</span>
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>
However....
There's one way we can kinda achieve the result you want, which is to use a <div> in place of the wrapping <p>. Like this:
p,
.p {
font-family: Arial;
position: relative;
padding-right: 120px;
}
.note-num {
font-size: 10px;
margin: 0 1px 0 -3px;
}
.note-content {
position: absolute;
right: 0;
font-size: 12px;
max-width: 100px;
}
.note-content ul {
margin: 0;
padding: 0;
}
<div class="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.
<sup class="note-num">1</sup>
<span class="note-content">
<ul><li>Block Note</li></ul>
</span>
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>
My friend, Pavel Panchekha, found another method that doesn't need to change <p> to <div>: use <object> instead of <span>:
p {
font-family: Arial;
position: relative;
padding-right: 120px;
}
.note-num {
font-size: 10px;
margin: 0 1px 0 -3px;
}
.note-content {
position: absolute;
right: 0;
font-size: 12px;
max-width: 100px;
}
.note-content ul {
margin: 0;
padding: 0;
}
<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.
<sup class="note-num">1</sup>
<object class="note-content">
<ul><li>Block Note</li></ul>
</object>
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>
Try adding display: inline-block to your <span>'s style...
See: https://www.w3schools.com/cssref/pr_class_display.asp
Scenario :
I can't figure out how to have a 50% opacity "box" behind a text that just cover the text and not a whole square.
I have a h2-tag that i have specified this CSS to:
background: rgba(0, 0, 0, 0.5);
width: fit-content;
Problem :
I tried the same thing on a p-tag, but that does not work...
this is working fine. Check This
h2{
background: rgba(0, 0, 0, 0.5);
width: fit-content;
}
p{
background: rgba(0, 0, 0, 0.5);
width: fit-content;
}
<h2>Some Text Here</h2>
<p>Some Text Here</p>
if you want color behind the text then use <mark> tag
mark{
background: rgba(0, 0, 0, 0.5);
}
<mark> test</mark>
Try this way.
p{
background: rgb(0, 0, 0 , 0.5);
opacity: 0.5;
}
<p>Hello world</p>
This is works for me. :)
You need an inline element like <span> and apply the same color to this inline element. Other wise you can apply display:inline to your <p>.
p{
background: rgba(255, 0, 0, .5);
display: inline;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris purus risus, tincidunt vel accumsan et, tempus placerat nisi. Suspendisse ornare, elit vitae vulputate pulvinar, arcu mi pretium lorem, et ultricies elit purus interdum nulla. Suspendisse vel erat id tellus venenatis viverra. Donec et mauris efficitur<p>
Hope this is you are looking for.
.back {
background-color: red;
width: 100%;
height: 200px;
text-align: center;
padding-top: 20px;
}
h2 {
color: #000000;
font-size: 35px;
font-weight: 900;
}
p {
color: #ffffff;
font-size: 16px;
}
<div class="back">
<h2>This is h2 text</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book</p>
</div>
Please check the above code.
p{
background-color:lightgreen;
margin:10px;
}
p.p{
background-color:lightpink;
margin:10px;
}
<p>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.</p>
<p class="p">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. </p>
<p class="p">Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.</p>
<p class="p">Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.</p>
<p class="p"> Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
You make the <p> inline. See below snippet.
This also work with width: 100%;.
p {
background: rgba(255, 0, 0, 0.2);
width: auto;
display: inline;
}
<p>
hello world
</p>
I've got a text-paragraph and a button.
I want to display the button right-aligned below the text but I can't quite get it to work.
This is how it currently looks like:
How can I do this WITHOUT float (it falls in the element below it if I set float: right)
Just use the desired vertical-align, e.g.
button {
vertical-align: -75%;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
<button>Button</button>
</p>
This could do it width inline-block + transform.
JsFiddle
a {
display: inline-block;
background: yellow;
padding: 5px 10px;
transform: translateY(100%);
}
I've got a text-paragraph and a button. I want to display the button right-aligned below the text but I can't quite get it to work.
Link text
Is this what you're looking for?
div {
width: 400px;
}
button {
display: inline-block;
background: orange;
padding: 5px 10px;
margin-left: 300px;
width: 100px;
}
<div>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."<button>Click Me</button>
One way could be putting it in a div, with the width set to 100% (that is, if the div and paragraph share parents) and then set the divs text-align to right.
<div>
<p>....</p>
<div style="width:100%; text-align:right;">
<button>click here</button>
</div>
</div>
If I understand your question correctly, the following fiddle should work. Here is the fiddle: http://jsfiddle.net/cLyycy3d/
CSS:
button {
float: right;
}
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>
http://jsfiddle.net/pkLMC/
the left column should shrink to fit, and the right column should take up the remainder of the width of the page. It needs to work with IE7 as well
image of issue
<style>
table
{
width:100%;
border:1px solid black;
}
td
{
vertical-align:top;
border:1px solid green;
background-color:orange;
}
.left
{
/* trim the column to the minimum necessary width required to avoid overflow */
width:1px;
}
.long
{
/* this layout works whether the content of the right column wraps or not */
/* display:none; */
}
</style>
<table>
<tr><td class="left">ABC</td><td>Lorem ipsum dolor</td></tr>
<tr><td class="left">ABCDE</td><td>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td></tr>
<tr class="long"><td class="left">ABCDEFG</td><td>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</td></tr>
<tr class="long"><td class="left">ABCDEFGHI</td><td>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</td></tr>
<tr class="long"><td class="left">ABCDEFGHIJK</td><td>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</td></tr>
</table>
The data you present in your example is tabular in nature in that it has both rows and columns. Css without HTML tables is good for formatting stuff in columns (like a newspaper). Once you have both rows and columns with variable width columns (like your data), tables (/table, /tr, /td, etc.) is the way to go.
You might want to stripe your rows. Here is an example: http://jsfiddle.net/peavU/
Something to keep in mind is that using tables for layout is not a bad thing at all IF the information you're presenting is tabular in nature.
Using tables to arrange non-tabular data isn't good, but that doesn't mean that tables don't have their place.
On preview... what #DwB said.
A definition list <dl> is perfect for the type of layout you have on your fiddle.
http://www.maxdesign.com.au/articles/definition/
Have you tried using div tags instead? They are more organized, efficient, and can adjust to multiple screen sizes
I agree with both #DwB and #Diodeus. Means, if you have really tabular data, the best you can do is to use tables. But, if your list is actually a list of definitions, then it makes sense to convert to <dl> like in the example:
HTML
<dl>
<dt>THIS IS THE TITLE</dt>
<dd>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</dd>
<dt>THIS IS ANOTHER TITLE</dt>
<dd>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</dd>
</dl>
CSS
dl {
width: 100%;
background: Orange;
margin: 0;
padding: 0;
}
dt {
width: 10em;
clear: left;
float: left;
padding: 1em;
border-top: 1px solid #fff;
}
dd {
margin-left: 12em;
padding: 1em;
border-left: 1px solid #fff;
border-top: 1px solid #fff;
}
I can get a bit crazy using lists, but here is my two cents...with a jsFiddle example: Table like layout using lists
The code should resize and the text won't wrap, utilizing the "text-overflow: ellipsis;" css rule.
HTML:
<ul>
<!-- "table" header" -->
<li class="col1 th">Column 1 header</li>
<li class="col2 th">Column 2 header</li>
<!-- "table" rows -->
<li class="col1">data</li>
<li class="col2">data</li>
<li class="col1">data</li>
<li class="col2">data</li>
<li class="col1">data</li>
<li class="col2">data</li>
<li class="col1">data</li>
<li class="col2">data</li>
<li class="col1">data</li>
<li class="col2">data</li>
CSS:
* {
margin: 0;
padding: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
ul {
border: 1px solid #333;
list-style-type: none;
zoom: 1; /* For IE 6/7 (trigger hasLayout) */
}
ul:after {
content:"";
display: table;
clear: both;
}
.col1, .col2{
float: left;
text-align: left;
border-bottom: 1px solid #999;
border-left: 1px solid #999;
padding: .25em;
white-space: nowrap;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
.col1 {
clear: left;
width: 30%;
}
.col2{
width: 70%;
}
.th {
font-weight: bold;
text-align: center;
}
Hopefully that helps!