background tiled with flexible background image on top (oh - and a shadow) - css

I have a site design that uses background images and textures as a feature of the site.
See background design concept here: http://www.flickr.com/photos/54233587#N03/6145240784/in/photostream
The background is intended to work like this:
The page background has a tiled pattern (or on some pages there will be solid background colour).
The top part of the background is overlayed with a background image. The background image is a large image (2000px wide) and needs to be centred in the window. Depending on the page, the height of the image will crop from the bottom (that is, on one page the image may need to be 400px, while on others it may be 450px). This background image also has a CSS3 box-shadow applied so there is a slight shadow at the bottom of the image. This background image cannot use a fixed position - that is, it should move with the page if it is scrolled.
All other page content sits on top of the background in a centered div, indicated by the black box in the screenshot.
I have tried to achieve this by targeting the HTML5 html node for the tiled background.
html {
background: url(../img/pegboard.jpg) repeat center;
}
Then, for the overlaying background image I've been using a div element to insert an image.
<div id="bgimage"><img src="mybgimage.jpb"></div>
Then styling the img to try and center, not be fixed when scrolling, and resize the div to crop image from bottom. All without much success.
Thanks.

I would do something like this.
HTML:
<div id="bgimage"></div>
<div id="content">
Actual content goes here.
</div>
CSS:
body {
background: url(../img/pegboard.jpg) repeat center;
}
#bgimage {
position: absolute;
top: 0;
left: 0;
right: 0;
background: url(../img/mybgimage.jpg) no-repeat center;
height: 400px;
box-shadow: 0 5px 5px -5px #000;
}
#content{
margin: 0 auto;
width: 960px;
height: 1000px;
background: #000;
filter: alpha(opacity=50);
opacity: 0.5;
}

Related

How to conform image to match border-radius of a div?

So I have the following css code:
.crop img{
max-width: 100%;
position: relative;
top: -50%;
/* width:100%; */
border-radius: 10px 10px 0px 0px;
object-fit:cover;
object-position: center;
}
What this code does is it takes an image from a URL, places it inside a div that I have, fills the div, then moves up 50%, so that the middle half of the image is displayed in my div. The problem here is that the div my image is in has rounded corners in the top left and right, but by moving the image up 50%, I can't confirm the image to fit the rounded corners (see image below).
Is there anything I can do to make the image fit into the rounded corners of the div, without declaring them manually? Is there like an inherit tag or anything I can use? Sadly I can't provide a working example of my problem, as it is locked behind a login page.
Just add {overflow: hidden} to your div.
If anyone is interested, the answer is courtesy of #wilkoklak, who says to use overflow:hidden; in the parent div with the rounded corners. Thanks, wilkoklak!

How to place the image outside of the div with transparent background?

The white part is a container div centered horizontally on the website. The stripes are the background image of the body element. I have the rest of the dumbbell as a picture and I want to place it outside of the container so that there's a complete picture.
Usually it would be positioning the image absolutely in the container div and moving it a bit to the right.
But my problem is that the background of the whole image is white. So the result is:
Is there a way to solve this?
<body>
<div id="container">
<div id="pimg"><img src="../images/image_part.png"></div>
</div>
</body>
html {
background-image: url('../images/stripes.png');
}
#container {
position: relative;
background-color: white;
background-image: url('../images/image.png'); // first picture
background-repeat: no-repeat;
background-position: top right;
width: 800px;
height: 90%;
margin: 0 auto;
}
#pimg {
position: absolute;
top: 0;
right: -100px; // second image
}
You can set the following css to hide the part of the image that goes outsite the div#container
#container
{
overflow:hidden;
}
The above approach will crop the image, and if you don't want to do that you could set this so that the image has maximum width the one of it's container
#pimg
{ width:800px; }
#pimg img
{ max-width:100%; }
The main problem is that your PNG has a white background instead a transparent background like you want so:
Edit "image.png" in an image editor software like Adobe Photoshop or GIMP
Open it in the image editor
Erease the background (because you have a PNG, yes, but it has a white background)
Save the image in PNG or GIF format, because JPEG doesn't support transparent backgrounds
Tip: Photoshop have an option to save a picture for the web, Control(Command in Mac) + Shift + alt + S, this option can help you to optimize the image adjusting its params
Here's a Photoshop tutorial: http://www.youtube.com/watch?v=PLA2FaOXkkg

HTML background overlapping body background

I have a background image on the html and the body tags as I have a repeating background on the html that I want to grow in height with the content. On top of this is the body background image - which is the main background image (that appears to dissolve into the html image, but it's just overlapping it).
This is working fine EXCEPT for when someone does a browser zoom. Oddly, the HTML background begins to creep over the body background on the right hand side.
html {
margin: 0; padding: 0; border: 0;
background: #000000 url("menu/images/redline2.jpg") repeat-y center;
}
body {
margin: 0; padding: 0; border: 0;
background: url("menu/images/about_bg2.jpg") no-repeat center;
}
Link to example of the issue: http://www.bitchofrome.com/about/about3.html
This is a common issue, and there's a simple solution for it. It often happens when you have a 100% width container with a background color or image. If you narrow down the browser window (or zoom) and then scroll right, the background has disappeared (as it doesn't get redrawn). The fix is to set a min-width on the outer container equal to (or greater than) the width of the inner elements.
In this case, what's needed is this:
html {min-width: 1100px;}

3 columns div css

I'm trying to build a webpage with 3 columns. The one in the middle (centered) needs to have fixed width (1000px) and the other 2 with no specific width. When the user resizes the window only the left one and the right one should be resized. Is this possible?
Regards
Yes this is possible
You should create one maindiv in your css and set the background to repeat in your body like shown below and give it a background color/gradient/whatever you like. I usually use a 1px width gradient picture.
Setting the same background color and image in your div as in your body will help you keep an even background depending on your design (i.e. You have a design that has a margin at the bottom of 20px to create a clear space, then the background will follow through instead of showing white)
STYLESHEET.CSS
body {
margin: 0px;
background-position: 0px 0px;
background-repeat: repeat-x;
background-color: #03255d;
background-image: url(../img/bg_gradient.gif);
}
#MainDiv {
position: absolute;
width: 1000px; /* width of middle column */
z-index: 1;
top: 0%;
left: 50%;
margin-left: -500px; /* should be half and minus of width to center it */
background-color: #03255d; /* set background color same as body */
background-image: url(../img/bg_gradient.gif); /* set background image same as body */
}
Now in your HTML after the body tag you start with your MainDiv and before the body end tag you close the MainDiv
INDEX.HTML
<body>
<div id="MainDiv">
Your HTML here
</div>
</body>
Now when you resize your browser, it resizes the background and your middle column stays centered

CSS Sprite vertical repeat problem

I am trying to include css sprites in my webapp. The thing is I have arranged my website background vertically in sprite image. Now, one portion of the sprite needs to be repeated vertically.
I was trying the following code...
#page-wrapper {
margin: 0px auto;
background-image: url(../images/background.png);
height: 100%;
width: 1000px;
}
#page-wrapper #content {
background-position: 0px -80px;
background-repeat: repeat-y;
height: 1px;
}
I am confused in the height property of content class. How should I define the height of the section which I want to repeat and the height of the div(#content)?
Regards
Vikram
You can repeat the sprite vertically if your sprites are arranged horizontally in the image.
You can not repeat part of an image in the background. Setting the height only changes the height of the #content element. The images is always repeated completely.

Resources