Jump to content

Box Shadow Problem


Tom8001
Go to solution Solved by Ch0cu3r,

Recommended Posts

What? You started of saying you dont want it to go around the image then you are asking how to go around the image. So which is it?

 

Maybe google for "CSS box shadow generator" and play with them to get the effect you are after?

No?, i said i want a box shadow going around the image but the box-shadow does not fit around the image, on the right & left side of the image there is extra space i want to get rid of to make it fit around the image properly.

Link to comment
Share on other sites

The box shadow will only wrap around the element you are applying it to. If you have extra space around the image there is mostly like some margin/padding being applied to the image or the element the image is contained within? Its hard to tell you without seeing a working example of your problem.

Link to comment
Share on other sites

<div id="img"> <center> <img src="pic.png" /> </center> </div>
	<style>body {background-image: url('http://desktopwallpapers.biz/wp-content/uploads/2014/09/Website-Background-Cool-HD.jpg')} #img {background-color: #000; margin-top: 40px; box-shadow: 5px 0px 5px 0px #ff0000; display: block; width: auto;}</style>

This is my code

Link to comment
Share on other sites

  • Solution

As I said earlier. The box shadow will wrap around the element you apply it to. You have used the box shadow in the #img selector. Therefore it will apply the box shadow to the div with the id of img. If you want the box shadow around the actual image then you'll need to target that element in your css, in which case you use  #img img  selector or just use the  img  selector to apply it to all images

 

Also if you want to center elements dont use <center></centre>. You can apply auto margins for centering

 

CSS

body {
	background-image: url('http://desktopwallpapers.biz/wp-content/uploads/2014/09/Website-Background-Cool-HD.jpg');
} 
#img {
	background-color: #000; 
	margin-top: 40px; 
}

/* apply box-shadow to the <img> within <div id="img"> */
#img img {
	box-shadow: 5px 0px 5px 0px #ff0000;
	margin: 0 auto; /* use auto margins to center element */
	display: block;
}

HTML

<div id="img"><img src="pic.png" /></div>
Edited by Ch0cu3r
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.