How to scale down CSS background-image when using various background-positions? - html

I use three shots of a button on an image to give impression of a button in action.
Normal / Hover / Active.
Here is an image of that:
The CSS code for picking the right image for the right state is here:
#btnSet1 {
position: absolute;
left: 200px;
top: 100px;
}
.btn1 a {
padding: 0px;
text-decoration: none;
opacity: 0.7;
}
.btn1 a.link1 p {
position: relative;
text-align: center;
left: -10px;
top: 20px;
color: white;
font-family: sans-serif;
text-decoration: none;
text-shadow: 5px 5px 5px #111;
opacity: 1;
}
.btn1 a.link1:link {
display: block;
height: 90px;
width: 144px;
background: url(../images/btn3.png) no-repeat 0 0;
}
.btn1 a.link1:hover {
display: block;
height: 90px;
width: 144px;
background: url(../images/btn3.png) no-repeat 0px -90px;
}
.btn1 a.link1:active {
display: block;
height: 90px;
width: 144px;
background: url(../images/btn3.png) no-repeat 0px -180px;
}
.btn1 a.link1:visited {
display: block;
height: 90px;
width: 144px;
background: url(../images/btn3.png) no-repeat 0px -270px;
}
#tHeader {
position: absolute;
top: 100px;
left: 300px;
}
I made these images to be large, because I need to scale them, occasionally. The HTML image element can be used to stretch any image, but I only show a region of the total image with the CSS style. So, for the sake of clarity, let's call each button face being shown a view... so, how can I stretch the view of each button face in code, since the x y refer to unscaled metrics of the image?

background-size
sprite *
px
css
div{
width:75px;height:45px;
background:url(http://i.stack.imgur.com/8yNbR.png) no-repeat 0px 0px;
background-size:75px 135px;
text-align:center;
line-height:45px;
}
div:hover{
background-position:0px -45px;
}
Demo
http://jsfiddle.net/katPx/
percent
css
div{
width:75px;height:45px;
background:url(http://i.stack.imgur.com/8yNbR.png) no-repeat 0% 0%;
background-size:100% auto;
text-align:center;
line-height:45px;
}
div:hover{
background-position:0% 50%;
}
Demo
http://jsfiddle.net/katPx/1/
this last one scales automatically based on the container size.
use a class
.btns{
width:75px;height:45px;
background:url(http://i.stack.imgur.com/8yNbR.png) no-repeat 0% 0%;
background-size:100% auto;
text-align:center;
line-height:45px;
}
.btns:hover{
background-position:0% 50%;
}
html
<div class="btns">whatever</div>
demo
http://jsfiddle.net/katPx/2/

How about using CSS background-size?
.btn1 a.link1:link {
background-size: 144px 90px;
}
This post has more info - Set size on background image with CSS?

You can achieve this by using percentage-based background-size and background-position. Here is a basic working example you can adapt to your needs.
JSFiddle
a {
display: block;
background-image: url('http://i.stack.imgur.com/8yNbR.png');
background-size: 100%;
background-position: 0 0;
background-repeat: no-repeat;
}
a:hover {
background-position: 0 50%;
}
a:active {
background-position: 0 100%;
}
a.big {
width: 150px;
height: 90px;
}
a.small {
width: 75px;
height: 45px;
}

Related

CSS trapezoid shape clickable area issue in chrome browser

I'm trying to get a trapezoidal perspective shape to have the whole area be clickable. I've gotten it to work in Firefox and even IE, but Chrome isn't cooperating too well.
Here's a fiddle with the shape and a link: http://jsfiddle.net/9n9uh6f6/1/
As you can tell, the link doesn't become active until you hover over the 'area' part of the text. In other browsers, the whole height of the shape is clickable.
I read that Chrome renders a perspective image differently and perhaps that's why it's not doing what it's supposed to.
Here's my CSS:
.prodcaptions {
width:136px;
height: 85px;
position:relative;
left:10%;
text-transform:uppercase;
text-align:center;
letter-spacing: 1.6px;
color: #000;
}
.prodcaptions:before {
content:"";
position:absolute;
border-radius:1px;
box-shadow:0 0 0 3px #27628e;
top:-5%;
bottom:-11%;
left:-1%;
right:-5%;
-webkit-transform:perspective(40em) rotateX(-45deg);
transform:perspective(40em) rotateX(-45deg);
}
.prodcaptions a {
z-index:999;
position:relative;
height: 85px;
display: block;
padding-top: 25px;
}
Please have look at this code:
.prodcaptions {
position: relative;
height: 150px;
width: 150px;
margin: 50px;
padding: 10px;
perspective: 150px;
perspective-origin: 50% 0;
}
a{
padding: 50px;
position: absolute;
border: 1px solid black;
transform: rotateX(-15deg);
}
Seems to work the way you want it. fiddle
Try this shape for link trapazoid shape - jsFiddle
Advantage - you can change skew property to change angle of shape! Easy and effective! Reverse value for reverse shape!
html
Click Here!
css
a {
display: block;
z-index: 1;
position: relative;
/* custom sizes */
width: 136px;
height: 85px;
/* demo-only decoration */
margin: 100px auto;
font: 16px/50px Arial, sans-serif;
text-transform: uppercase;
text-align: center;
background-color: orange;
}
a:before, a:after {
content:'';
position: absolute;
top: 0;
left: 0;
width: 100%;
bottom: 0;
z-index: -1;
/* demo-only decoration */
border-radius: 4px;
background-color: orange;
}
a:before {
transform: skew(-20deg);
left: 25px;
}
a:after {
transform: skew(20deg);
right: 25px;
left: auto;
}

Highlight text on image in CSS

I have a some text on image, but the problem is i am using opacity so that text gets highlighted but it makes images look very dull.
Here is Updated Fiddle Link
Html
<div class="subcontainer">
<img src="http://i58.tinypic.com/11kbnlf.png" alt="">
<h3 class="header3">Motivate Yourself</h3>
</div>
CSS
.subcontainer {
width: 100%;
height: 100%;
float: left;
position: relative;
border: 3px solid white;
}
.imgcolumn {
background-repeat: no-repeat;
float: left;
width: 60%;
height: 80%;
margin-left: 130px;
margin-top: 45px;
position: absolute;
opacity: 0.4;
filter: alpha(opacity=40);
}
.header3 {
z-index: 100;
position: absolute;
float:right;
color: black;
font-size: 25px;
margin-top: 175px;
text-align: center;
margin-left: 170px;
}
Is there any other way i can highlight text by keeping image as it is.
Note : I am trying to achieve something like this PAGE and i don't see image being blurred or having opacity.
use this fiddle
eg:
.header3 {
z-index: 100;
position: absolute;
float:right;
color: black;
font-size: 25px;
text-align: center;
position:absolute;
width:80%;
height:45%;
background-color:rgba(0,0,0,0.4);
top:20px;
left:24px;
line-height:150px;
}
You could also set the background-image of the parent container then lay another element over top of it with a semi-transparent background color as I have done here. Then, the highlight can be controlled via the opacity of the BACKGROUND of the overlay layer without affecting the text opacity.
http://jsfiddle.net/xDaevax/8Mzh9/
.subcontainer {
border: 3px solid white;
margin: 0px auto;
background: url("http://i61.tinypic.com/2ur6rk1.png") no-repeat center top;
height: 225px;
}
.imgcolumn {
width: 60%;
display: table;
height: 100%;
margin: 0px auto;
border: solid 1px #000000;
background-color: rgba(255, 255, 255, .6);
}
.header3 {
color: black;
font-size: 25px;
text-align: center;
position: relative;
top: -120px;
}
HTML
<div class="subcontainer">
<h3 class="header3">Motivate Yourself</h3>
</div>
The page you gave as an example uses contrasting colors for text and image. For example, that page uses dark images and the text on them is pure white.
If you want the text to stand out, use contrasting colors, or else use a contrasting drop shadow/outer glow (made with image editing software like PhotoShop), or add a semi-transparent background like this: http://jsfiddle.net/P22Cg/
.header3 {
z-index: 100;
position: absolute;
float:right;
color: black;
font-size: 25px;
margin-top: 175px;
text-align: center;
margin-left: 170px;
background-color: rgba(255, 255, 255, 0.5); /* I added this... */
padding: 5px; /* ... and this */
}

Wrapper size increases after adding the button

I have an image wrapper in which i want to show a button on mouse hover with a black background. I tried to do it but it added a white space to the container at the bottom, i dont know why.
HTML:
<div class="tour-box-wrapper" style="margin-right:45px">
<div class="image-wrapper">
<img src="http://static.teambuy.ca/deal/540x254/other/28165573-2014-03-03-28144457-boxhouse-10b.jpg" />
<a><button type="button" class="view-deal-button" >View Deal</button></a>
</div>
</div>
CSS:
.tour-box-wrapper
{
width:45%;
border: 1px solid #BBB;
padding:2px;
background-color: #E7E7E7;
background-image: -webkit-gradient(linear,left top,left bottom,from(#FFFFFF),to(#E7E7E7));
background-image: -webkit-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: -moz-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: -ms-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: -o-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: linear-gradient(to bottom,#FFFFFF,#E7E7E7);
float:left;
display:block;
}
.image-wrapper
{
border:1px solid #E0E0E0;
padding:2px;
display: block;
}
.image-wrapper img
{
width:100%;
}
a.grayscale {
display: inline-block;
background: black;
padding: 0;
}
a.grayscale img {
display: block;
}
a.grayscale:hover img
{
opacity: 0.5;
}
.view-deal-button
{
border: none;
text-align: center;
border-radius: 6px;
text-align: center;
z-index: 999;
position: relative;
left: 343px;
bottom: 36px;
background-color: #CD277B;
padding:6px;
}
.view-deal-button a
{
color:white;
font-size:14px;
}
Note ignore the Javascript which i know will be used to display button on mouse enter but i just want to fix this extra space below the image and want to bring the button to the bottom right corner of the image.
JSFiddle
Your button having a position of 'relative' is what's creating the space that the bottom. It's 'mass' is affecting its parent container. If you don't want it having any 'mass', try positioning it 'absolute' relative to the parent.
This happens because of the relative positioning and the bottom property.
.view-deal-button {
background-color: #CD277B;
border: medium none;
border-radius: 6px;
bottom: 36px;
left: 343px;
padding: 6px;
position: relative;
text-align: center;
z-index: 999;
}
Moving the button right and under the image.
.view-deal-button {
border: none;
border-radius: 6px;
text-align: center;
float: right;
margin: 5px 0;
background-color: #CD277B;
padding:6px;
}
http://jsfiddle.net/b4r3p/3/
Try this css for button
.view-deal-button
{
border: none;
text-align: center;
border-radius: 6px;
text-align: center;
z-index: 999;
position: relative;
left: 343px;
bottom: 36px;
background-color: #CD277B;
padding:6px;
margin: 0% 0% 0% -80%;
}
check this fiddle

Prevent line break in this case

I am trying to prevent line breaking in this Html
http://jsfiddle.net/DD3v8/
It happens that when I resize my window, both icons and text break into new line. I've already tried with whitespace CSS property. I've tried also, a table approach, but the behaviour is the same
Can anyone figure what is happening?
Thanks in advance
try this:
.line {
height: 44px;
width: 100%;
display: inline-block;
background-color: #6c7987;
white-space: nowrap;
position: relative;
}
.icon {
position: absolute;
left: 0;
height: 44px;
width: 90px;
background-color:
#FF0080;
color: white;
text-align: center;
line-height: 44px;
font-family: Arial;
float: left;
font-size: 12px;
font-weight: bold;
padding: 0;
}
.title {
position: absolute;
left: 90px;
color: white;
line-height: 44px;
text-align: left;
padding: 0 0 0 10px;
font-family: Arial;
float: left;
font-size: 12px;
display: inline;
white-space:nowrap;
}
.botoes {
position: absolute;
width: 300px;
right: 0
}
.botao {
width: 46px;
height: 45px;
float: right;
line-height: 44px;
text-align: center;
display: block;
white-space:nowrap;
cursor: pointer;
}
.botaoVerRecurso {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoVerRecurso:hover {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoEditarRecurso {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoEditarRecurso:hover {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoFavRecurso {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoFavRecurso:hover {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoPartRecurso {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoPartRecurso:hover {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoApagarRecurso {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.botaoApagarRecurso:hover {
background: url('http://www.think-cell.com/images/cross.png') center no-repeat;
}
.clear {
clear: both;
}
​
The explanation is simple: with floating, you can't put more width to a holder, which is bigger than the holder's height, the float will automatically drops it, and breaks line.
If you use positions, use it like this:
CONTAINER (position: relative)
SUBelement (posision: absolute, top: 0, left: 0) < put to the top left
SUBelement (posision: absolute, bottom: 0, right: 0) < put to the bottom right
in W3C: http://www.w3schools.com/css/css_positioning.asp
If I understand your problem correcly, you need to be able to resize the window width without having the text and the "x" icons jumping down, is so:
REMOVE CSS FROM .title
min-width: 500px;
See this Fiddle Example!

Top banner image needs to be half the width of the screen and breaking the top of my page

I am working on this site: http://www.problemio.com and I am supposed to make a background image for half of the width of the screen for the very top of the page with the links for log-in, sign-up, etc. and make those links appear on the right side bottom of the banner border.
I tried giving it this css:
.banner
{
position: relative;
height: 80px;
/* These paddings increase the height padding a little bit */
/* padding-top: 10px;
padding-bottom: 5px; */
z-index: 1;
border-style:solid;
border-width:1px;
border-color: gray;
}
.site_title
{
float:left;
margin-top: 10px;
margin-left: 20px;
font-weight: bold;
color: #ffce2e;
text-shadow: 2px 2px 2px rgba(0,0,0,0.8);
font-size:2.5em;
text-align: left
text-color: black;
width: 300px;
}
.site_login
{
width: 700px;
float:right;
height: 80px;
position: absolute;
right: 0.5em;
top: 0.5em;
bottom: 0.5em;
color: black;
text-align: right;
text-align: bottom;
background-image: url('http://www.problemio.com/img/ui/problemiotoprightimage.png');
background-repeat: no-repeat;
background-position: right;
margin-top: 10px;
margin-left: 20px;
}
but for some reason I can not get the log-in, create-profile text to get aligned to the bottom instead of the top. And for some reason the image does not fit perfectly into the borders of the banner div.
How could I accomplish those two things?
Thanks!!
You can make a new div inside the banner div like:
.bgdiv{
position:absolute;
right:0px;
left:240px;
top:0px;
bottom:0px;
background-image: url('http://www.problemio.com/img/ui/problemiotoprightimage.png');
background-repeat: no-repeat;
}
...and for the site login:
.site_login
{
width: 700px;
float:right;
position: absolute;
right: 10px;
bottom: 10px;
color: black;
text-align: right;
text-align: bottom;
}
Which produces: