I have a <div>
which has a background image of wood repeating.
I now want to cut a hole in this for a window. Is there any way to do this in HTML and CSS? Javascript welcome.
See this example on jsFiddle
I have a <div>
which has a background image of wood repeating.
I now want to cut a hole in this for a window. Is there any way to do this in HTML and CSS? Javascript welcome.
See this example on jsFiddle
It's simple - draw the door using paths in the <svg>
element.
<svg xmlns="http://www.w3.org/2000/svg" id="svg-door">
<defs>
<pattern id="wood" patternUnits="userSpaceOnUse" width="1024" height="768">
<image xlink:href="http://i.imgur.com/Ljug3pp.jpg" x="0" y="0" width="1024" height="768" />
</pattern>
</defs>
<path xmlns="http://www.w3.org/2000/svg" d="
M0,0 225,0 225,300 0,300 z
M165,10, 215,10 215,80 165,80 z
" fill="url(#wood)" fill-rule="evenodd"/>
</svg>
The CSS:
#svg-door {
background-image: url(http://pcdn.500px.net/15548893/7f3b7c411716b1fb29c5cffb3efcf8ce33eacd76/15.jpg);
background-size: cover;
box-sizing: border-box;
padding: 100px;
width: 100%;
height: 500px;
}
The advantage of this method is that your background can be anything, and the window is a genuine window (see-through).
I have precalculated the paths for you, and you can find the new door in the fork that I have created from your fiddle - http://jsfiddle.net/teddyrised/qS4G7/
[Edit] For completeness sake, I have also used a wooden texture as the background image for the svg path.
You mean like this? http://jsfiddle.net/UWyvz/3/
I basically used some wood and created a window pane.
Nah, I replicated the window
, but called it windowpane
, then set the window pane's z-index
to be lower than that of the window
's and set the background-color
of windowpane
to white.
Might be a bit of an "ugly fix", but it works: using the border-property
to simulate a door (the element is actually the window).
HTML
<div class="door"></div>
CSS
body {
background-image:url("http://wallpapers.free-review.net/wallpapers/42/Sun_in_white_cloud.jpg");
}
.door {
height:70px;
width:50px;
background-color:rgba(0, 0, 255, 0.4);
border-left: 175px solid orange;
border-top: 10px solid orange;
border-right: 10px solid orange;
border-bottom: 230px solid orange;
border-image:url("http://roundsquarewoodworking.com/wp-content/uploads/2010/07/wood-texture-background.jpg") 25% repeat;
}
EDIT
Updated the code to see the "see-through" effect. The borders aren't perfect, but I hope you get the idea.
I recommend use canvas html5. http://www.html5canvastutorials.com