0
<div id="gallerywrapper">
    <img src="ECC1.png"> <!--1-->
    <img src="ECC2.png"> <!--2-->
</div>

CSS:

#gallerywrapper img{ 
    border: 2px;
 }

Why won't the css selector apply the border attributes to the pictures? Am I using the wrong selector?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Bryan
  • 117
  • 3
  • 13

2 Answers2

3

Your selector is perfectly fine, what is wrong is the lack of 'style' for the border.

Something like border: 2px solid; would work just fine. This will set all four sides to be 'solid' at 2px thick; opposed to the default 'none' at 'medium', what ever 'medium' is.


Just as a side note or point of reference, your current selector is 'any img tag that is a descendent of a #gallerywrapper', if you swap to #gallerywrapper > img you will get only the direct children. In other words, buy adding the > you could have say a <p> with an image in it would not get a border, and as it is not a direct child. Either way works given the HTML the OP posted, and neither is 'bad'.

thecoshman
  • 8,394
  • 8
  • 55
  • 77
  • can you please describe more that why > tag is not good? as i want to know so can be aware next time when m using it. i just want to know why its wrong in this case..thanx – Leo the lion Jul 07 '15 at 08:27
  • @Leothelion no, I can't. I never said it was good or bad. I simply stated that the selector OP had would work, and then explained how the addition of `>` changes it's meaning. I leave to the reader to decide if they need to use that extra specification, but I'd take the same principle as with regex, try to keep it as simple as possible to do what you want. – thecoshman Jul 07 '15 at 09:16
  • no m not saying that my question is wrong or but i just want to increase my knowledge..:) so i also won't get any problem in future..and yes i also mentioned that thing in my ans that issue is with only border style and about >, this is the normal way m using so..hope you can understand. – Leo the lion Jul 07 '15 at 09:29
0

use this

#gallerywrapper > img{ border: 2px solid; }

and it will work.

UPDATED

As OP asked clearly that he don't know why its not working and needed solution so i gave him final solution(No More chit chat). He did not ask for more details so i did not provide. but here i go..

User did not define any style for border which is must..Read more here

Without Border-style, no border will show..that's why that selector wasn't working.And in general m using the way i provide so i provided that solution so i don't think its wrong or confusing.. But...Nothing..

Leo the lion
  • 3,164
  • 2
  • 22
  • 40
  • Can you edit your answer and include an explanation why you're solution works and why OP's doesn't? – Ivanka Todorova Jul 07 '15 at 07:15
  • This answer is confusing. Without any explanation as Ivanka Todorova has pointed out, it seems to suggest that the problem is indeed in the selector, but it isn't because there is no reason `#gallerywrapper img` would not work if `#gallerywrapper > img` does. In reality, the problem is that the border style is missing, which this answer fills in along with changing the selector. – BoltClock Jul 07 '15 at 07:18
  • 1
    Normally I don't comment on downvoted answers because I know people will point fingers at me, but I'm doing this to help you. You are suggesting that something is a solution when it is not. If your answer is self-explanatory, fine, but if your answer is misleading without an explanation then it's not a good answer. If the OP is new, then all the more you should explain it to them so that they can understand - all you had to say was "you need a border style", or just not change the selector, and it would become clear. Explanation is not chit chat; accusations of jealousy and hurt feelings are. – BoltClock Jul 07 '15 at 07:37
  • @BoltClock,i have been through your profile and i got that what type of mentality you have so no need for further explanation but new user are coming on so, just for quick answer to complete their project asap. And it wasn't leading to any wrong way..and yes you can see, the other question, he said you need color but he did not mention that he need style so basically he is leading to wrong way, not me..but you did not say anything to him..great – Leo the lion Jul 07 '15 at 07:39