I'm making a "D" like picture with css and border radius to render it with html2canvas.
The letter is created with code:
.a2 {
width: 1em;
height: 1em;
border-top-right-radius: 1em;
border-bottom-right-radius: 1em;
border: 4px solid black;
border-left: 0px;
}
The problem is that while css shows up correctly, the canvas isn't - the top right border in canvas gets thinner at end.
Here is jsfiddle: https://jsfiddle.net/x2LxvL0g/1/
What's wrong?
UPDATE:
It seems that border-left is interfering with border-top-right-radius.
I made the animation that shows top-right radius depending on border-left
https://jsfiddle.net/x2LxvL0g/10/
below is screen of end of the animation:
Looking at the documentation for html2canvas you can see that the documentation states that the the script does not take a screenshot of the page and in fact generates a canvas based on the information.
The script allows you to take "screenshots" of webpages or parts of
it, directly on the users browser. The screenshot is based on the DOM
and as such may not be 100% accurate to the real representation as it
does not make an actual screenshot, but builds the screenshot based on
the information available on the page.
Can i ask for the reason why you need to define the D in css but then want to display it on a canvas? Also you have used a dynamic size for your width and height but then a static size for the border width, is this intentional?
I have this piece of CSS:
.ab-banner
{
background-color: #212121;
background-image: url(logo.png);
background-repeat: no-repeat;
width: 100%;
height: 45px;
text-align: right;
border-bottom: 2px solid #4DD2FF;
}
which produces:
Adding this: box-shadow: 0px 2px 2px 0px #000;
produces this:
If you look closely at the shadow, it starts in the middle of the border. Increasing the border thickness causes the same behavior, so its not started at the layer's bottom.
How can I get the shadow to start from the bottom of the border?
I saw that you can do this by setting the border as a background image as done here, but is there no way to do this in CSS? I can get around this by making the shadow larger, though, that is not what my design calls for.
This is what I'd like:
EDIT:
#StackOverFlow UI, you are right, this will work correctly. Thank you for the example! The reason why the shadow was appearing in the middle was because the style was applied both to the table itself as well as the row that it contained. Removing that style class reference from one or the other would fix the issue. This unearthed a deeper issue in the layout, beyond the scope of this question. Accepting your answer as it is relevant.
What you have seems to be fine. Check this out, it is just that the shadow is deeper near the borders.By increasing the box-shadow property to a higher value, you can get what you want. http://liveweave.com/DkpyhE
i hope someone can answer this question because my client wants this and right now i dont know how to build this in css.
Does anyone know how to build something like this ?
It should be something like if you align your image to the right your text will align nicely with the image.
Here what i want to do is to build a div make a border around all the text that has been typed and then align it with the image. how could i do this?
After the help of Pete.
Problem here is the
box-shadow
Also the box needs to be transparant later in the stage.
This is my result right now http://jsfiddle.net/peteng/cu59r/.
Edit : Thank you for all the answers and support to help me solve this css issue.
The following thing it should happen is :
See the picture.
See the jsfiddle link i posted.
The content with the border needs a box-shadow, a border radius and a gradient.
This needs to be dynamic.
And again thank you community for helping me means alot to me.
with the use of a couple of images you should be able to create what you want
html
<div id="wrapper">
<div id="imageHolder"><div class="inner"><img src="http://lorempixel.com/200/200" /></div></div>
<!--put text here-->
<p>Text</p>
</div>
css
#wrapper {width:400px; border-radius:10px; border-top-right-radius:0px; background-color:#7ab37a; overflow:auto; padding:15px;}
#imageHolder {float:right; margin:-15px -15px 0 0; background:#ffffff url(http://i.imgur.com/gMIy72D.gif) left top no-repeat;}
#imageHolder .inner {background:url(http://i.imgur.com/RLBbLYV.gif) right bottom no-repeat; padding:10px 10px 20px 20px;}
Example
Update
With all your edits as to what you now want (instead of the simple l-shape in your original question). This is not possible for the following reason
The text has to have a background colour which means that you need the background colour on the main wrapper so that it will make the l-shape. This means the only way to get the desired effect of the rounded corners for the image is to place another background over the wrapper background (meaning you cannot have anything transparent otherwise the wrapper background-color will just show through)
The best you can hope for is to tell the client, if they want that shape, they will have to keep the images to an exact size and their text to a specific length and then you can use a simple background image
I think there isn't a easy way to style your text-box like this.
My suggestion: designs the box with Photoshop and then add it as a background image in two different divs (the text box should have a transparent background where the image should be). After this you position the divs in the right way, if necessary with a wrapper div.
disadvantages: not responsive, static, and so on
You can simply float the image and it will look like this: http://www.homeandlearn.co.uk/wd/images/chapter3/text_wrap_final.gif
Just add
float: right/left;
margin: 0;
See if that works.
see this DEMO . Is this what you are expecting.
<figure style="float:right;">
This is a very good question in my opinion :)
My short answer would be - yes, it's possible - see Pete's answer. I understand the difficulty of the situation and also I understand the fact that this kind of solution lacks flexibility because it combines css border-radius and an image - so => a) it will look weird in IE8 and below and b) it will look weird if we change some css :)
My own answer would be to use css only to do that, but the main issue will be unsolved, the corners close to the image will not be rounded by any means in css that I'm aware of.
Consider looking at this fiddle - http://jsfiddle.net/skip405/m6cpb/1/
I would prefer my variant because it's a bit more flexible - if there is a need of change - only css will change, no need of re-making any images of another color or of a different radius... no images needed at all :) Although you will need to style the images floated to the left differently and those - in the middle of the text as well.
Skull3r7 had a good idea with background-images. In addition, it is possible to use two divs with (dynamic) text and one other with the 'top border'.
Layer one contains the text as 'placeholder' and 'bottom border',
Layer two contains the 'top border image' (covers the top of Layer one)
Layer three contains the visible text.
Example
However, it is easier to implement Pete's solution, but I hope this example can help too. :)
A further alternative to those suggested, given the following HTML structure:
<div class="imgContainer">
<img src="http://placekitten.com/150/150" />
<p><!-- text excised for brevity --></p>
</div>
And CSS:
.imgContainer {
border: 1px solid #000;
padding: 0;
width: 80%;
margin: 0 auto 1em auto;
border-radius: 1em;
}
.imgContainer img {
float: right;
margin: -1px -1px 0 0;
padding: 0 0 0.5em 0.5em;
border: 1px solid #fff;
border-bottom: 1px solid #000;
border-left: 1px solid #000;
}
.imgContainer p {
margin: 0.5em;
padding: 0;
text-indent: 0.5em;
}
JS Fiddle demo.
This should allow any size image to be used (so long as it fits within the container element, of course), and be responsive, and adaptable to changed sizes.
Unfortunately, though, I can't think of a way to provide the curve on the borders of the img itself. On the plus-side, it avoids needlessly wrapping and re-wrapping elements, so the HTML itself could, and should, stay pretty lean.
I've designed a 3 column site and I wanted to place a thin horizontal line between each column. I did this quite easily and got the exact height I wanted in Chrome, I then opened it in Firefox and the horizontal line was about 10px shorter, the same thing happened with IE9.
Is this normal or am I doing something wrong? Is there anyway to fix this or do it better. This is the css I used, the html was just a div:
#horizontal-dividing-line-news-arabnews {
border-left: solid 0.1em #0099FF;
height: 31.8em;
float: left;
color: #FFF;
margin-top: 7.3em;
}
thank you!
You're using em ("ems") here as the unit for the size.
"Ems" are proportional to the current font-size and browsers might not all have the same default font-size so this is why the size vary.
You'll want to use px (pixels) for this.
What is the difference between border and outline properties in CSS?
If there is no difference, then why are there two properties for the same thing?
From: http://webdesign.about.com/od/advancedcss/a/outline_style.htm
The CSS outline property is a confusing property. When you first learn about it, it's hard to understand how it is even remotely different from the border property. The W3C explains it as having the following differences:
Outlines do not take up space.
Outlines may be non-rectangular.
In addition to some other answers... here are a few more differences I can think of:
1) Rounded corners
border supports rounded corners with the border-radius property. outline doesn't.
div {
width: 150px;
height: 150px;
margin: 20px;
display: inline-block;
position: relative;
}
.border {
border-radius: 75px;
border: 2px solid green;
}
.outline {
outline: 2px solid red;
border-radius: 75px;
-moz-outline-radius: 75px;
outline-radius: 75px;
}
.border:after {
content: "border supports rounded corners";
position: absolute;
bottom: 0;
transform: translateY(100%);
}
.outline:after {
content: "outline doesn't support rounded corners";
position: absolute;
bottom: 0;
transform: translateY(100%);
}
<div class="border"></div>
<div class="outline"></div>
FIDDLE
(NB: Although firefox has the -moz-outline-radius property which allows rounded corners on outline... this property it is not defined in any CSS standard, and is not supported by other browsers (source))
2) Styling one side only
border has properties to style each side with border-top:, border-left: etc.
outline can't do this. There's no outline-top: etc. It's all or nothing. (see this SO post)
3) offset
outline supports offset with the property outline-offset. border doesn't.
.outline {
margin: 100px;
width: 150px;
height: 150px;
outline-offset: 20px;
outline: 2px solid red;
border: 2px solid green;
background: pink;
}
<div class="outline"></div>
FIDDLE
Note: All major browsers support outline-offset except Internet Explorer
Further to other answers, outlines are usually used for debugging. Opera has some nice user CSS styles that use the outline property to show you where all the elements are in a document.
If you're trying to find out why an element isn't appearing where you expected or at the size you expected, add a few outlines and see where the elements are.
As already mentioned, outlines do not take up space. When you add a border, the element's total width/height in the document increases, but that doesn't happen with outline. Also you can't set outlines on specific sides like borders; it's all or nothing.
tldr;
The W3C explains it as having the following differences:
Outlines do not take up space.
Outlines may be non-rectangular.
Source
Outline should be used for accessibility
It should also be noted that outline's primary purpose is accessibility. Setting it to outline: none should be avoided.
If you must remove it it maybe a better idea to provide alternative styling:
I’ve seen quite a few tips on how to remove the focus indicator by using outline:none or outline:0. Please do not do this, unless you replace the outline with something else that makes it easy to see which element has keyboard focus. Removing the visual indicator of keyboard focus will give people who rely on keyboard navigation a really hard time navigating and using your site.
Source: "Do Not Remove the Outline from Link and Form Controls", 365 Berea Street
More Resources
http://outlinenone.com/
A practical use of outline deals with transparency. If you have a parent element with a background, but want a child element's border to be transparent so that the parent's background will show through, you must use "outline" rather than "border." While a border can be transparent, it will show the child's background, not the parent's.
In other words, this setting created the following effect:
outline: 7px solid rgba(255, 255, 255, 0.2);
From W3 School Site
The CSS border properties allow you to specify the style and color of an element's border.
An outline is a line that is drawn around elements (outside the borders) to make the element "stand out".
The outline shorthand property sets all the outline properties in one declaration.
The properties that can be set, are (in order): outline-color, outline-style, outline-width.
If one of the values above are missing, e.g. "outline:solid #ff0000;", the default value for the missing property will be inserted, if any.
Check here for more information :
http://webdesign.about.com/od/advancedcss/a/outline_style.htm
Border is created inside the element, where as outline is created outside the element. So border is computed along with the width and height of the element, while outline draws outside the element.
A little bit of an old question, but worth mentioning a Firefox rendering bug (still present as of Jan '13) where the outline will render on the outside of all child elements even if they overflow their parent (through negative margins, box-shadows, etc.)
You can fix this with:
.container {
position: relative;
}
.container:before {
content: '';
margin: 0;
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
outline: 1px solid #ff0000;
}
Super unfortunate that it's still not fixed. I much prefer outlines in many cases since they do not add to the dimensions of an element, saving you from always having to consider border widths when setting dimensions of an element.
After all, which is simpler?
.container {
width: 960px;
height: 300px;
outline: 3px solid black;
}
Or:
.container {
width: 954px;
height: 294px;
border: 3px solid black;
}
It is also worth noting, that W3C's outline is IE's border, since IE does not implement W3C box model.
In w3c box model, the border is exclusive of element's width and height. In IE it is inclusive.
Differences between border and outline:
Border is part of the box model so it counts against the element's size.
Outline is not part of the box model so it doesn't affect nearby elements.
Demo:
#border {
border: 10px solid black;
}
#outline {
outline: 10px solid black;
}
<html>
<body>
<span id="border">Border</span>Other text<br><br>
<span id="outline">Outline</span>Other text
</body>
</html>
Other differences:
The outline is displayed outside the border.
Outlines cannot have rounded corners; borders can.
I've made a little piece of css/html code just to see the difference between both.
outline is better to inclose potential overflowing child elements, especially into an inline container.
border is much more adapted for block-behaving elements.
Fiddle for you sir!
The outline property in CSS draws a line around the outside of an element. It's similar to border except that:
It always goes around all the sides, you can't specify particular
sides It's not a part of the box model, so it won't effect the
position of the element or adjacent elements
Source: https://css-tricks.com/almanac/properties/o/outline/
As a practical example of using "outline", the faint dotted border that follows the system focus on a webpage (eg. if you tab through the the links) can be controlled using the outline property (at least, I know it can in Firefox, not tried other browsers).
A common "image replacement" technique is to use, for example:
<div id="logo">Foo Widgets Ltd.</div>
with the following in the CSS:
#logo
{
background: url(/images/logo.png) center center no-repeat;
}
#logo a
{
display: block;
text-indent: -1000em;
}
The problem being that when the focus reaches the tag, the outline heads off 1000em to the left. Outline can allow you to turn off the focus outline on such elements.
I believe that the IE Developer Toolbar is also using something like outline "under the hood" when highlighting elements for inspection in "select" mode. That shows well the fact that "outline" takes up no space.
think about outline as a border that a projector draw outside something as a border is an actual object around that thing.
a projection can easily overlap but border don't let you pass.
some times when i use grid+%width, border will change the scaling on view port,for example a div with width:100% in a parent with width:100px fills the parent completely, but when i add border:solid 5px to div it make the div smaller to make space for border(although it's rare and work-aroundable!) but with outline it doesn't have this problem as outline is more virtual :D it's just a line outside the element
but the problem is if you don't do spacing properly it would overlap with other contents.
to make it short:
outline pros:
it doesn't mess with spacing and positions
cons:
high chance of overlapping
Google web.dev has a good explaintion for Box Model.
The border box surrounds the padding box and its space is occupied by the border value. The border box is the bounds of your box and the border edge is the limit of what you can visually see. The border property is used to visually frame an element.
The margin box, is the space around your box, defined by the margin rule on your box. Properties such as outline and box-shadow occupy this space too because they are painted on top, so they don't affect the size of our box. You could have an outline-width of 200px on our box and everything inside and including the border box would be exactly the same size.
Copied from W3Schools:
Definition and Usage
An outline is a line that is drawn
around elements (outside the borders)
to make the element "stand out".