Click here to Skip to main content
15,885,659 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I have an image which is 500X500px size.. Now i have set the image as background of body.. I have some content in my div tag..

My question is how do i make only that much part of the background image of body visible which is according to the size of content in div.. I dont make to visible the whole image of body background as i dont want to have vertical scroll bar..

Eg..body background size is 500X500 px and the content inside div is 200X500 px(h and W) , so i need to make only 200px of body image to be visible..

Please help me.

Regards,
Krunal Panchal
Posted

1 solution

This approach would not be simple and would not be productive. If you change your window a little bit, you would need your image width of 201, then 203, 205… Why?

The typical HTML approach is the opposite: you change the size of div according to the size of the image, automatically. Don't you think it would be much better? Perhaps you need to review your design and learn liquid, fluid and elastic design. Please see my past answer and the links: To Get Screen resolution[^].

[EDIT]

After OP's clarification in the comments below:

I just tried it: you can use CSS clip property: http://www.w3schools.com/cssref/pr_pos_clip.asp[^].

The practical use of it could be somewhat complicated: if you want to change the size dynamically, you have to write JavaScript modifying clip parameters depending on the current size of the parent div element. The best way of such manipulations would be using jQuery. Please see: http://api.jquery.com/category/css/[^].

—SA
 
Share this answer
 
v2
Comments
krunalpanchalN 10-Sep-13 2:11am    
Hi Sergey,

Thanks for your response.. but i dont need to have image of the following sizes i.e. (201,2013 etc)..instead the image would be of its actual size but its visible portion would be according to the height of content div.

Please help.

Krunal
Sergey Alexandrovich Kryukov 10-Sep-13 2:28am    
Ah, part of image... Sorry, I didn't get it a first. This looks somewhat complex. Normally, the image will "push" the size of outer element to fit. Perhaps you would need to crop the image in the fly...
—SA
Sergey Alexandrovich Kryukov 10-Sep-13 2:35am    
Oh, I got it. Please see the updated answer, after [EDIT].
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900