tags:

views:

128

answers:

3

It should just basically be an outline of the square or circle - that I can style accordingly (i.e. change the color to whatever I want, change the thickness of the border, etc.)

I would like to apply that circle or square over something else (like an image or something) and the middle part should be hollowed out, so you can see the image beneath the square or circle.

I would prefer for it to be mainly CSS + HTML.

+3  A: 

i don't know of a simple css(2.1 standard)-only solution for circles, but for squares you can do easily:

.squared {
    border: 2x solid black;
}

then, use the following html code:

<img src="…" alt="an image " class="squared" />
knittl
care to explain the downvote?
knittl
This is interesting...I just don't like using the `<img>` tag. I prefer using a regular `<div>` like the above solution. Thanks though. By the way, I never downvoted. I upvoted :)
marcamillion
Why do you prefer using a div instead of an img? I'm curious...
Nicknameless
@marcamillion: i only used an image tag because it really does not matter. (quote: »I would like to apply that circle or square over something else (like an **image** or something)«) – you can of course use a div, a paragraph, or anything else. just apply the class and style it to your liking
knittl
@nick because the div was made for that (a default container) as opposed to an img tag made to pull images. I know it doesn't have to be used what it was made for, but I would prefer to do that :) @Knittl....I think you misunderstood what I was looking for. I am not looking for a square border. I would like to create a square that is say 50px X 50px, that is just an outline. Like Caspar did in his example for the circle - I just modified that for a square. That's what I was looking for. Now all I will do is add z-index to it, above the elements I want it to be on top of. That's all :)
marcamillion
ok, you said “apply the square to …”, so it wasn't really clear to me. glad you found a solution to your problem
knittl
+3  A: 

css:

div{
    -moz-border-radius: 50px/50px;
    -webkit-border-radius: 50px 50px;
    border-radius: 50px/50px;;
    border:solid 21px #f00; 
    width:50px;
    height:50px;   
}

html:

   <div><img /></div>

more here

Caspar Kleijne
+2  A: 

To my knowledge there is no cross-browser compatible way to make a circle with CSS & HTML only.

For the square I guess you could make a div with a border and a z-index higher than what you are putting it over. I don't understand why you would need to do this, when you could just put a border on the image or "something" itself.

If anyone else knows how to make a circle that is cross browser compatible with CSS & HTML only, I would love to hear about it!

@Caspar Kleijne border-radius does not work in IE8 or below, not sure about 9.

Nicknameless
IE9 will support it: http://stackoverflow.com/questions/635851/support-for-border-radius-in-ie
Chris
I didn't figure it would, but I hadn't tested it myself, so I didn't want to say for sure, surprising that IE has finally decided to support something that everyone wanted them to. :D
Nicknameless
@Nicknameless there are no browser requirements set by the OP. (perhaps it is for fun or corporate intranet)? The OP wanted a circle in html and CSS so he gets what he asked for ;)
Caspar Kleijne
@Nick I am trying to do 'tagging' functionality, like facebook. Where you can tag a section of an image or some other element. That's why someone might want to do this. Also, the CSS2/3 border-radius implementation is good enough for me.
marcamillion
I would suggest instead of using an extra parent div over the item you are "tagging" that you add a CSS class with the required css to the item you want "tagged".
Nicknameless