How do I make punch-through transparent text in HTML/CSS? - html

I have a div which has css background: rgba(0, 0, 0, 0.85);. Centered in that div is the title of the page. I want to make the title see through (knockout, punch-through, however you want to call it. i.e. see past the div's background black to the background image of the page). The only method of doing that that I have come up with is using an image with the div's background and transparent text and seperate the header part into blocks.
///////////////////////////////////////////////
// (empty) // TITLE IMAGE // (empty) //
///////////////////////////////////////////////
The problem is that I dont know how to create the empty divs such that the image will remain centered (the empty divs need to be there to add the black background). Is there a different way to either do the see through text that doesnt have this problem or a way to center the image div with the empty divs?
EDIT: For an example of the effect that I am trying to achieve, look here:
http://www.showandtell-graphics.com/layer-knockout.html

you can not do this directly; You should use an image for this, or svg might do the trick but that's a hell of a lot more complicated and browsers do not all support it that well.

You should just be able to do this
<div>
<h1>Title</h1>
</div>
Place the background-image on the div
The h1 will be transparent by default.
To center the title, use text-align:center
To center the background image, you can use background-position:center
Example: http://jsfiddle.net/jasongennaro/EQDZd/

Related

Can I make a blank white page on top of a background image?

I currently have a background image but want to insert a blank white page on top of it using either html5 or css3. In addition, I would like the page to be able to be adjusted in terms of dimensions.
From the question description you have provided, I can understand that you need a White Box isnide a Box with an Image as background.
There are many ways to do it, Simple is to create a Div inside Div. Parent Div will have style of background image and child Div will have background color as white and position relative.

Hiding an image behind a div [ z-index ]

I want to hide two images (partially) behind my center/main div ,just like it is shown on the picture i included [the images are blue and the center div is brown,the darker blue color is the part of the image that is supposed to be hiden behind the div].The two images are included in the HTML (as tags).They have to be (as they currently are) part of the HTML and not "injected" via CSS.
The positining of the images isn't a problem,but the "overlaping/hiding" is.I have tried so many times via z-index but to no avail.
Can anyone help ?
link to picture. http://i.stack.imgur.com/ZCKdt.jpg
If you're looking to partially hide them behind the main div, you can either set the parent container (your body tag, if nothing else contains the main div) and add your images in css using background-image: url(image1.png), url(image2.png); and then background-position: left center, right center;. You can also use pixels or percentage to determine the positioning of the horizontal and vertical, respectively. That way, you don't have to bother with the z-index.
However, neither this, nor z-index will solve your other problem of having the images partially visible. For this, you can set the colour and opacity of your main div's background with background: rgba(0, 0, 0, 0);, where the first three zeros can be any number from 0 to 255 which represents red, green, and blue, and the fourth zero represents any number from 0 to 1 (as decimals) which determines opacity. The lower the number, the more transparent the background is. The more transparent it is, the more you can see the images behind it.
Alternatively, you can use opacity: 0; in the same way as above
Without seeing your HTML/CSS, it's going to be harder to diagnose the problem, but it sounds like you're confusing body elements with positioned elements. Z-index won't work for body elements, so you should try to place the blue images into a div and pull that div behind your brown div.
You can find more info and a jsfiddle example at this older post: Hiding a image under the div

How to clip an element's background to display only a part of the image?

For clarification look at the following images.
The first one is what I intend to achieve. It's a text input element with two background images, one on each side.
The second image is the sprite image containing the icons I need.
Now my question is, is it possible to clip a background image to only display a portion of the image? Furthermore is it possible to use it with multiple backgrounds?
1st image:
2nd image:
You're going to have to use two separate icon images to get this to work as you expect at the moment.
With CSS sprites, the background is clipped by the size of the element, there is an experimental CSS3 property called background-clip but it doesn't work the way you want (it will clip to the borders, padding or content of the box, not a specific dimension.)
So create two icons, use one on each side of the element with background-position.
As you can see here, with a spritesheet it will display the entire background image instead of the two icons you want. There is as yet no way to clip BG images in the way that you want. (one day, hopefully!)
You will need to use separate icons OR you will need to have 2 additional elements (for showing the icons) overlaid on top of the input box. The latter will let you use the sprite itself.
Set to your element (let's say div) yor big backgound picture and then adjust with background-position. Your image will be croped by your element size (ex. div).
in your case it will be around:
background-position: -87 -35;
and div size:
width: 28px; height: 30px
with CSS3 you can use multiple background images for an element. to show a specific part from the image you need to set its background-position property.
for example:
background-image: url(sprites.png), url(sprites.png);
background-position: center bottom, left top;
you can also define background-postion in pixels like:
background-position: -5px 10px, -35px 10px;
for more information check this link

scrolling text underneath a fixed position element

I am currently creating a one page website, however I am having an issue, I need the scroll text underneath the fixed element however you can see the text that should be dissapearing under the fixed position element, as the element as a back-ground, which is a transparent png, is there any way I can hide text as it scrolls underneath the fixed position element.
Here is a fiddle of what I have, so far
JS FIDDLE
Ideally I am wanting it so that when text moves behind the box with red borders it is not visisble, without the need for a background color.
I have visited your website and stolen some images to better understand what you are trying to accomplish.. Assuming i'm correct in the assumption you do not want a solid background on the header because it would mess with your pages background....
you can use multiple backgrounds...
see your demo
You will need something in #banner that will hide the text. From the css it looks like there is supposed to be a background image in that block, but it is not showing up.
The header is transparent as set in your css reset, so a color or image will be necessary if you want the text to be hidden. Otherwise, it's like moving the text behind a piece of glass...you will still see the text unless you have something to actually cover it.
I suspect if there was a working background image on the header, it would block the text where it wasn't transparent. When I add a background-color it achieves that effect.

Div, Background Image, and Image Map

On a web page I'm creating, I have a div with a background image. I overlay some text over the image that I'll be changing frequently, so that's why I'm using a background image and real text instead of an img tag that contains the text.
The background image contains some click-able areas, so I need an image map.
I think the best way to do this is to have another overlay div with a transparent image, and have an image map for the transparent image that corresponds to the background area click-able areas.
Am I on the right track, or is there a better way?
If you only need the "rectangle" shape for the links in the image map, you could use css defined link positions instead. This is accomplished by specifying the position and setting the background-color to transparent. Here is an example: http://www.position-relative.com/tutorials/tute1_css_bg_image.php
something you might try is placing the background div on "float"
IE
div.background {
float:left;
}
since its got a "float" on it the size of the background wont push the divs that come after it to the side...
then you can make a second div to contain all the text stuff and then use something like :
div.textarea{
position:realtive;
left:50px;
}
to position the text area (that youll be editing a lot) above the div background
IE6 doesn't support transparency so I recommend you use the IE6 png fix hack.