I have a query in relation to images, using just html and css (if possible).
I would like to have an image (e.g wallpaper image of a city at night) transformed into a circular shape with a surrounding border.
Hopefully i would use this image also as a button, and add text to it.
So for example a picture of a football stadium in the middle, circular in shape. Surrounded by a small border. When you click on the image (which will have text on it) you are transferred elsewhere...I will have 4 of these in a line on my poage.
Thanks
All help in this matter would be greatly appreciated
<div class="circular"><a></a></div>
.circular {
border: solid 1px
width: 300px; //edit this
height: 300px; //edit this
border-radius: 150px; // a half of width and height will cause a circle
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
background: url(http://link-to-your/image.jpg) no-repeat;
}
Just answering your position question, check the answer here https://stackoverflow.com/a/19461564/2012904
The flexbox is a good method.
See this demo
HTML:
<a href="#" class="round">
Click Me!
</a>
<a href="#" class="round">
Click Me!
</a>
<a href="#" class="round">
Click Me!
</a>
CSS:
.round{
display:table-cell;
width:100px;
height:100px;
border-radius:50%;
overflow:hidden;
border:2px solid #cc0000;
background:url("http://www.placehold.it/100x100");
vertical-align:middle;
text-align:center;
}
Using the css property border-radius you can round the edges of an element. If you use border-radius: 50% you will end up with a circular image.
So, if you had the following HTML:
<img src="some.url" class="circle">
and the following css:
.circle{ border-radius: 50%;}
You will end up with a rounded image. In order to have a circular image, the dimensions of the element that border-radius is being applied to must be square. So, you will need to set a height and width property in the css as well.
.circle{
border-radius: 50%;
height: 150px;
width: 150px;
}
You should be aware if you are not using a square image and are applying the dimensions directly to the image, you could end up stretching or smushing the image.
To add the border to the image, you need to include the border property in your css:
.circle{
border-radius: 50%;
height: 150px;
width: 150px;
border: red solid 2px;
}
Alternatively, you could just create a button element and add the image as a background image to that element like this:
//html
<button class="circle"></button>
//css
.circle{
background-image:url("http://upload.wikimedia.org/wikipedia/commons/7/71/St._Bernard_puppy.jpg");
background-size: cover;
background-position: center center;
border-radius: 50%;
border: red solid 2px;
height: 150px;
width: 150px;
}
This will create a button element with a background image from the url specified. The background-size property will ensure that the image is always large enough to cover the button. The background-position will center the background image inside the button so that the portion of the image that is shown on the button will be from the center of the background image.
This might be a better option for you since you can change the background-position property to position a background image and keep the focus of that image in the center of the new circular element you have created.
In order to use the round image as a button you have a few ways you can go. The best would be to use pure javascript or use jQuery to select the rounded element and add a click event handler.
You could also wrap the rounded element in an <a> element and simply turn the rounded element into a link. Like this:
<button class="circle"></button>
In this case, you could remove the button if you wanted:
However, make sure you then add display: block; to your css for the .circle class:
.circle{
display: block;
background-image:url("http://upload.wikimedia.org/wikipedia/commons/7/71/St._Bernard_puppy.jpg");
background-size: cover;
background-position: center center;
border-radius:50%;
width: 150px;
height: 150px;
border: red solid 2px;
}
Related
I will attach an image with the effect I'm trying to achive using html and css.
Instead of the black color, I'll have an image, and I want to make an white overlay to give the impression of a round bottom. This could be done using an background image but I'd like to make this using css and keep that option as a last resort.
Setting 50% to border-bottom-left-radius and border-bottom-right-radius should give you the expected results.
border-bottom-left-radius: 50%;
border-bottom-right-radius: 50%;
div {
background-color: black;
width: 400px;
height: 50px;
border-bottom-left-radius: 50%;
border-bottom-right-radius: 50%;
}
<div></div>
Something like this:
div {
background-color: orange;
width:500px;
height:200px;
border-bottom-left-radius:50%;
border-bottom-right-radius:50%;
overflow: hidden;
}
<div>
<img src="http://lorempixel.com/output/city-q-c-640-480-5.jpg">
</div>
This shape can be achieved by using 2 HTML elements.
We set the rectangular primary element to overflow: hidden.
The child element should be shaped as an oval (can be done via border-radius), and scaled+translated a bit so that it has only the bottom edge within the main element area.
Please try this jsFiddle.
I have a button that contains text and an image illustrating a click event. I understand it is feasible to display an image as a background on the button.
CSS:
.upperLeftButton {
display: inline-block;
background-image:url(Images/checkmark.png);
height:50px;
width:200px;
}
HTML:
<asp:Button ID="checkInButton" runat="server" Text="Check In" OnClick="checkInButton_Click"/>
Is there any way to display the image and text side by side within the button?
Yes...use background-position but that will depend on the look you are going for...which we can't tell without the actual image.
Quick demo...
.upperLeftButton {
display: inline-block;
background-image: url(http://lorempixel.com/output/abstract-q-c-25-25-7.jpg);
background-repeat: no-repeat;
background-position: center left 25px;
height: 50px;
width: 200px;
}
<button class="upperLeftButton">Check</button>
Add an img tag inside the button
Because the button element can contain inner HTML content, you may use an img tag as an alternative to setting a background-image in CSS.
img {
margin-right: 5px;
vertical-align: middle;
}
button {
padding: 5px;
}
<button type="button">
<img src="http://placehold.it/30" alt="Place Holder" />
My cool button
</button>
Add padding-left: 30px (or whatever width of checkmark.png is) and background: url(images/checkmark.png) top left no-repeat to button CSS, so it will offset the text, but leave icon in left corner.
EDIT: also, must likely you should add padding-top: 10px (or so) as well, so text is centered vertically in middle to icon as well.
Another idea is to redesign (even with simple paint) background and add 'blank' space for text and place it there with css.
.button{
background-image: url('http://community.avid.com/cfs-filesystemfile.ashx/__key/CommunityServer.Components.PostAttachments/00.00.53.19.51/WhiteBlack10801440x1080.png');
background-size: cover;
width: 200px;
height: 50px;
text-align: left;
padding-left: 32px;}
Like in fiddle here:
https://jsfiddle.net/pp719t5n/
Black space is your image and white space background for your text.
I was wondering if there is anyway to make the background image in a div expand to the border.
Let's say I have a div with a background and a border. I want to make the background image in the div expand over the border so it kind of looks like there is no border at all(I know there's no point for this but I need to know how to do it for something I'm working on).
Maybe something like this code:
#myImage {
height: 200px;
width: 500px;
background-image: url("image.jpg")
background-repeat: no-repeat;
border: 0px solid black;
overflow: hidden;
}
I have 40*40px png with transparent background with a 30*30px circle in the middle.
I would like to use that png as a button with a simple hover effect, but i want the hover effect to take place only when the cursor is actually on the circle, not on the transparent background.
Is there a plain HTML+CSS solution for this? I tried to check it here and on other forums, but I didn't find anything.
Yes, you can do this with HTML and CSS. First create a circle element and place it before your image. Then wrap both your image and the circle in a container, like this:
<div class="container">
<div class="circle"></div>
<img src="your-image.jpg" />
</div>
Then, use position: absolute to position the circle on top of the image (align it with the circle that's in the image), and use the + selector to select the next adjacent element when the circle is hovered.
.container {
position: relative;
}
.circle {
position: absolute;
top: 100px;
left: 100px;
width: 100px;
height: 100px;
border-radius: 50%;
background: #222;
}
.circle:hover+img {
border: 5px solid aqua;
}
See DEMO.
Check out this script if you need to activate hover/click only when mouse is within the circle (and not in the square bounding box) http://tympanus.net/codrops/2011/11/22/hover-and-click-trigger-circular-elements/
It’s not possible in CSS only, as all elements are treated as rectangles, even if they are rendered with rounded corners.
Is it possible to hide the specific area of a CSS background image using clip? for example I have multiple icons on image but I want to show only one icon. Because area of Div is greater then the icon size so other unneeded icons are also showing. Can I hide them without making another image for that single icon?
Jsfiddle http://jsfiddle.net/jitendravyas/FyMW6/1/
Basically you create a container for each image which you use to dictate the area of the image.
http://jsfiddle.net/FyMW6/4/
HTML:
<div class="button">
<div class="text">Lorem ipsum dolor sit amet</div>
<div id="house" class="icons"></div>
</div>
CSS:
.button {
width: 300px;
float: left;
border:1px solid red
}
.text {
float: left;
width: 245px;
}
.icons {
background-image: url("http://www.smtusa.com/uploads/cssexample.jpg");
background-repeat: no-repeat;
width: 50px;
height: 50px;
float: right;
}
#house {
background-position: -56px -45px;
}
#gear {
background-position: -56px -106px;
}
No, I don't think so, at least not in CSS2.
You can't apply the clip property to a background image.
CSS3 has the background-clip property that seems to do exactly what you need. It comes with limited browser support at the moment, though. CSS has the background-clip property but it allows only to specify which bounding box the image is rendered in.
There may be no solution for this except using another container for the icon.
easiest way is to set the class to display: none;