How can I put an image on top of another image? - html

I have seen a few that explains how to do it with absolute position. I'm currently making a Bootstrap 3 site, so I cannot use the absolute attribute.
Below is a quick mock-up of what I'm talking about (note that the play buttons won't be burned into the images below)
Also, if you could explain how to make a similar gradient, it would be nice.
I have tried to use the z-index attribute, but when using it I couldn't figure out how to position the elements relative to elements with lower z-indexes.
Edit:
The play-button (seen on top of the images) will not be a part of the jpg image asset. Rather, it will be its own svg asset put on top of the jpg (thumbnail) image. I choose this way so that I can animate the "play-button" independently.
Neither will the gradient, title, subtitle or "article-tag" be a part of the thumbnail image asset.
The red "divider's" will be its own svg asset as well.
Ideally, I would like to be able to place <img></img> objects on top of another <img></img> bounding box and be able to move it relative to the bounding box. eg x=50% y=50% for centering. The method should be scalable so that I can have more than two layers as well as having multiple objects on the same layer.
Note: The thumbnail images will be stored on the web server in a resolution of 1920x1080. When trying to use the "divider" as a background image I had a clipping issue:
It wouldn't expand its parent <div>. (also, is there a way to detect user's screen size and rescale the pictures accordingly (on the server) in order to increase loading speed? Like a cookie or something?)
I'm sorry for probably breaking tons of rules on the site, this is my first question.

regarding the gradient, a short css writing will be:
background: -webkit-linear-gradient(135deg, #a11633 45%, #7D1229 48%, #7D1229 20%);
In addition: I've created a JSFiddle for you for the layouting :)
HTML:
<div class="relative-container">
<div class="absolute-container">
<div class="flex-1">
Img 1
</div>
<div class="flex-1">
Img 2
</div>
<div class="flex-1">
Img 3
</div>
</div>
</div>
CSS:
.relative-container{
width:300px;
height:200px;
background: -webkit-linear-gradient(135deg, #a11633 45%, #7D1229 48%, #7D1229 20%);
}
.absolute-container{
width:300px;
height:100px;
display:flex;
align-items: center;
position:absolute;
top:55px;
}
.flex-1{
flex:1;
border:1px dashed black;
text-align:center;
}

Related

how to have the background-color of a div red?

I have these divs with same classes and same css design containing pictures
<div class="it2" style="background: url(../images/ian.png) no-repeat top center;"></div>
<div class="it2" style="background: url(../images/top.png) no-repeat top center;"></div>
<div class="it2" style="background: url(../images/ylle.png) no-repeat top center;"></div>
what i was trying to do is when I hover on one of the divs the background will become red without covering the picture
any possible idea?
I tried adding in the css:
.it2:hover { background-color:red;}
but it is not working
I'm presuming the typo in your code snippit is just in the posting, and not in the actual code?
Presuming that your actual css file has 'background-color' instead of 'hacground-color' as the property name, is all your CSS inline, or is some in a separate stylesheet? Inline CSS will always over-rule the stylesheet (which is one of the adcvantages of starting with everything in the stylesheet -- more room to work with, when changes need to happen.
Does your png have transparency and are you using a browser that supports that? If not, the background color will be behind the image, and thus you won't see the change.
If your site needs to work on browsers that don't render transparency properly, you may need to use two background images, (the only difference being the background color of the image) and use the CSS to switch between them.
try this:
.it2:hover
{
background:url() no-repeat top center;
background-color:red;
}

Text flows around polygon edges in html

In my html content, I want to place an image at the bottom right corner of some container. While the image, like all images, is square in that it has a height and width, the actual visual image that the eye sees is not square. It could be a ball for example or a triangle. I also want text in this container but when the text is a lot, I would like it to flow around the edge of the visual image and not along the actual rectangle edges. Is this possible? Does html or css have some construct where you can setup the border (or edges) where text should stay away from?
If you want to solve the problem only with css and html you need to programming the page with many paragraphs (<p> tag) with various dimensions and set the image like a background image of the div wrapper.
#wrapper {
width:500px;
height:500px;
background-color: #fff; /*Default bg, similar to the background's base color*/
background-image: url("image.png");
background-position: right bottom; /*Positioning*/
background-repeat: no-repeat; /*Prevent showing multiple background images*/
}
After that set any paragraphs with custom width to set the text around the image.
Unfortunately i don't know any other "automatic" solutions.
Maybe, you can find a valid plugin here:
check this another stackoverflow question

Responsive Web Design - What Is the Best or Right Way to Put Images and Divs On Top of Image?

I have a background image for the "portal" to a new website. On top of the image, there need to be 5 images, placed in a unique pattern, plus 3 divs with text with links. Here is a picture of what it needs to look like:
Link to design of Portal
http://dansdemos.info/clips/screenshots/portal.png
The portal needs to be implemented in a responsive design.
I have experimented with relative and absolute positioning, but I am having trouble figuring out whether either or both of those is the correct way to position these smaller items on top of the larger item. So, I am struggling to figure out the best way of positioning the images and yellow divs on top of the picture. My question is: what is the best way of putting the images and divs on top of the background image for the portal?
Link to construction to live portal.
http://dansdemos.info/prelaunch/WorldClothingCorp_QA/
I think I can figure something out, but I really want to do this the "right way", or at least a good way.
Thank you.
I've had this situation myself before.
Resize the images you want to put on top to the same size as the parent (background) image. So place the images the way you want and make the rest transparent (png24, good transparency support and lower file size as gif).
Using your favorite image editing software:
Create a canvas of the same size as the background image
Place the background image in the canvas for reference (and lock the layer if possible)
Put in the overlay image and position like you want
Repeat this for the other overlays
Remove the background (reference) image and make the canvas transparent
Export the overlay images as PNG24
In the CSS use:
img { width: auto; max-width: 100%; }
…to make the images responsive. Now if the window resizes the images will respond to the width you specify to the page container.
More info on responsive or "fluid" images here: http://alistapart.com/article/fluid-images
I would suggest you position your background image within a relatively positioned div container. Once you have that placed to your liking, You would do the same thing for the images to be placed on top of the big image except you will want to position them absolutely.
HTML:
<div id="container>
<img src="..." alt="Background Image" /> /* Big Image */
<img src="..." alt="Jacket" />
<img src="..." alt="Skirt" />
<img src="..." alt="Top" />
<img src="..." alt="Dress" />
<img src="..." alt="Jacket 2" />
RETAIL STORE
WHOLESALE USED CLOTHING
WIPING RAGS
</div>
CSS:
#container {position:relative;}
#container > img { width: 100%; }
#container img+a {position:absolute; top:30%; left:30%;}
#container img+a+a {position:absolute; top:50%; right:30%;}
#container img+a+a+a {position:absolute; top:30%; right:30%;}
#container img+a+a+a+a {position:absolute; top:30%; left:30%;}
#container img+a+a+a+a+a {position:absolute; top:80%; left:40%;}
#container .yellowflag
{
/* Retail Store */
background-image: url(...);
position:absolute;top:...;left:...
}
#container .yellowflag+.yellowflag
{
/* Wholesale */
top:...;left:...;
}
#container .yellowflag+.yellowflag+.yellowflag
{
/* Wiping rags */
top:...;left:...;
}
As Chawk said you want to position your divs containing each image using position:absolute in a div containing the background image which uses position:relative. By setting them up this way, the 5 images will be positioned in relation to their parent element rather than the full screen.
Be aware that the divs around the images are currently displayed as blocks meaning they take up the full width of the parent element. You might want to set widths for them and display them as inline-block to make things easier.

Apply width and height styling to div background image

I am using a background image for my top "heading" div section of my website. It was drawn on CorelDrawX6 and exported to a .jpg image, meaning I can't set the height and width exactly right when exporting. What I want to achieve is have the webpage scale the background image to the right height. I want to have height:150px; width:100%, but because it is applied to the div like this:
<div style = "height:150px;background-image:url('Design.jpg');">
I can't apply styling directly to the image. Does anyone have a solution?
P.S. I have checked out many of the "related questions" and have not found an answer. Also, please bear in mind I want a background image for one div, not the whole page (which would be a lot easier).
Current situation:
My desired situation is to have the full image as a background (the current image is a scaled-up version, the real image (which I could not upload) looks the same but has text on, and the light blue bar is much smaller).
try
HTML
<div class="lorem" alt="lipsum" title="lorem lipsum">
<img class=ImgLorem></img>
</div>
CSS
.lorem{
}
.ImgLorem{
}
.lorem img{
background: url(Design.jpg);
height:150px;
width:100%;
}
this should work.
Let me know.
This is what you looking for?
background-size: auto 150px;

Fixed width div in center of screen with two either side of it to fill rest of screen?

So, I have this wonderful image here:
And what it is is a header for a website - click it to view it full size..
I need to re-create this using HTML/CSS/images and I can't figure out how. It has to be 100% width yet, the point where the gradient turns from one type to the other, has to remain in the same place on resize. To illustrate:
The area that is not blacked out must stay in the center of the page at all times and not move. The areas in black must extend to 100% of the screen width and have a tiled background gradient.
How can this be done?
I have tried something like this:
Where green is a div with a fixed width and centered yellow is the 'twirl' gradient bit and then red/blue are the tiling gradients. But this does not work because the tiling gradients to not match the position of the 'twirl' when the browser is resized.
Note: This must support IE7+ and must be cross-browser compatible and preferably uses no javascript.
I’m not sure why do you actually want to make this so hard by cutting the image up into pieces?
Take the image, extend the canvas to let’s say 5000px and just repeat the gradients to both sides. You’ll maybe add about 200 bytes (yes, bytes, not kilobytes) to the image size, but you’ll make it all up without adding 2 more requests for the separate backgrounds to the page.
And then just set the image to background-position: center top;
And as the center DIV is fixed width, you can either add a container to have the background or add the background to BODY for example.
Well, I think I've managed to do it..
<header>
<div id="bg-left"></div>
<div id="bg-right"></div>
<div id="header-content">
My header contents
</div>
</header>
And
header {
height:88px;
}
header #header-content {
width:1004px;
height:88px;
position:absolute;
left:50%;
margin-left:-502px;
background-image:url("/img/header-bg-middle.png");
}
header #bg-left, header #bg-right {
position:absolute;
height:88px;
}
header #bg-left {
background-image:url("/img/header-bg-left.png");
width:50%;
}
header #bg-right {
width:50%;
background-image:url("/img/header-bg-right.png");
right:0px;
}
So basically, I am creating a fixed width div in the center of the page, and then behind that I create two 50% width divs that have the appropriate gradient background.
Id do the same thing as you started doing with the one 'twirl' being centered, with two divs on the outside... the way I would do this is like this:
this is what i have:
<div style="width:100%">
<div style="background:#333; position:absolute; left:50%; top:0; width:50px; margin:auto; height:50px; z-index:10;">
</div>
<div style="width:50%; position:absolute; left:0; top:0; background-color:#060; height:50px; margin:0; z-index:1">
</div>
<div style="width:50%; position:absolute; right:0; top:0; background-color:#060; height:50px; margin:0; z-index:2">
</div>
</div>
</div>
which can be viewed here: http://sunnahspace.com/TEST.php
basically you have a container div, which if you decide to move this around at all id make relative positioned. then youd take the piece where the gradients change and make that your 1st inner div, with the different gradients your 2nd and 3rd div. Basically, the 1st div (the "twist") is positioned to stay in the same place of the browser (the middle, see the 50%, but this can be set to say 200px from the right, etc.) with the other two divs expanding when browser window sizes change. The z-index layers the css, so the 1st one having a z-index of 10 is on top (the number hardly matters so long as it is the highest number, but leaving it like this allows you to add more layers underneath without having to change the z-index, with the other two having z-indexes of 1 and 2, doesnt matter which order so long as they are less than the top div, this lets the first div sit on top of these two divs, hiding where they meet. Should work, let me know how it goes, and if need be ill fix a few things.
Is this what you want to do? http://jsfiddle.net/nnZRQ/1/