Problem
I'm trying to position an color block/overlay background: rgba(34, 34, 34, 0.73); on top of an image when it is hovered over.
Tried using z-index to push the overlay to the front as it seems to be sitting behind the image, while I have a feeling that my positioning position: relative may be the problem, changing it to position: absolute has made the overlay jump way out of position.
I've looked into the previously posed questions and haven't had too much luck.
Github repo for Angular project: https://github.com/onlyandrewn/angular
home.html
---
name: home
url: /
---
<div ng-controller="MainCtrl">
<header>
<p class="sponsored" id="top">Sponsored by </p>
<img src="http://placehold.it/200x30" class="sponsors" alt="">
<h1>Business Directory</h1>
<div class="find">
<input type="search" placeholder="What are you looking for?" ng-model="query">
</div><!-- /.find -->
</header>
<div class="businesses">
<div class="storeIcon">
<img src="/assets/img/store.png" class="store" alt="">
</div><!-- /.storeIcon -->
<p class="number">Search {{businesses.length}} businesses in Brandon</p><button class="filter button">Filter by <i class="fa fa-chevron-down"></i></button>
<div class="options">
<div class="cat">
<div class="categories">
<div class="group">
<p class="name">Grade Level</p>
<div class="check">
<input type="radio" name=""><p>Auto</p>
<input type="checkbox" name=""><p>Restaurant</p>
<input type="checkbox" name=""><p>Other</p>
</div><!-- /.check -->
</div><!-- /.group -->
<div class="group">
<p class="name">School Type</p>
<div class="check">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
</div><!-- /.check -->
</div><!-- /.group -->
</div><!-- /.categories -->
</div><!-- /.cat -->
</div><!-- /.options -->
</div><!-- /.businesses -->
<div class="all">
<div class="business large-4.columns" data-ng-repeat="business in businesses | filter:query | orderBy:'name'" >
<div class="overlay">
<img src="http://placehold.it/300x300" class="storefront" alt="">
</div><!-- /.overlay -->
<div class="info">
<p class="name">{{business.name}}</p>
<p class="description">{{business.description}}</p>
<p class="address">{{business.address}}</p>
{{business.website}}
</div><!-- /.info -->
</div>
</div>
<footer>
<hr>
<i class="fa fa-twitter"></i>
<i class="fa fa-facebook"></i>
<div class="backContainer">
<p class="back">Back to top</p>
</div><!-- /.backContainer -->
</footer>
</div>
custom.scss (Code snippet, for brevity)
/*----------------------------------
OVERLAYS
----------------------------------*/
.overlay {
background: rgba(34, 34, 34, 0.73);
position: relative;
width: 300px;
height: 300px;
border: 1px solid red;
opacity: 0;
&:hover {
opacity: 1;
}
}
.storefront {
position: relative;
}
Take a look at this, I've done a little example which shows you how to do an overlay in CSS. Hope this helps you out.
If you want to add an image instead of just changing the opacity or overlaying with colour. Just add this line into the #overlay:hover
background-image: url("imagePath");
Also remove the opacity, as you don't need to change the opacity if you want to use a image
Example:
div { position: relative; float: left; }
img { display: block; }
#background { background: red; }
#background:hover img { opacity: 0.5; }
#overlay span {
background: red;
bottom: 0;
display: block;
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
z-index: 1;
}
#overlay:hover span { opacity: 0.5; }
<!-- Uses background color to fade color from behind. -->
<div id="background">
<img src="http://lorempixel.com/100/100/food" height="100" width="100" />
</div>
<!-- Uses empty span to overlay color. -->
<div id="overlay">
<span></span>
<div>
You can achieve what you want without changing your markup:
.overlay {
position: relative;
width: 300px;
height: 300px;
}
.overlay:hover:after {
content: '';
width: 100%;
height: 100%;
background: rgba(34, 34, 34, 0.73);
position: absolute;
left: 0;
}
<div class="overlay">
<img src="http://placehold.it/300x300" class="storefront" alt="" />
</div><!-- /.overlay -->
The reason your current overlay doesn't work is because your image is a child element of overlay. You can think of the img element as sitting on top of it's parent (.overlay). It isn't possible for the parent to sit on top of its child elements.
Related
I have an info icon which when the user hovers over, is able to see more information. The icons are pngs and I DO NOT want to change the position of the image, so is there any idea about using tooltips with images in my case? I also would like the tooltip to look like this:
Example Tooltip
This is my HTML:
<div class="modeHolder">
<div class="toggle">
<label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label>
</div>
<div class="mode">
<p>Ipad Mode</p>
</div>
<div class="infoIcon">
<img src="images/info.png" alt="info icon">
</div>
<div class="settings">
<img src="images/settings.png" alt="settings icon">
</div>
</div>
<div class="modeHolder">
<div class="toggle">
<label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label>
</div>
<div class="mode">
<p>Mac Mode</p>
</div>
<div class="infoIcon">
</div>
<div class="settings"></div>
</div>
</div>
Thank you in advance
Codepen: https://codepen.io/D4SH13/pen/jOmOWqb
1st: Using Title tag in <img> element.
<div class="infoIcon">
<a href="#">
<img title="Extra Info" src="https://cdn.onlinewebfonts.com/svg/img_151567.png" alt="info icon" />
</a>
</div>
Final Code
Code Pen: https://codepen.io/gautam25raj/pen/poPoeNy
2nd: Using <span> element.
Take a <span> element and put it inside your tootltip container.
<div class="infoIcon">
<!-- New span element -->
<span class="extraInfo">Extra Info</span>
</div>
Make the <span> postion: absolute relative to your tooltip container position: relative and add some styles to <span> element.
.infoIcon {
position: relative;
}
.extraInfo {
position: absolute;
color: #fff;
background-color: #000;
border-radius: 5px;
padding: 2px 5px;
width: 70px;
text-align: center;
}
Now, change the visibility of the span element. So that it can stay hidden until the tooltip is hovered.
visibility: hidden;
i.e.
.extraInfo{
position: absolute;
color: #fff;
background-color: #000;
border-radius: 5px;
padding: 2px 5px;
width: 70px;
text-align: center;
visibility: hidden;
}
Now, when your tooltip is hover make the span element visible.
.infoIcon:hover .extraInfo {
visibility: visible;
}
Final Code
Code Pen: https://codepen.io/gautam25raj/pen/xxdxgrO
Hope this solves your problem
I want to make a carousel like the one on this website:
https://debut-demo.myshopify.com/
The words stick with the picture it belongs to in the carousel.
I tried to use position: relative and position: absolute to make the words on the background.
1.My HTML
<div class="swiper-container">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">
<h2>title01</h2>
<img src="../src/images/background1.jpg" alt="">
</div>
<div class="swiper-slide">
<img src="../src/images/background2.jpg" alt="">
</div>
<div class="swiper-slide">
<img src="../src/images/background3.jpg" alt="">
</div>
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
2.My SCSS
.swiper-container {
.swiper-slide {
max-height: 700px;
position: relative;
img {
-webkit-filter: brightness(.8);
width: 100%;
}
h2 {
top: 245px;
left: 100px;
font-size: 4.0625rem;
z-index: 20;
position: absolute;
}
}
}
enter image description here
enter image description here
I'm trying to add a blur panel behind my modal using vue.js but The problem is that the modal-mask has the content nested in it so to add a filter: blur() property it'll blur everything.
Right now I can only add a black tint to the background.
jsfiddle: https://jsfiddle.net/EricTalv/2eed5qjo/26/
HTML
<div id="content-container">
<div id="wrapper">
<ul id="flex-container">
<li class="flex-item">
<div id="list-area"></div>
</li>
<li class="flex-item">
<div id="img-desc-container">
<div class="image-area">
<img src="http://dukes-lancaster.org/wp-content/uploads/2014/11/placeholder.jpg">
</div>
<div class="description-area"></div>
</div>
</li>
</ul>
<button class="modal-close" #click="$emit('close')">Close</button>
</div>
</div>
</div>
CSS
/* BLUR PANEL */
#modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .6);
display: table;
transition: opacity .3s ease;
}
you'll need to move the content into a separate container and toggle a blur class
https://jsfiddle.net/2eed5qjo/27/
<div :class="{'blur-content': showModal}">
... your content ...
</div>
<!-- use the modal component, pass in the prop -->
<modal v-if="showModal" #close="showModal = false">
</modal>
then add a css class like this
.blur-content{
filter: blur(5px);
}
This is my code:
<div id="wrapper">
<header>
<div id="header">
<img src="http://s22.postimg.org/vdwnuxg4x/logo.png" alt="logo" />
</div>
<div class="header-content">
<img src="http://s22.postimg.org/tndmtfylt/banner.png" alt="banner" />
<div class="issue">
<img class="issue-image-1" src="http://s22.postimg.org/jniqdjncd/issue_no_img.png" alt="issue" />
<span class="issue-no">Issue No.<br /><b>376</b></span>
</div>
<div class="header-content-center">
<p>
<span class="new">NEW!</span>
<date>JUN O7,2013</date>
</p>
<p><i>Get your breakpoints on.</i></p>
<h1 class="h1-clear">DOT NET ARTICLES</h1>
<p><i>by</i> <a class="jon" href="#"> JOHN WOO</a><i>-10 comments</i></p>
<form>
<input type="search" placeholder="Search.."/>
</form>
</div>
</div>
<hr class="hr-style" />
</header>
This is my jsfiddle:
http://jsfiddle.net/vas4bxu5/
here banner.png and issue_no_img.png are displayed in header, it shows, backside of issue image, there is display of banner image, i want to hidden that .
I used z-index:9999; or z-index:-9999; , still nothing change.
May i know what is the exact css property to fix this.
You need to change some styles and by the way z-index works with positioned elements, change your CSS like following:
.issue
{
width: 23px;
height: 50px;
float:left;
position:relative; /* added this */
}
.issue-no
{
color: #fff;
font-size: 16px;
font-weight: 700;
left: 30px; /* updated this */
position: absolute;
top: -80px; /* updated this */
line-height: normal;
}
Demo
I'm relatively new at this level of complexity – at any rate, creating a webpage on the Squarespace platform which will feature a code block that presents a grid of 12 clickable tiles with Hover response and click through functionality. While Squarespace has built in responsiveness, whatever is in the code block is exempt from that.
So, the problem I'm having is that my nicely centered grid of 12 tiles is only centered when displayed on a fully open browser window. As the browser window diminishes in size and the tiles begin stacking, the grid aligns to the right. I've already put the gallery in a div in order to get the original centering.
Is there a way to force centering regardless of browser size?
To see the behavior in action, change Result window size of jsfiddle:
http://jsfiddle.net/terryogara/VQ3hk/
Thank you, and here's the code:
<style type="text/css">
.caption-style-1 li{
list-style-type: none;
margin: 0px;
padding: 5px;
position: relative;
overflow: hidden;
}
.caption-style-1 li:hover .caption{
opacity: 1;
}
.caption-style-1 li:active .caption{
opacity: .5;
}
.caption-style-1 img{
float: left;
}
.caption-style-1 .caption{
cursor: pointer;
position: absolute;
opacity: 0;
-webkit-transition:all 0.45s ease-in-out;
-moz-transition:all 0.45s ease-in-out;
-o-transition:all 0.45s ease-in-out;
-ms-transition:all 0.45s ease-in-out;
transition:all 0.45s ease-in-out;
}
.caption-style-1 .blur{
background-color: rgba(0,0,0,0.65);
height: 180px;
width: 180px;
position: relative;
}
.caption-style-1 .caption-text{
position: absolute;
width: 180px;
height: 180px;
text-align: center;
top:10px;
}
.outer-container {
width: 100%;
min-width: 980px
margin: 0 auto;
text-align: center;
}
.inner-container {
display: inline-block;
}
</style>
<!-- CONTENT -->
<!-- OUTER CONTAINER -->
<div class="outer-container">
<ul class="caption-style-1">
<!-- ROW 1 TOP | IMAGE GALLERY 1 -->
<div class="inner-container">
<!-- IMAGE 1 -->
<div style="float: right;">
<div style="float: right;">
<a href="http://www.example.com">
<li>
<img src="http://murmurhaus.com/wp-content/uploads/2014/07/ph-180x180.png" height="180" width="180" alt="ALT">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>TEXT HERE</h1>
</div>
</div>
</li></a>
</div>
<!-- IMAGE 2 -->
<div style="float: right;">
<a href="http://www.google.com">
<li>
<img src="http://murmurhaus.com/wp-content/uploads/2014/07/ph-180x180.png" height="180" width="180" alt="ALT">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>TEXT HERE</h1>
</div>
</div>
</li></a>
</div>
</div>
<!-- IMAGE 3 -->
<div style="float: right;">
<div style="float: right;">
<a href="http://http://stackoverflow.com/">
<li>
<img src="http://murmurhaus.com/wp-content/uploads/2014/07/ph-180x180.png" height="180" width="180" alt="ALT">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>TEXT HERE</h1>
</div>
</div>
</li></a>
</div>
<!-- IMAGE 4 -->
<div style="float: right;">
<li>
<img src="http://murmurhaus.com/wp-content/uploads/2014/07/ph-180x180.png" height="180" width="180" alt="ALT">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>TEXT HERE</h1>
</div>
</div>
</li></a>
</div>
</div>
<!-- END GALLERY 1-->
<!-- CLOSE INNER CONTAINER -->
</div>
<!-- CLOSE OUTER CONTAINER -->
</ul>
</div>
<!-- END ROW 1 -->