How to set fixed background position from right side in css? [duplicate] - css

This question already has answers here:
Offset a background image from the right using CSS
(17 answers)
Closed 7 years ago.
In this case
li {background: url("../img/grey-arrow-next.png") no-repeat right center;
border-bottom: 1px solid #D4E8EB}
I want 20px space in right side before to background image and I can't give margin on li because border should touch the edges.
So I need to set 20px but it takes 20px from left side not right side.
li {background: url("../img/grey-arrow-next.png") no-repeat 20px center;
border-bottom: 1px solid #D4E8EB}

in your css mention position right then "spacing value(50px)" then other position(center/top)
li {background: url("../img/grey-arrow-next.png") no-repeat right 50px center;
border-bottom: 1px solid #D4E8EB}
Older Browser and IE8 and old version of IE does not support this code. Latest updated browsers has no conflicts with this method and hopefully future updates will support it too.
If you are using modern browser, try background-position: calc(100% - 50px) center; as suggested in another answer too. calc has long way to go as it is logically and mathematically capable to produce much accurate result.

You can use the CSS3 "calc" function:
example:
background-position: calc(100% - 10px) center;

Just add 20px blank space to the image right side in a graphic editor.

You can use other object inside li tag, and give it your background image with a margin-right:
li #image {
margin-right: 20px;
background: url(pp.jpg) no-repeat right center;
}
li {
border: 1px solid #D4E8EB;
}

use the following code to add 20px to the right of the background-image --
li {background: url("../img/grey-arrow-next.png") no-repeat right center;
border-bottom: 1px solid #D4E8EB; padding-right:20px}
use the following code to add 20px to the left of the background-image --
li {background: url("../img/grey-arrow-next.png") no-repeat right center;
border-bottom: 1px solid #D4E8EB; padding-left:20px}

border-right: 20px solid transparent;

unfortunately the 'easy' solution is edit your image and add 20px right and bottom of transparent space.
you could achieve it with background-clip / background-origin probably but that'd take a bit of playing with...

place a span tag within the <li> and add the margin to that, that way your <li> should still stretch to the edge along with your border.

Related

div or asp:Panel background image

I am trying to get a background image to display in the bottom right corner of a div (or asp:panel) but I believe that the display:inline-block is causing it to not show. That is required because I have multiple boxes horizontally aligned on the screen (without it they display vertically).
css:
.showIcon{
background: url('Images/icon.png') no-repeat right bottom;
display: inline-block;
box-shadow: 2px 2px 2px #808080;
}
Is there something wrong with the css?
I do have a table displayed within each div, can that be the reason?
There is no problem with your code. And also as you asked, no table won't make any difference.
See this fiddle with your code: http://jsfiddle.net/3V8m9/2/
The only thing I added is the dimensions: height: 100px; width: 100px; to illustrate.
There can be two scenarios. One, either your image path is not correct. Two, width/height may not be adequate enough.
If you believe display:inline-block is the issue. You can always use float left to align each against each other.
CSS
.showIcon{
background: url('Images/icon.png') no-repeat right bottom;
float: left;
box-shadow: 2px 2px 2px #808080;
} code here

Vertically centering menu items between menu separator images

This is what I'm trying to achieve, and have come pretty close:
This is my CSS:
li {
float: left;
position: relative;
padding-left: 55px;
background: url(../../images/separator.png);
background-repeat: no-repeat;
background-position: left bottom;
height: 87px;
}
a {
font-size: 15px;
line-height: 67px;
}
I'm almost there, but there are a few problems. The only way I came up with to have the menu items vertically in the middle of the separators was to use line-height. But now of course when hovering over the links the hover is the height of the line-height, and I don't want that.
Also: is there a way to have the menu items go "inside" the separator images, like in the picture? The separator image is a transparent png. If not I'll just decrease the padding on the menu items to try and get them closer.
First method:
Give the link a height, position it 50% from the top, half the height back to top:
a {
font-size: 15px;
height:30px;
display:block;
position:relative;
top:50%;
margin-top:-15px;
}
Demo
http://jsbin.com/ovaqix/1/edit
Second Solution
Make the a element display:table-cell and same height as li, then use vertical-align:
a {
display:table-cell;
height:87px;
vertical-align:middle;
}
Demo
http://jsbin.com/ovaqix/2/edit
Table-cell doesnt work in IE7
Have you tried changing stating a height in a:hover ?
To have the menu items go inside the separators, I think that you need to create after and before pseudo elements, with the border hack to generate triangular shapes. Something in he line of:
a:before {
border-top: 38px solid transparent;
border-bottom: 60px solid transparent;
border-right: 60px solid black;
}
If you provide more details, I can be more specific.

how to stop background 30px from bottom

I have a background image to blockquote but i want it to stop 30px or so from the bottom of the blockquote.
current css:
.project-inner-quotes blockquote
{
background: url("Img/quoteTop.gif") no-repeat scroll center top transparent ;
margin: 0 3px 0 3px;
font-style:italic;
font-size:14px;
}
the reason is I have a p tag in the quote which has the closing speech buuble...
.project-inner-quotes blockquote > p:last-child
{
background: url("Img/quoteBot.gif") no-repeat scroll center bottom transparent;
padding: 30px 20px 50px 50px;
}
that can be "faked" with css in a tricky way because it depends on your design. I will make some assumptions now, first of all your blockquote container element has a #fff background (could be any color really).
in that case you could do this:
.project-inner-quotes blockquote > p:last-child {
background: url("Img/white-image_8x30") repeat-x scroll left bottom transparent;
}
.project-inner-quotes blockquote > p:last-child span {
background: url("Img/quoteBot.gif") no-repeat scroll center bottom transparent;
padding: 30px 20px 50px 50px;
display: block;
}
this will "fake" a 30px offset from the bottom. wrap your p text inside the span that will get the background image and display block to get the padding applied.
you will need to create a 8px wide (for better tiling) and 30px high image that will be applied to the paragraph at the bottom. the color of the image will be the color of the background you are trying to get when "offsetting" the quoteTop image... however this approach will fail if you do not have a solid color as main background.
let me know if it's not clear

How to get rid of spaces before (on top of) a div

I have this weird issue... The last line of CSS rules is commented. When it's commented, the div has a space on top. But with the comment removed, the border comes in and the space is gone!
#divFooter {
height: 99px;
display:clear;
width: 970px;
margin: 0 auto;
text-align:center;
background: #000000 url(../../Images/TopBanner-Slim.png) repeat-x;
color:white;
/*border: 1px solid yellow;*/
}
I don't want the space. I also don't want the border. Is there something wrong in my CSS rules?
The image is 99px tall.
Any ideas are really appreciated.

How to Create flexible Rounded corners?

I want to Create DIV based Flexible corners. as per shown in the Image.
This is Not regular rounded corner, but something more complicated. This is Something like challenge .
And Please Note that I want Image based rounded Corners, so please give answer as per requirments.
Thanks a Lot
Well, the easiest answer is: use CSS3:
#roundedCornerDiv {
-moz-border-radius: 1em; /* for mozilla-based browsers */
-webkit-border-radius: 1em; /* for webkit-based browsers */
border-radius: 1em; /* theoretically for *all* browsers
dependant on implementation of CSS3 */
border: 12px solid #ccc;
}
you should be able to do this with 9 explicitly sized and floated divs. the corner divs are fixed size and have background-url for the 4 corners and the side divs are repeat-y and top bottom divs have repeat-x
You should look into The Thrashbox approach for this.
You can use a series of spans and 4 images, one for each corner, to make a resizable rounded corner div. Like this:
div {
background: white url(topleft.gif) top left no-repeat;
}
div span {
display: block;
background: url(topright.gif) top right no-repeat;
}
div span span {
background: url(bottomright.gif) bottom right no-repeat;
}
div span span span {
padding: 2em;
height: 0; /* fixes a padding bug in IE */
background: url(bottomleft.gif) bottom left no-repeat;
}
div span span > span {
height: auto; /* sets the height back to auto for all other browsers */
}
And now for the HTML:
<div><span><span><span>Round corners!</span></span></span></div>
For an actual example and code please refer to this page for a working example and source code.
border-radius: 10px 10px 10px 10px;
first is the left-upper corner.
second is the right-upper corner.
third is the right-lower corner.
fourth is the lower-left corner.
you can use that basically in any tag where you want the round corners. just remember to specify the border like:
border: 2px solid black;
if you specify the border separately, eg:
border-left: 6px;
border-right: 6px;
border-top: 2px;
border-bottom: 2px;
you can get some awesome-looking stuff.

Resources