Skip to content
Advertisement

CSS border not showing when background-coloris added

I have written a code that works great for me. So I have a (half) border around my picture. like the picture below. But when I add a background-color the line dissapears.

Image

Now I want the oppiste colors but there for I need a background-color. So I did that but now the border isn’t showing anymore. So I want a white line with an orange background. There are 3 files. The CSS file, The PHP file u can see here and a file where they get together.

My PHP/HTML

JavaScript
JavaScript

Advertisement

Answer

Like I said already in the comment. The use of box-shadow would be the easier approach to achieve the wanted design. That way you dont need pseudo elements. you can use 2 box shadows with a vertical and horizontal offset.

Lets go through the code and see how it actually works:

1st: you need a border aroudn your image. specifiy the border as white solid with a thickness of your liking.

2nd: We need an orange frame which we’ll get by using the box-shadowattribute with 2 values that are seperated with a comma.

3rd: lets start with the second and last value: -30px 30px 0 0 orange the first number is the horizontal offset which will move the frame 30px to the left. The second number is the vertical offset which moves the frame 30px to the bottom. The third number is the blur value. With 0 it will be a solid color. The fourth and last number is the size. With 0 it has the exact same size as the picture.

4th: To prevent that the whole shadow displays as an orange block, we need to put another box shadow value in front of it. We give it the same offset and blur value. The fourth number we change however. We change it to a negative value of the intended “frame” thickness. In this case -10px which will make the “frame” 10px thick.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement