Wrap text with margin around image - css

Is there a way to wrap text in a div with a border and margin around an image with float: right?
So far, the best I was able to do was get the text wrapping correctly around the image but the border ended up behind the image.
EDIT
Here is a screenshot of what I was able to get it too look like:
http://www.tiikoni.com/tis/view/?id=6753a19
As you can see, the border ends up behind the image when I'm trying to get it to stop when it reaches the image border.
The code for this is:
<img src='images/mangos.jpeg' width='500px' style='float: right; border: 2px solid $theme; padding: 5px; margin: 0 5px 5px 5px;'>
<div style='font-size: 19px; white-space: pre-wrap; border: 2px solid #F6B616; padding: 5px; margin: 5px;'>
Text Here
</div>
EDIT 2
Sorry the question wasn't very clear. What I was after was effectively a small gap between the text and image border. The text and its border needs to wrap around the image and its border. Is there any way of achieving this?

What you are seeing is in fact perfectly normal. Imagine your text would become higher then the image, a true wrap would make the text proceed underneath the image, and not just in a single column to the left of the image. That is the entire purpose of a float after all (though it is often abused in all kinds of ways). Something like this:
+------+---+ +------+---+
|text |img| |text |img|
THIS: |text +---+ NOT THIS: |text +---+
|text text | |text |
+----------+ +------+
Your use case can be solved quite easily though, supposing your background is a solid color. You can just mask the text border that you see behind the image. Something like this:
<img src='path/to/image'>
<p>Lorem ipsum...</p>
img {
float: right;
box-shadow: 0 0 0 5px #FFFFFF, 0 0 0 7px #F6B616;
margin: 7px 5px 5px 13px;
width: 250px;
}
p {
font-size: 19px;
white-space: pre-wrap;
border: 2px solid #F6B616;
padding: 5px;
margin: 5px;
}
As you can see I added a double box shadow to to the image, that mimics the effect of a border with 5px margin. The big difference is the white form this shadow will mask the underlying border of the text, which produces the effect you are after.
There are other techniques, like working with pseudo elements (which could be useful in case you have a more complex background) but personally I find this method the easiest for your use case.

Related

CSS - Making an image a circle, with a border, has a small space inbetween

I am trying to create an image, in a circle shape, with a border around it. The problem is that if you look VERY carefully between the image and the border, there seems to be a small space.
Is is possible somehow to make the border attach itself perfectly to the circle shape?
Here is a small codepen:
https://codepen.io/dbugger/pen/NjYMEQ
This is the CSS used:
img {
border-radius: 150px;
box-shadow: 0 0 0 10px black;
}
Just give image the same background-color (whatever that is, I used maroon here) like this:
img {
border-radius: 150px;
box-shadow: 0 0 0 10px black;
background-color: maroon;
}
<img src="https://placehold.it/300/300" alt="" />

Why doesn't img reach to the bottom of its containing div? [duplicate]

This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 7 years ago.
Notice that the bottom of the image does not reach the red outline below it, which is the bottom of the containing div.
What's going on here? This is counter-intuitive or not obvious to me anyway.
I'm not looking for a kludge to fix it. This is a made up example. I'm trying to master my understanding of css.
* {
margin: 0px;
padding: 0px;
}
.frame {
outline: 1px solid red;
padding: 0px;
}
.frame img {
/*border: 10px solid yellow;
outline: 10px solid blue;*/
}
<div class="frame">
<img src="http://lorempixel.com/200/300/city/200x300/" />
</div>
Images are inline elements and are, thus, treated like text. They sit on the baseline just as text does so there is a slight padding underneath them. That gap is there to allow for descenders of text.
To remove the gap, add vertical-align:bottom to the CSS for the image.
In order to get rid of this, just add this style to your <img>:
display: block
This will force the image display not to be inline and so that things like line-height won't apply to it.

How can I create facebook style vertical border line (layout)? :)

How can I create vertical border line on both (left, right) side like facebook using CSS??
I've read several posts on Stackoverflow, but I could not find exactly what I wanted...Anybody know how to make vertical lines(layout)?
Thank you :)
facebook
| contents |
| |
| | <-these two vertical lines on facebook
| |
| |
There are two options:
use css borders and play with box-shadow too
use image lines there
both work fine. I would choose the css solution but there are others who create an image background and place it behind the main content area and then center all content on top of it.
Just apply borders and shadow to these borders (you can change the box-shadow value to fit your needs). Here's a fiddle
.middle {
width:400px;
height:800px;
border-left:1px solid #eeeeee;
border-right:1px solid #eeeeee;
margin:0 auto;
box-shadow: 5px 5px 5px #888888;
}
Specify your content width first. then use
margin : 0 auto;
it will keep your content in the middle of the page with both side equal space blank. then put dashed border on the content. try it. give your feedback.
You can use border-right and border-left here is an example below
#middle-region{
width: 900px;
min-height: 600px;
border-right: 1px solid #CCCCCC;
border-left: 1px solid #CCCCCC;
margin: auto;
}

Trapezium with css AND with box-shadow

I'm looking at making a trapezium with a box shadow that's 10px wider at the top than the bottom. In the past I've made a trapezium as outlined in the following jsfiddle, but you'll notice that if I put a box-shadow onto the element it boxes the outerWidth in a rectangle, rather than putting a shadow on the slanted border:
#trapezium {
margin:20px auto;
height: 0;
width: 80px;
border-bottom: 80px solid blue;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
box-shadow:0 0 10px #333;
}
http://jsfiddle.net/YhePf/8/
My initial thoughts would be to use something along the lines of:
-webkit-transform:perspective(100) rotateX(1deg);
Something like that. While this certainly begins to resolve the issue, I'm not sure what the number 100 refers to in 'perspective', and how I could calculate a formula that would make sure the top width was precisely 10px wider than the bottom, regardless of how high or wide this element is.
Any tips? Or a third option to pull this off?
What you've built isn't a trapezoid (aka trapezium) -shaped element; it's a rectangle-shaped element where the border styling creates the appearance of a trapezoid. This is why the box-shadow is rectangular.
Using the proprietary -webkit-transform property wouldn't change the shape of the actual element.
To create a truly non-rectangular element, you'll need to use SVG. See Multi-Shaped CSS Layers \ Non-rectangular CSS Layer or non-rectangular hoverable area.

CSS auto adjust not FULL width problem

I want to do so the size of the bubble, is auto-adjusting after the text(comment) which is inside the div..
Firstly heres the code:
.bubble {
font-size: 12px;
margin-bottom: 0px;
}
.bubble blockquote {
margin: 0px;
padding: 0px;
border: 1px solid #c9c2c1;
background-color: #000;
}
.bubble blockquote p {
display: inline;
margin: 0px;
padding: 0px;
font-size: 18px;
}
.bubble cite {
position: absolute;
margin: 0px;
padding: 7px 0px 0px 15px;
top: 5px;
background: transparent url(b/tip.gif) no-repeat 20px 0;
font-style: normal;
}
And the page:
<div class="bubble">
<blockquote>
<p>
Hello, my name is Azzyh
</p>
</blockquote>
<cite>I wrote this today</cite>
</div>
Now as i said, i want it to auto adjust to the text, so the "bubble" is around "hello, my name is azzyh"..
Not like how it is now:
http://img341.imageshack.us/img341/8303/exampleu.png
As you see it goes all out to the browser's right+left end..
Check the image, you'll see the line (the "box") where the text is, are too big for the text. I want css to adjust the box after the text.. so the "lines" gets around the text "hello my name is" sorry for my english
See this image:
http://img17.imageshack.us/img17/6057/exampleph.png
The "red" is how i want it to be..
How can i do this?
Thanks
div elements are block-level elements that, by default, stretch as far to the left and right as their containing blocks will allow.
In order to get the width of the div to auto-adjust, you'll have to convert it to an inline element, using the same style as you put on the p: display: inline;
Note that this may have the unintended side effect of not automatically forcing each div onto a new line. Without more information, though, I'm not entirely sure if that would be good or bad in your layout.
A similar problem I had was solved by applying the following CSS:
display:inline-block;
I wanted a link to look like a button but not expand the background to fill the width of the containing DIV.
Supported in nearly all browsers, including partial support in IE6 and IE7 but only where element has 'inline' as a default. There are some alternative properties to gain cross-browser support. There is also something on Google Code for setInlineBlock, but I haven't tried this myself.
Move your border property
border: 1px solid #c9c2c1;
from
.bubble blockquote {}
into your
.bubble blockquote p {}
and that should put the box where you want it.

Resources