hiding image background - html

I have the following css and html. I'm trying to hide the background of an image so that you just see the image without its surrounding white space. Note: I'm a noobie with css so please be gentle. lol
.boxcontainer {
font-size: 12px;
position: absolute;
left: 100px;
top: 20px;
width: 300px;
z-index: 1000;
}
.boxwithicon
{
background: transparent;
background-position: 5px 10px;
background-repeat: no-repeat;
padding-left: 50px;
}
.boxstatus {
-moz-border-radius: 10px 10px 10px 10px;
background-color: rgba(0, 0, 0, 0.4);
border: 3px solid #000000;
color: #FFFFFF;
/*margin-bottom: 5px; */
padding: 15px;
position: relative;
}
HTML:
<div class="boxcontainer">
<div id="head1" ><b><u>Test</u></b></div>
<div class="boxstatus boxwithicon">
<img src="images/smrsfolderopen.png" alt="">Customers
</div>
</div>
So what I'm getting is my image with white background showing in image block. Just like with any image you have white space around actual image. I don't want that to show up. Hopefully i'm explaining this properly.
-DND
I think we are all on the same page. Now when i explorer other websites that use images they do have white backgrounds as well when I check out the image itself but when displayed on website its transparent. For instance check out this site: link text and click on Simple Example button. you will see icon next to text in box. How are they making the white background be transparent?
Thanks

Assuming you have an image with a white background, I would open up the png in photoshop and delete the background layer, and then make it a transparent png. That way, the background behind the image will come through.

.boxcontainer {
background: transparent;// you actually want to make sure you're not overriding this in any other elements further up the DOM
font-size: 12px;
position: absolute;
left: 100px;
top: 20px;
width: 300px;
z-index: 1000;
}
.boxwithicon
{
background: transparent;
background-position: 5px 10px;
background-repeat: no-repeat;
padding-left: 50px;
}
.boxstatus {
-moz-border-radius: 10px 10px 10px 10px;
background: transparent;// and NOT a set color. that would make it NOT be transparent...
border: 3px solid #000000;
color: #FFFFFF;
/*margin-bottom: 5px; */
padding: 15px;
position: relative;
}

You need to edit your image and make the background transparent.
Note that it will not work in IE6, unless you use a filter.

Png files have the ability to have transparency. But that doesn't mean that the image has any transparency set. I'd first check the image to see what's up.
Aside from that I don't see anything that would cause the whitespace...
There doesn't seem to be any styles in your code above targeting the image itself.
Feel free to follow up with questions, and I'll be happy to help you troubleshoot.

Related

Making harvey ball with border style css

I am trying to make a css styling for a harvey ball with an image inside, but so far I haven't figure out a way to do it right. This is what I have now:
.three {width: 43px;
border-radius: 100%;
border-style: solid;
border-width: 4px;
border-left-color: #dadad9;
border-top-color: #009ee3;
border-right-color: #009ee3;
border-bottom-color: #009ee3;
width:40px;
height:40px;
}
.lead-name {
font-size: 16px;
font-family:Symantec Sans;
color:#424242;
font-weight: 600;
margin-bottom:0px;
}
.lead-title {
font-size: 14px;
font-family:Symantec Sans;
color:#424242;
margin-top: -3px;
margin-bottom: 10px;
}
<div class="lead-designer">
<img class="three" src="http://orig09.deviantart.net/09e7/f/2008/159/0/1/side_profile_vector_by_sruphil.png"/>
<div style="display:inline-block; margin-bottom:0px; margin-top:5px;">
<p class="lead-name">Designer Name</p>
<p class="lead-title">Messaging PO</p>
</div>
</div>
https://jsfiddle.net/yiluka/dtauydrz/
What I want is something like
As you can see, I want the circle to be divided straight and have part of the image grey scaled.
I have a lot of them and I really want to do it in code instead of photoshop to save some labor.
You can also do it using the pseudo element ::after - https://jsfiddle.net/dtauydrz/3/
The HTML:
<div class="image-container">
<img class="three" src="http://orig09.deviantart.net/09e7/f/2008/159/0/1/side_profile_vector_by_sruphil.png"/>
</div>
<div style="display:inline-block; margin-bottom:0px; margin-top:5px;">
<p class="lead-name">Designer Name</p>
<p class="lead-title">Messaging PO</p>
</div>
The CSS:
.three {
border-radius: 100%;
border-left-color: #dadad9;
border-top-color: #009ee3;
border-right-color: #009ee3;
border-bottom-color: #009ee3;
width:40px;
height:40px;
border-style: solid;
border-width: 4px;
border-color: #dadad9;
}
.image-container::after{
content: "";
display:block;
position: absolute;
margin-top: -52px;
background-color: #009ee3;
-moz-border-radius: 25px 0 0 0;
border-radius: 25px 0 0 0;
width: 25px;
height: 25px;
opacity: 0.5;
}
After an hour of messing with it, I finally finished my solution.
TL;DR
JSFiddle Demo
JSFiddle Demo with a kitten(pick this one)
JSFiddle Demo with the unhappy king of all kittens(Actually this one is amazing)
This solution, after being implemented, renders this(minus, of course, the amazing hand-drawn circle):
This solution doesn't require square images, playing with the background-image placement, and is quite easy to implement.
Let's get started!
First of all, we take your nice <img> HTML element, and replace it with this monstrosity of HTML(It really isn't that bad):
<div class="image-wrapper">
<img class="main" src="http://orig09.deviantart.net/09e7/f/2008/159/0/1/side_profile_vector_by_sruphil.png">
<div class="grayscale">
<img class="gray" src="http://orig09.deviantart.net/09e7/f/2008/159/0/1/side_profile_vector_by_sruphil.png">
</div>
</div>
Now for a little explanation. We use two different image elements so we can gray-scale one of them. We do not use a background image, since this requires a massive amount of changes if you want to make the icon bigger, or the images are different sizes.
.image-wrapper is the container div, the elements inside are positioned relative to it. It's CSS is stupid simple:
.image-wrapper {
position: relative;
}
(If you can't understand that CSS, go read HTML5 and CSS3 for dummies. That's how I started with css... #destroying_my_reputation)
.main is, of course, the main image in color. It's CSS is a little mor complicated, but still very basic:
.main {
width: 100px;
border-radius: 100%;
border: 5px solid #dadad9;
}
The width can be changed to whatever you want, if you do change the width, make sure you also change the width of the .gray image. border-radius:100% makes a circle, and border obviously adds a border.
Now on to the more complicated CSS(It's all pretty simple)!
.grayscale is the div used to hold the gray-scale image. If you know CSS, you can probably tell what is happening.
.grayscale {
position: absolute;
top: 0;
left: 0;
overflow: hidden;
height: 50px;
width: 50px;
border-radius: 100% 0 0 0;
background: #009ee3;
padding-top: 5px;
padding-left: 5px;
}
The div is positioned absolute at the top-left corner of .image-wrapper. Anything overflowing it is hidden. It's top-left corner is given a border-radius of 100%, making it into the quarter-circle shape. Instead of a border, we change it's background color, and add a padding. This is because if we use a border, it is added to all sides, messing up the desired shape.
And then the .gray img:
.gray {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
width: 100px;
border-radius: 50% 0 0 0;
}
Simple, the image is changed to gray-scale using the grayscale() CSS filter. Make sure the width is the same as .main. And a border radius to add the round effect.
That's a wrap!
And here is the long awaited demo, with all the code
I just created a div that has the shape of a quarter circle
.quarter-circle-top-left {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 50%;
background: rgba(0, 0, 0, 0.4);
border-radius: 100px 0 0 0;
-moz-border-radius: 100px 0 0 0;
-webkit-border-radius: 100px 0 0 0;
border-left: 4px solid #009ee3;
border-top: 4px solid #009ee3;
}
And absolutely positioned that div on top of your image. It's got a transparent gray background and a top and left border with your blue. Both are now contained within an wrapper div so that the quarter circle would have something to be relative to.
Here's where the quarter circle css came from: http://1stwebmagazine.com/css-quarter-circle (I changed the class names because they seemed backwards to me).
And here's the updated fiddle: https://jsfiddle.net/ingridly/dtauydrz/1/
UPDATE:
I incorporated the idea from the other answers of filling another element with the image and grayscale-ing that, and now I think this answer does everything:
https://jsfiddle.net/ingridly/dtauydrz/6/

Code a complex menu with html/CSS for mobile

I have this menu image
I want to code it in plain HTML/CSS to be used for a game I'm creating for a phonegap application. I could just use this image inside the app, but the menu items text must be editable.
So I created an empty image to use as a background:
In Android there's lot of screen resolutions which forces me to use percentage instead of pixel, so first I restricted the game to be played only in portrait mode.
Sofar my approach is;
Use percentage values to position elements.
Use the image above (without the text) as a background and the items as spans.
Check a live demo here.
But this is not accurate; in some devices the text gets out of the area where it should :(
Here's the full game window:
Any hints?
You could achieve something pretty damn close to that JPG using nothing but CSS, it will be tricky though. Additionally, if the target audience is ONLY mobile users, then you don't have to worry about IE8 and below. Doing this in pure CSS would be impossible without CSS3 stuff that IE8 and below doesn't support.
So there is the CSS option... Then there could also be the SVG option. SVG's are vector graphics, meaning they scale infinitely without that nasty pixelating you see in raster graphics (like a jpg). SVG's can also be styled with CSS... Which means you could change the hover color, or the text color by modifying some CSS. The text then would just be overlayed on-top of the graphic. The vector graphic would allow you to scale the image up or down according to your orientation and screen size.
This is about as good as I could get with what I have to work with and limited time. Note that widths, heights, angles, etc can all be adjusted and your widths can be adjusted to be percentage based so they are more dynamic.
JSFiddle Demo
HTML:
<div class="container">
<div class="button">
</div>
<div class="button">
</div>
<div class="button">
</div>
<div class="button">
</div>
</div>
CSS:
.container {
width: 500px;
}
.button {
position: relative;
width: 300px;
height: 40px;
margin: 10px auto 0 auto;
background: #b9aea2;
box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.2);
}
.button:first-child:before {
content: ' ';
position: absolute;
z-index: -1;
width: 40px;
height: 0px;
top: 14px;
left: -20px;
margin: 0px 0px 0 0px;
border-top: 20px solid transparent;
border-left: 15px solid white;
border-bottom: 20px solid transparent;
-webkit-transform: skew(-5deg);
-moz-transform: skew(-5deg);
-o-transform: skew(-5deg);
background: #b9aea2;
}
.button:last-child:before {
content: ' ';
position: absolute;
z-index: -1;
width: 40px;
height: 0px;
top: 14px;
right: -20px;
margin: 0px 0px 0 0px;
border-top: 20px solid transparent;
border-right: 15px solid white;
border-bottom: 20px solid transparent;
-webkit-transform: skew(5deg);
-moz-transform: skew(5deg);
-o-transform: skew(5deg);
background: #b9aea2;
}
.button:after {
content: ' ';
position: absolute;
display: block;
width: 240px;
height: 10px;
bottom: -10px;
left: 30px;
-webkit-transform: skew(-80deg);
-moz-transform: skew(-80deg);
-o-transform: skew(-80deg);
background: #6b6562;
}
.button:last-child:after {
width: 0;
height: 0;
background: transparent;
}
A few things that might help:
In your CSS, looking at the .menu-game--container class, if you change background-size: center; to background-size: contain;, that makes sure that all of the image is indeed in the picture. Sometimes this doesn't happen.
If you really want to be sure that your text will be in the right place, consider putting the text directly into the image using photoshop or something, and then using a <map> tag for the links.
Finally, I have found that it works better if you use href="javascript:" rather than href="#" and then putting the javascript into the OnClick event or something.

Color of div hangs over the background image on hover over

Explanation
Im trying to make a few buttons.
I have a background image on a div, parts of this images are transparent. The background image is a circle.
When the user hovers over that div it changes the background to purple showing through the transparent parts.
The div is 80px x 80px. Same with the background image.
The radius of the div is 100px;
Problem
When the user hovers over the div, there is a small part of the purple showing outside the background image.
How do I stop this from happening?
HTML Code
<div id='Menu'>
<div onclick="gotoPage('HomePage')" class='MenuItem' id='home'>
Home
</div>
<div onclick="gotoPage('AboutUsPage')" class='MenuItem' id='team'>
About Us
</div>
</div>
CSS Code
#Menu
{
width: 80px;
}
.MenuItem
{
font-family: 'Share Tech', bold, sans-serif;
background-image: url(../images/button.png);
color: rgb(51, 0, 102);
text-align: center;
vertical-align: center;
margin-top: 25px;
border-radius: 999px;
width: 80px;
height: 80px;
line-height: 80px;
}
.MenuItem:hover
{
background-color: rgba(51, 0, 102, 1);
color: darkgray;
cursor: pointer;
/**position: relative;
top: -5px;
left: -5px;
margin-bottom: -20px;**/
}
Example Page
The overlapping image for your button isn't the full 80 x 80;
I changed background position in the fiddle to compensate but now the hover color bleeds to the bottom.
You need to fix the image itself or change the overall size of the button which is what is demonstrated on the fiddle http://jsfiddle.net/69Jaw/ and the code below.
border-radius: 78px;
background-position: -2px -1px;
width: 77px;
height: 78px;
line-height: 78px;
Assuming every thing is as you say, I would only suggest that you add this to ensure the bg image is sized and located correctly:
background-position:center;
background-size:80px 80px;
Also, the border-radius should be amended to:
border-radius: 50%;
JSFiddle Demo

Getting a page-curl transparent image to work with a solid background color

I have a small png with a transparent area I want to act as the bottom-right hand corner of a solid color div, but I can't seem to come up with an elegant way of doing this with css.
my current css:
div.example {
border-radius: 9px;
background-color: #fff;
background-image: url(bottom-right-corner-peel.png);
background-repeat: no-repeat;
background-position: right bottom;
}
The problem with the above code is that the background color of the div (#fff) shows through the transparent part of the png, ruining the effect. I can think of a couple extremely hacky approaches to fix this (for example - creating another div (or using ::after) to put an element below div in question, and use some tricks to make that work, but there must be a better way, right?
View the [revised] Demo:
http://jsbin.com/abacey/8/
Here is a solution to your problem: http://jsfiddle.net/promatik/uZFpZ/
I've added a #content-bottom next to #content:
<div id="content">
<h1>Corner Peel Demo</h1>
</div>
<div id="content-bottom">
<div id="content-space"></div>
<div id="content-corner"></div>
</div>
And added this in CSS:
div#content{
...
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0px;
}
div#content-bottom {
height: 30px;
position: relative;
}
div#content-space {
height: 27px;
border-bottom-left-radius: 9px;
background-color: #fff;
margin-right: 42px;
}
div#content-corner {
position: absolute;
top: 0px;
right: 0px;
height: 27px;
width: 42px;
background-color: transparent;
background-image: url(data:image/png;base64,...');
}
My Ideas is to use the png to cover up the entire corner of the div.
Lets assume your png is 40x40px and the upper left part is white while the lower part is transparent.
You can use
border-bottom-right-radius: 40px;
to "cut off" the corner of the div. Therefore you have the background image visible. Now you lay your png over it to cover up the ugly round corner.
http://jsfiddle.net/Xd8CD/
(needs a better png...)

is it possible to achieve an image clipping/masking effect with html + css3?

I'm trying to place a nice border around an image that's 250x250, using only html and css. The markup is this:
<div id="img-container"><img src="pic.jpg" border="0"/></div>
And the css is:
#img-container {
height: 225px;
width: 225px;
padding: 3px;
border: 1px solid black;
z-index: 10;
position: relative;
overflow: hidden;
border-radius: 10px;
}
#img-container img {
z-index: 5;
}
Basically, I want the div container to clip the picture's edges that exceed its boundaries. This will achieve the rounded edges effect using the border-radius property (-moz-border-radius, -webkit-border-radius, etc) - if it actually works or could even be done. Looking for tips and tricks on this. Thanks.
And, yes, I'm obviously not a web designer :)
Yes it's possible, but you should set the image as the div background using CSS:
#img-container {
height: 225px;
width: 225px;
padding: 3px;
border: 1px solid black;
background-image: url('pic.jpg');
border-radius: 10px;
}
This is necessary, otherwise you will get horrible white borders around the image (tested in Google Chrome).
as far as I understood your question, deleting the
#img-container img {
z-index: 5;
}
part should do the trick.
Or you could use the image as a background image:
#img-container {
...
background: url(pic.jpg) no-repeat top left;
}