Making image as a css - css

I tried to create this canvas in css:
this is my jsfiddle:
http://jsfiddle.net/alonshmiel/kyfha/35/
I have a problem only with the circle border, it's not exactly like the canvas.
this is my css:
.PersonaCanvas {
width: 100px;
height: 100px;
border-top: 12px solid rgb(238,238,238);
border-left: 12px solid rgb(238,238,238);
border-right: 12px solid rgb(238,238,238);
-webkit-border-radius: 100px;
-khtml-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
overflow: hidden;
}
.PersonaCanvas img {
display: block;
margin-top:16px;
width:100%;
height:80%;
}
and my html:
<div class="PersonaCanvas">
<img src="http://s8.postimg.org/ij71l6xol/New_Pers_achiever_1.png"/>
</div>
any help appreciated!

Basically you set a width and height of the container to 100px, but when you add a border, it automatically grows in size; if you inspect, you have the final width which is 124px, which comes from the 100px you set, along with the 12px border-left and another 12px border-right. You would either have to manually change it to accommodate the size to add up to 100px, or you can use a css3 method of box-sizing: border-box to do the calculation for you. Also, we had to change the width of the img to 80%, since you want it to stay in proportion to its height within the container. Lastly, the size of the img is fixed, but we have to align its margin: 16px auto 0. Try this updated one:
.PersonaCanvas {
width: 100px;
height: 100px;
border-top: 12px solid rgb(238,238,238);
border-left: 12px solid rgb(238,238,238);
border-right: 12px solid rgb(238,238,238)
-webkit-border-radius: 100px;
-khtml-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
overflow: hidden;
box-sizing: border-box
}
.PersonaCanvas img {
display: block;
margin: 16px auto 0;
width: 80%;
height: 80%;
}

The issue with the width of the border decreasing is cause by the lack of a bottom border (which is assumed to be 0 pixels)
So by adding a transparent bottom border you can make the width consistent.. (but you will need extra elements to make the ends be curved)
border-bottom: 12px solid transparent;
http://jsfiddle.net/kyfha/39/

I added two other div's. One for a white circle to cover part of the solid bottom border. And I also added the css elements and made te absolute so they will still fit wherever you need them. The border ends are not perfect, but if you made a white image with the correct edhe you have and inseted it into the thrid div tag, you will be perfect.
I hope this helps :)
http://jsfiddle.net/kyfha/44/
<div class="PersonaCanvas">
<img src="http://s8.postimg.org/ij71l6xol/New_Pers_achiever_1.png"/>
</div>
<div class="PersonaCanvas2">
</div>
<div class="PersonaCanvas3">
</div>
Here is the CSS
I changed the size of the image slightly and moved it around a little to give you your image.
.PersonaCanvas {
width: 100px;
height: 100px;
border-top: 12px solid transparent;
border-left: 12px solid transparent;
border-right: 12px solid transparent;
border-bottom: 12px solid transparent;
overflow: hidden;
position: absolute;
z-index: 100;
}
.PersonaCanvas2 {
width: 100px;
height: 100px;
border-top: 12px solid rgb(238,238,238);
border-left: 12px solid rgb(238,238,238);
border-right: 12px solid rgb(238,238,238);
border-bottom: 12px solid rgb(238,238,238);
-webkit-border-radius: 100px;
-khtml-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
overflow: hidden;
position: absolute;
z-index: 1;
}
.PersonaCanvas3 {
position: absolute;
width: 50px;
height: 50px;
-webkit-border-radius: 50px;
-khtml-border-radius: 50px;
-moz-border-radius: 50px;
border-radius: 50px;
background: #FFF;
top: 110px;
left: 46px;
z-index: 10;
}
.PersonaCanvas img {
display: block;
margin-top:16px;
width:80px;
height:80px;
position: absolute;
left: 10px;
top: -0px;
}
Basicallly I have two instances of the div tag and the image is in one without the border or the radius.

Related

I want to make one part of my border different from others

I want to make a div that a 2px solid white border on the bottom, left, right, and most of the top except for a small part roughly 50px wide that will have a 1px solid green border. I know php if you think that will help. My current css is this...
div#ghostBox{
width: 170px;
height: 100px;
border: 2px solid white;
position: fixed;
left: 550px;
top: 270px;
}
Btw I am making a game of pac-man.
You can keep the use of only one element and rely on gradient:
body {
background: pink;
}
.box {
width: 170px;
height: 100px;
border: 5px solid white;
border-top: none;
background: linear-gradient(to right, white 50px, green 0) 0 0/100% 5px no-repeat;
}
<div class="box">
</div
i think you want this (:
body{
background-color:black;
}
p{
color:white;
margin: 1px;
}
/* TEXT BOX */
div#ghostBox{
height: 100px;
width: 150px;
border: 2px solid white;
border-top: 5px solid white;
position: fixed;
left: 50px;
top: 50px;
color:red;
padding: 0px;
padding-top: 0px;
}
/* High text color line */
div#text{
border-top: 5px solid green;
position: absolute;
margin-top: 0px;
width: auto;
margin: 0px;
}
/* High color line after text */
div#notext{
border-top: 5px solid red;
margin-top: 0px;
width: auto;
margin: 0px;
}
<div id="ghostBox"><div id="text"><p>good luck
</p></div><div id="notext"></div></div>
You can do it using css after or before pseudo selector. Below is just an example . You can modify it according to your requirement
div#ghostBox {
width: 170px;
height: 100px;
border: 2px solid white;
position: fixed;
background: red;
}
div#ghostBox:after {
content: '';
width: 50px;
border: 2px solid green;
position: absolute;
padding-right: 50px;
}
<div id="ghostBox"> Ghost Box</div>
There may be better ways, but you could use a span at the beginning of the div:
Just set the border-top for the span and set its width:
(I removed the left and top properties for the example)
body {
background-color: red;
}
div#ghostBox {
width: 170px;
height: 100px;
border: 2px solid white;
position: fixed;
}
span {
border-top: 2px solid blue;
width: 50px;
position: absolute;
}
<div id='ghostBox'>
<span> </span> test
</div>

Creating a thick-to-slim border/box-shadow in css

How would I achieve the following as seen in the image below, in the best way as possible? I want a thick top border, but as it goes down I want the sides to become thinner and just "mend" (if that's right expression) into the black block.
This is my CSS code for the black block:
.containerMain {
background: #000;
padding: 15px;
border-radius: 5px;
width: 250px;
}
You can use the after pseudo-element to position an upside-down trapezoid behind your element.
Look here for a trapezoid shape example.
body { padding: 30px; }
.containerMain {
background: black;
padding: 15px;
border-radius: 5px;
width: 250px;
height: 250px;
position: relative;
}
.containerMain:after {
content: '';
border-radius: inherit;
margin: -20px;
margin-top: -25px;
width: 100%;
height: 50%;
position: absolute;
z-index: -1;
/* upside-down red trapezoid props */
border-top-width: 150px;
border-top-style: solid;
border-top-color: red;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
}
<div class="containerMain"></div>

making borders around CSS shapes

So I'm drawing elements in CSS, using this tutorial as a guide. I need some help with borders, though. For instance, here's my code for a curved trapezoid:
.foobar {
height: 0px;
width: 140px;
position: relative;
border-bottom: 200px solid red;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
border-bottom-left-radius: 150px 70px;
border-bottom-right-radius: 100px 25px;
}
The problem: I want to draw a 1px line border around the foobar element, but I'm already using the border properties to draw the element in the first place.
Is there an easy way to do this? My sense is that I'll have to create a shadow element that is the same shape as -- but slightly larger than -- the foobar element.
Thanks in advance!
You can position a :pseudo element behind with slightly adjusted dimensions.
.foobar, .foobar:before {
height: 0px;
width: 140px;
position: relative;
border-bottom: 200px solid red;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
border-bottom-left-radius: 150px 70px;
border-bottom-right-radius: 100px 25px;
}
.foobar:before {
content: "";
display:block;
position: absolute;
left: -31px;
top: -1px;
width: 142px;
z-index: -1;
border-bottom: 202px solid black;
/* add these lines if you're a pixel perfectionist */
border-bottom-left-radius: 150px 71px;
border-bottom-right-radius: 100px 26px;
}
http://jsfiddle.net/4vNGL/2
You can use a pseudo element drawn behind with same rules with a small increase of scale.
.foobar, .foobar:before {
height: 0px;
width: 140px;
position: relative;
border-bottom: 200px solid red;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
border-bottom-left-radius: 150px 70px;
border-bottom-right-radius: 100px 25px;
position:relative;
}
.foobar:before {
content:'';
position:absolute;
display:block;
z-index:-1;
top:0;
left:-30px;
width: 140px;
-webkit-transform-origin:center;
-webkit-transform:scale(1.03);/* adapt here the width of your fake border */
transform-origin:center;
transform:scale(1.03);
border-bottom: 200px solid black; /* color of fake border */
}
http://codepen.io/gc-nomade/pen/eDIGJ
You can even play with both pseudo-element and still add some shadows: http://codepen.io/gc-nomade/pen/axmsc

CSS problems...position fixed disappears

When I make the browser smaller, and scroll horizontally, the left_nav disappears. I tried changing the position. But that didn't work. Any advice?
#left_nav {
position: fixed;
height: 95%;
width: 100px;
background-color: #ededed;
border-right: 1px solid #aaa
}
#container {
margin-left: 100px;
position: absolute;
overflow: auto;
width: 75%;
min-width: 1129px;
overflow: hidden;
min-width: 1100;
background-color: #fff;
border-right: 1px solid #aaa;
border-bottom: 1px solid #aaa;
border-left: 1px solid #aaa;
-webkit-border-bottom-right-radius: 20px;
-moz-border-radius-bottomright: 20px;
border-bottom-right-radius: 20px
}
#left_nav {
position: fixed;
top:0;
left:0;
height: 95%;
width: 100px;
background-color: #ededed;
border-right: 1px solid #aaa
}
You should specify the left and top for fixed elements as above. This will place the left nav 0px from the top and left of the browser window.
Are you trying to specify it relative to the container? If so, you need to give the left_nav a position of absolute and the container a position of relative
Try adding min-width: 100px; to your left_nav, and getting rid of min-width: 1100; on container...
Notice you are duplicating the min-width attribute; this is a no-no:
min-width: 1129px;
overflow: hidden;
min-width: 1100;

How can I make a CSS only speech bubble with a border?

I want to make a CSS only speech bubble. So far, I have this...
Example
CSS
div {
position: relative;
background: #fff;
padding: 10px;
font-size: 12px;
text-align: center;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
div:after {
content: "";
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: -60px;
margin-left: -15px;
border-width: 30px 20px 30px 20px;
border-style: solid;
border-color: #fff transparent transparent transparent;
}
jsFiddle.
...which is almost exactly what I want. However, I want a light border around the whole thing.
Obviously, on the main portion, that is simple as adding border: 1px solid #333 to the div.
However, as the tail of the bubble is a border hack, I can't user a border with it.
I tried setting a box shadow of 0 0 1px #333 but browsers apply the border to the rectangular shape of the element (which I guess is what they should do).
jsFiddle.
My next thoughts were finding a Unicode character that looks like a bubble tail and absolutely positioning it there, with text-shadow for the border and using z-index of the main bubble to hide the top shadow of the text.
What Unicode character would be suitable for this? Should I do something different? Do I need to resort to an image?
I only have to support Mobile Safari. :)
<div>Hello Stack Overflow!<span></span></div>
div span:after {
content: "";
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: -51px;
margin-left: -15px;
border-width: 20px 20px 30px 20px;
border-style: solid;
border-color: #000 transparent transparent transparent;
}
http://jsfiddle.net/QYH5a/
For the Unicode character approach you suggested, the most appropriate would be ▼ U+25BC BLACK DOWN-POINTING TRIANGLE. I don't know whether iOS has glyphs for it.
Here is a similar solution:
http://jsfiddle.net/JyPBD/2/
<div>Hello Stack Overflow!<span></span></div>
body {
background: #ccc;
}
div {
position: relative;
background: #fff;
padding: 10px;
font-size: 12px;
text-align: center;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
border: 1px solid #333;
}
div:after {
content: "";
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: -60px;
margin-left: -16px;
border-width: 30px 20px 30px 20px;
border-style: solid;
border-color: green transparent transparent transparent;
}
div span
{
border-color: #FF0000 transparent transparent;
border-style: solid;
border-width: 25px 15px;
bottom: -51px;
margin-left: -65px;
position: absolute;
z-index: 10;
}
You could use the filter property with box-shadow() to do it...
-webkit-filter: drop-shadow(1px 1px 1px #111) drop-shadow(-1px -1px 1px #111);
jsFiddle.

Resources