Place background behind img in div - html

So, I have img inside div like this:
<div class="row text-center about__gallery">
<div class="col-xs-12 col-sm-4">
<div class="about__gallery--first img">
<img />
</div>
</div>
.
.
.
</div>
The effect I want to achieve is to have div with color exactly the same size as img behind it (on hover I'm gonna move img a little bit).
SCSS looks like this:
.about__gallery{
margin-top: 5%;
.img{
background-repeat:no-repeat;
background-size:cover;
width:70%;
height:230px;
margin-bottom: 15%;
img{
z-index: 3;
}
&:before {
position: absolute;
content: " ";
display: block;
width: 70%;
height: 230px;
background-color: $color-blue;
z-index: -100;
}
}
.about__gallery--first{
margin-left: 45%;
img{
content:url("../img/aboutus_pic1.png");
width: 100%;
}
}
.
.
Unfortunately result looks like this: DELETED DUE TO REPUTATION
Edit with full code:
<div class="row text-center about__gallery">
<div class="col-xs-12 col-sm-4">
<div class="about__gallery--first img">
<img class="about__gallery__img--bg" />
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="about__gallery--second img">
<img class="about__gallery__img--bg" />
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="about__gallery--third img">
<img class="about__gallery__img--bg" />
</div>
</div>
</div>
And my full .scss looks like this:
.about__gallery{
margin-top: 5%;
margin-bottom: 10%;
.img {
position: relative;
margin-bottom: 15%;
img {
width: 100%;
height: auto;
}
&:before {
position: absolute;
top: 0;
left: 0;
content: " ";
display: block;
width: 100%;
height: 100%;
background-color: $color-blue;
z-index: -100;
}
}
.about__gallery--first{
margin-left: 45%;
margin-bottom: auto;
img.about__gallery__img--bg{
content:url("../img/aboutus_pic1.png");
width: 100%;
}
}
.about__gallery--second{
margin:auto;
img.about__gallery__img--bg{
content:url("../img/aboutus_pic2.png");
width: 100%;
}
}
.about__gallery--third{
margin-left: -15%;
margin-bottom: auto;
img.about__gallery__img--bg{
content:url("../img/aboutus_pic3.png");
width: 100%;
}
}
}
And now my page looks like this:RESULT
My goal is to have something like that on my site:GOAL
Added hover that doesn't work........
codepen.io/Kreha/pen/vmbzPb

A few things I would do. First, remove the static height/widths that you have set. Let the container inherit them from the image. Then, you'll need to set the top/left position of the pseudo element, relative to the position of your container (which should be set to relative). Here's a working example.
<div class="row text-center about__gallery">
<div class="col-xs-12 col-sm-4">
<div class="about__gallery--first img">
<img src="http://placehold.it/250x250" />
</div>
</div>
</div>
.about__gallery {
margin-top: 5%;
.img {
position: relative;
margin-bottom: 15%;
img {
opacity: 0.8; // just to show the blue behind it
width: 100%;
height: auto;
}
&:before {
position: absolute;
top: 0;
left: 0;
content: " ";
display: block;
width: 100%;
height: 100%;
background-color: $color-blue;
z-index: -100;
}
}
&--first {
margin-left: 45%;
}
}

When i do css stuff i usually use Chrome Inspect Element to locate that particular element and try to change it's bg color and on the right side of CIE see css tab where you can see which class specifically is being effected so just simply call that class in your internal or external file and use an image as a background, hope it helps!
I changed the bg color of this current page we are working on, hehe!
.so-header~.container {
background-color: #ccc;
}

Related

CSS show a bigger image while hover

Ive got a product page with a smaller image of the product.
Now I want to show a bigger version of this image with a colored background covering the whole page, while I hover the smaller image.
The problem is, that the bigger image flickers while I move the mouse around.
My CSS:
#zoomed-product-img {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(162, 130, 192, 0.8);
z-index: 0;
visibility: hidden;
}
#zoomed-product-img img {
display: block;
margin: auto auto;
}
.productsdetail-image:hover~#zoomed-product-img {
visibility: visible;
}
My HTML:
<div class="productdetails">
<div class="productsdetail-image">
<img src="/assets/images/products/{{page.name}}.png" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
<div id="zoomed-product-img">
<img src="/assets/images/products/{{page.name}}.png" alt="Produktbild">
</div>
Can you help me? Maybe my way of thinking is wrong.
I think it flickers because when I show the bigger image, it is above (z index) the small one and I am not hovering the image anymore so it disappears.
I would also love to solve this with javascript, if you can give me any advice.
You need to specify dimensions for the container of the image. This is why it is flickering. I also used display: none; and display:block to hide and show the images.
.productdetails {
position: relative;
}
#zoomed-product-img {
display: none;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
}
/* This is the product detail image styles */
.productsdetail-image {
display: block;
height: 200px;
width: 200px;
}
.productsdetail-image:hover img {
display: none;
}
.productsdetail-image:hover + #zoomed-product-img {
display: block;
}
HTML
<div class="productdetails">
<div class="productsdetail-image">
<img src="https://placeimg.com/200/200/animals" alt="Produktbild">
</div>
<div id="zoomed-product-img">
<img src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
Demo:
http://jsfiddle.net/n07bt46y/
Please check this in full page
$(document).ready(function(){
$('.productsdetail-image img').hover(function() {
$(this).hide();
$('#zoomed-product-img ').show(500);
});
$('#zoomed-product-img .close').click(function(){
$(this).parent().hide();
$('.productsdetail-image img ').show();
});
});
.productsdetail-image img {
width: 150px;
height: auto;
transition: all 0.5s ease;
}
#zoomed-product-img {
display: none;
position: absolute;
width: 100%;
height: 100%;
background-color: red;
}
#zoomed-product-img span.close {
position: absolute;
color: #fff;
cursor: pointer;
top: 20px;
right: 20px;
}
#zoomed-product-img img {
position: absolute;
width: 300px;
height: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: aUto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="productdetails">
<div class="productsdetail-image">
<img src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div id="zoomed-product-img">
<span class="close">close</span>
<img class="zoom-img" src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
Are you wanna build something like that? Hoppefully that fiddle can help you

Bootstrap design container-fluid with differens color

I would like to achieve the following:
Have a fluid container with one background color on each side - but the separator should be two cols in the inside container.
I tried to describe it in this picture. Is this even possible?
use css positions and after/before see the link below:
Codepen
.container {
background: #ddd;
height: 250px;
}
.extra1 {
height: 250px;
background: #fff;
position: relative;
z-index: 999;
}
.extra2 {
height: 250px;
background: #000;
}
.extra1:before {
content: '';
background: yellow;
position: absolute;
width: 300%;
top: 0px;
height: 100%;
left: -200%;
}
.extra2:before {
content: '';
background: green;
position: absolute;
width: 300%;
top: 0px;
height: 100%;
right: -200%;
}
.your-things {
position: absolute;
left: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-4 extra1">
<div class="your-things">
<p>.col-md-4</p>
</div>
</div>
<div class="col-md-8 extra2">
<div class="your-things">
<p>.col-md-8</p>
</div>
</div>
</div>
</div>
This can be done using psuedo element before and after on .container-fluid class or give any other class name.
Here is a code pen demo:
`http://codepen.io/duptitung/pen/adNOpV`
ya, you can give background image of the specific color and place it on that specific region
css
.container-fluid{
background:url( //image link// );
background-position: // arrange image // ;
background-size: auto 100%;
}

hover stops working when I add more element

Here is a simple site: 1 featured post and 3 small boxes under. I have a darkening effect on hover. The problem is when I add the small boxes. It stops working =(
<div class="bigBox">
<div class="featured_post">
<span></span>
<div class="category">Stuff</div>
<h1>Text will go here</h1>
</div>
</div>
<div class="small_boxes">
<div class="box01">
<span></span>
<div class="category">Stuff</div>
<h1>Text will go here</h1>
</div>
FULL CODE WITH CSS:
1 small box (work) http://codepen.io/tsalexey544/pen/wBExPJ?editors=110
3 small boxes (doesnt work) http://codepen.io/tsalexey544/pen/xbaJpe?editors=110
your .small_boxes (box01, box02, box03) miss a position: relative. If you add that, you are done.
Your boxes float in their parent. Their parent has position: relative. The spans get the full height+width of that parent, which is 0x0, since its children float.
.small_boxes <-- position: relative. 0x0
.box01/02/03 <-- float: left
span <-- 100% of .small_boxes = 0x0
What you want:
.small_boxes
.box01/02/03 <-- float: left, position: relative;
span <-- 100% of .box = desired effect
you could use pseudo elements to achieve this effect, which would reduce markup considerably:
.cont {
position: relative;
background: url(http://japanpapa.ru/fun/jpap/img/post01.jpg);
background-size: 100% 100%;
height: 100px;
width: 100px;
displaY: inline-block;
margin: 10px;
}
.text {
display: inline-block;
color: white;
font-size: 20px;
text-align: center;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
line-height:100px;
}
.cont:before {
content: "";
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
background: black;
transition: all 0.4s;
opacity: 0;
}
.cont:hover:before {
opacity: 0.6;
}
<div class="cont">
<div class="text">text1</div>
</div>
<div class="cont">
<div class="text">text2</div>
</div>
<div class="cont">
<div class="text">text3</div>
</div>

HTML, CSS hover on image

I'm learning html and css, but I have some troubles.
Right now I'm making a site that has a small images with different w sizes.
The point is that, when you hover on them they show up clickable elements, and I can't get the right position on them.
What I have:
What I want:
Part of code for this:
<div class="photo">
<img src="http://placekitten.com/400/300" alt="image"/>
<div class="zoom">
</div>
<div class="all">
</div>
<div class="link">
</div>
<div class="info">
</div>
<div class="like">
</div>
</div>
CSS:
.photo img {
float:left;
width:auto;
height:auto;
}
.photo:hover {
display: block;
opacity:0.6;
}
.photo:hover .zoom {
position: absolute;
background-image:url(http://www.kolazhgostar.com/images/small-img05.png);
background-repeat:no-repeat;
width:46px;
height:50px;
background-position:center;
http://jsfiddle.net/zzu87/
You need to add some positioning to each image if you use position: absolute. Try something like this:
.photo:hover .zoom {
position: absolute;
top: 50%;
left: 200px;
background-image: url(http://www.kolazhgostar.com/images/small-img05.png);
background-repeat: no-repeat;
width: 46px;
height: 50px;
background-position: center;
}
This should get you where you want to go. (JS fiddle)
css
.photo {
display:block;
position:absolute;
background-image: url('//placekitten.com/400/300');
background-repeat: no-repeat;
width:400px;
height:300px;
}
.photo>.container {
display:none;
}
.photo>.container>div {
display:inline;
}
.photo:hover>.container {
display:block;
margin-left: 85px;
margin-top: 200px;
}
html
<div class="photo">
<div class="container">
<div class="zoom">
<img src="//www.kolazhgostar.com/images/small-img05.png"/>
</div>
<div class="all">
<img src="//www.kolazhgostar.com/images/small-img05.png"/>
</div>
<div class="link">
<img src="//www.kolazhgostar.com/images/small-img05.png"/>
</div>
<div class="info">
<img src="//www.kolazhgostar.com/images/small-img05.png"/>
</div>
<div class="like">
<img src="//www.kolazhgostar.com/images/small-img05.png"/>
</div>
</div>
</div>
First float the parent div left and set the position to relative. Then you'll have better control over the positioning of any child elements.
.photo {
float:left;
position:relative;
}
After, padding, margin, bottom, left, right, and top can be used to achieve the specific location desired inside the parent div. Here I used left and top...
.photo:hover .zoom {
position: absolute;
background-image:url(http://www.kolazhgostar.com/images/small-img05.png);
background-repeat:no-repeat;
width:46px;
height:50px;
background-position:center;
left:50%;
top:50%;
}
Here is the FIDDLE.
Interesting question. I solved the problem by making more div containers for the photo and its contents. Also, I worked under assumption that your photo images are 400x300. Modify the code as you like! :)
I think the interesting part about my solution is that I used only position: relative; which lifts up the hover menu above your images so it plays together nicely:
.photo-menu {
position: relative;
left: 0px;
top: -300px;
}
Thus, most of the horizontal position is accomplished using margin: 0 auto; instead of playing too much with absolute or relative position. Generally speaking, those can be avoided most of the time. It depends.
The result can be also viewed from the following: js fiddle example or from this jsfiddle example if cat images are removed sometime later.
Linking also relevant code below:
HTML:
<div class="photo-container">
<div class="photo">
<img src="http://placekitten.com/400/300" alt="image"/>
<div class="photo-menu">
<div class="upper-menu"></div>
<div class="lower-menu">
<div class="all"></div>
<div class="link"></div>
<div class="info"></div>
<div class="like"></div>
</div>
</div>
</div>
<div class="photo">
<img src="http://placekitten.com/400/300" alt="image"/>
<div class="photo-menu">
<div class="upper-menu"></div>
<div class="lower-menu">
<div class="all"></div>
<div class="link"></div>
<div class="info"></div>
<div class="like"></div>
</div>
</div>
</div>
</div>
CSS:
body {
margin: 0px;
padding: 0px;
}
.photo-container {
width: 800px;
}
.photo {
float: left;
width: 400px;
}
.photo, .photo-menu {
width: 400px;
height: 300px;
}
.photo:hover {
display: block;
opacity: 0.6;
}
.photo-menu {
position: relative;
left: 0px;
top: -300px;
}
.photo .photo-menu {
display: none;
}
.photo:hover .photo-menu {
display: block;
}
.photo-menu .upper-menu {
background-image: url("http://www.kolazhgostar.com/images/small-img05.png");
background-repeat: no-repeat;
background-position: center;
width: inherit;
height: 200px;
margin: 0 auto;
}
.photo-menu .lower-menu {
width: 280px;
margin: 0 auto;
height: 100px;
}
.photo-menu .lower-menu div {
min-width: 40px;
width: 24.9999%;
height: 40px;
background-repeat: no-repeat;
background-position: center;
float: left;
}
.photo-menu .lower-menu .all {
background-image: url("http://placehold.it/40/ff0000");
}
.photo-menu .lower-menu .link {
background-image: url("http://placehold.it/40/00ff00");
}
.photo-menu .lower-menu .info {
background-image: url("http://placehold.it/40/0000ff");
}
.photo-menu .lower-menu .like {
background-image: url("http://placehold.it/40/c0ff33");
}
Note: I used placehold.it to place dummy images for the icons.
Cheers.

Adding image over another image - bootstrap

I want to add an image over an image.
For example, there's an image in the background and on top of that i need to add an image of a play button. Where the user can play the video by clicking on it. This is also shown on the Shopify homepage.
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img width='100%'
src='http://roomista.com/uploads/hotel-gal/250_SunwayHotelHanoiSuperiorRoom.jpg' />
<div class='img-container'>
<div class='img-text'>
<img src="http://lizkhoo.com/content/play-icon.png" alt="..." />
</div>
</div>
And the CSS is as follows:
.img-container {
width: 100%;
position: relative;
display: inline-block;
margin: 10px 5px 5px;
}
.img-text {
width: 100%;
display: block;
}
Use position: relative on .item and position: absolute on .img-text.
You should not need to use z-index on .img-text, but if it appears under .img-container, use it.
.img-text {
/*position: absolute;*/ Wrong, see edit
width: 100%;
display: block;
/*top: ?; bottom: ?; left: ?; right: ?; //to place it as you want.*/
}
.item{
position: relative;
}
Edit : I misread your code, (badly indented :p)
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img width='100%'
src='http://roomista.com/uploads/hotel-gal/250_SunwayHotelHanoiSuperiorRoom.jpg' />
<div class='img-container'>
<div class='img-text'>
<img src="http://lizkhoo.com/content/play-icon.png" alt="..." />
</div>
</div>
</div>
</div>
So position: absolute on .img-container
.img-container {
position: absolute;
top: ?; bottom: ?; left: ?; right: ?; //to place it as you want.
}
Edit 2 :
A little jsFiddle, like the comment below : http://jsfiddle.net/hsYwV/1/
The easiest way to do this is to set the image as a background.
html:
<div class="item-active">
<img class='img-text' src="http://lizkhoo.com/content/play-icon.png" />
</div>
css:
.item-active {
width: 200px;
height: 200px;
background-image: url('http://roomista.com/uploads/hotel-gal/250_SunwayHotelHanoiSuperiorRoom.jpg');
}
.img-text {
position: relative;
left: 75px;
top: 75px;
width: 50px;
height: 50px;
}
JScript:
$(".img-text").bind("click", function(){
alert("play video");
});
http://jsfiddle.net/J7qnF/2/