Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background of <div> CSS

For those who can't wait Fiddle

I have this problem in CSS. The structure of the html and css code looks like this

HTML:

<div class="one">
    <div class="two">
        <div class="three">

        </div>
    </div>
</div>

CSS:

.one{
    width: 500px;
    height: 500px;
    background: url('http://www.moonlightcompanies.com/wp-content/uploads/2013/01/6973_MOONF-PomegranatesOnTree-8536-1.jpg');
    background-size: cover;
    background-repeat: no-repeat;
    padding: 20px;
}

.two{
    width: 300px;
    height: 300px;
    background: blue;
    padding: 20px;
}

.three{
    width: 200px;
    height: 200px;
    background: transparent;
    padding: 20px;
    border: 5px solid yellow;
}

My problem is how do I make the background of <div class="three"></div> that it would be transparent and would blend to the background of the <div class="one"></div>. I want my desired output to be like the attached image. Is this possible ?

enter image description here

like image 586
John Avatar asked May 27 '15 06:05

John


2 Answers

You can try like this: Demo

.three{
    width: 200px;
    height: 200px;
    background: transparent;
    padding: 20px;
    border: 5px solid yellow;
    outline:solid 100px rgba(0,0,255,.5);
}

update the border value as per your requirement.

Updated Demo

.three {
    background: transparent;
    border: solid blue;
    margin: 10px 0px;
    border-width:20px 40px 40px 20px;
}
.inner {
    outline: 5px solid yellow;
    width: 200px;
    height: 60px;
    margin:0;
    padding: 20px;
}
like image 80
G.L.P Avatar answered Oct 14 '22 18:10

G.L.P


I have added :before and :after also for blue background in right and bottom, so that more content can be added in the second div.

Here is the fiddle - http://jsfiddle.net/afelixj/ouy9thkk/15/

like image 31
Felix A J Avatar answered Oct 14 '22 17:10

Felix A J