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.
Related
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/
I have a rectangular sprite image that is 120px x 40px. When someone select the image I want the right side of the selected image to turn into an arrow pointing right.
I know how to use border-radius but that gives a curves whereas I want a point.
Using css how would I turn the right side of an image into a arrow?
Thanks
Basically I want to perform a border-radius only on the right side, but instead of curved pointed like an arrow.
.selected {
-webkit-border-radius: 0px 25px 25px 0px;
border-radius: 0px 25px 25px 0px;
}
If you can keep the white background here is a very simple solution:
jsFiddle here
Run the image in the background of the following example.
HTML
<div class="container"></div>
<div class="container"></div>
<div class="container"></div>
CSS
.container {
background: #333;
width: 200px;
height: 60px;
position: relative;
overflow: hidden;
margin-bottom: 10px;
}
.container:hover::after {
content: "";
position: absolute;
width: 70px;
height: 30px;
background: #fff;
top: -20px;
right: -20px;
z-index: 1;
transform: rotate(45deg);
}
.container:hover::before {
content: "";
position: absolute;
width: 70px;
height: 30px;
background: #fff;
bottom: -20px;
right: -20px;
z-index: 1;
transform: rotate(-45deg);
}
I do not know, i understood your question, but i think, what you want to achive, can be done by jQuery and css function with background-position
Basically, if you want to use a CSS Sprite image, background-position will indeed do it.
You may want to have a <div> positionned over your image, that will be displayed on hovering (CSS :hover) or click (jQuery click event) the image, depending on what you meant by "selecting" it.
Here is an example for hovering case (pure CSS) and here is an example for the clicking case (with 3 lines of jQuery).
I was wondering if it is possible to create following shadow in using CSS.I tried adding box-shadow but it adds shadow to box not something like in the following image. I also tried it using pseudo elements but didn't find any way to make it elliptical. I want to know if this is possible using CSS or I just have to use transparent image for shadow.
Here is something I just made that resembles the shadow part. You need to add rules for other browsers if you want to make it work on non-webkit. The basic idea is to use border-radius to create a circle, then shrink it in y-direction using scale and finally blur it.
http://jsfiddle.net/L4QDs/1/
#shadow {
border-radius: 50%;
width: 100px;
height: 100px;
background: black;
opacity: 0.5;
-webkit-filter: blur(10px);
-webkit-transform: scale(1, 0.2);
}
You can create it with a pseudo element
CSS
#base {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: blue;
position: relative;
}
#base:after {
content: '';
position: absolute;
bottom: 0%;
left: 5%;
width: 90%;
height: 8%;
border-radius: 50%;
box-shadow: 0px 10px 5px black;
}
fiddle
I've used CSS border arrows quite regularly, but I don't know if what I want to achieve is possible with them, so I went another route and used pseudo elements instead. I know my solution relies on trigonometry but still don't know how to emplement it.
I need , regardless of the height of my .front div, to be able to maintain the 7PX width, thus, allowing for a flexible height with a fixed width:
.front{
height: 20px;
**width: 7px;**
background-color: darkred;
position: relative;
}
and that implies changing the transform angle in a mathematically controlled way:
.front:after{
content: " ";
height: 30px;
width: 15px;
background-color: lightgreen;
position: absolute;
top:0;
left: 0;
-webkit-transform-origin: top left;
transform-origin: top left;
-webkit-transform: rotate(-20deg);
transform: rotate(-20deg);
}
Is there a simpler way to achieve this? Images are obviously out of the question, because pixellation...
JsFiddle here.
Here's your fiddle with a triangle in the top right corner made purely of CSS. I'm sure that animating it is just a matter of resizing the two border widths.
#top_rt_tri {
position:absolute; top:0px;right:0px;width: 0px;
height: 0px;
border-style: solid;
border-width: 0 0 60px 60px;
border-color: transparent transparent #007bff transparent;}
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.