Ive tried using z-index to over rule the absolute and relative positioning on the box hovers but it just doesn't work. Any body got any suggestions as to why? The links are there but to the side of the images rather than directly above.
HTML
<div id="container1">
<img src="images/blindsided1.jpg">
<div class="textbox">
<p id="title1">First Coding <br> Attempt</br></p>
<p id="text1"> This brief was my first attempt at designing a website.</p>
</div>
</div>
CSS
a:hover {
z-index: 99;
}
#container1 {
position:absolute;
float:left;
}
.textbox:hover {
opacity:1;
}
#title1 {
padding-top: 20px;
text-align:center;
color:#FFF;
font-family:"bebas";
font-size:32px;
word-spacing:2px;
letter-spacing:1px;
text-decoration:underline;
}
#text1 {
padding-top:40px;
text-align:center;
color:#FFF;
font-family:"bebas";
font-size:16px;
word-spacing:2px;
letter-spacing:1px;
}
.textbox {
width:361px;
height:362px;
position:absolute;
top:0;
left:0;
opacity:0;
border-radius:300px;
background-color: rgba(0, 0, 0, 0.75);
-webkit-transition: all 0.7s ease;
transition: all 0.7s ease;
}
You can wrap the whole hoverable div in the anchor tag, that way you can ensure that the hoverable div is clickable and that it points to the link that the image is referencing.
HTML
<div id="container1">
<a href="firstcoding.html">
<img src="http://zoarchurch.co.uk/content/pages/uploaded_images/91.png">
<div class="textbox">
<p id="title1">First Coding
<br>Attempt</br>
</p>
<p id="text1">
This brief was my first attempt at designing a website.
</p>
</div>
</a>
</div>
CSS
a:hover {
z-index: 99;
}
.textbox:hover {
opacity:1;
}
#title1 {
padding-top: 20px;
text-align:center;
color:#FFF;
font-family:"bebas";
font-size:32px;
word-spacing:2px;
letter-spacing:1px;
text-decoration:underline;
}
#text1 {
padding-top:40px;
text-align:center;
color:#FFF;
font-family:"bebas";
font-size:16px;
word-spacing:2px;
letter-spacing:1px;
}
.textbox {
width:361px;
height:362px;
position:absolute;
top:0;
left:0;
opacity:0;
border-radius:300px;
background-color: rgba(0, 0, 0, 0.75);
-webkit-transition: all 0.7s ease;
transition: all 0.7s ease;
}
The absolutely positioned child is sitting on top of the anchor link so any pointer interaction would fail.
You could use pointer-events:none on that child which would allow events to pass through but browser support it not great.
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
a,
img {
display: block;
}
#container1 {
position: relative;
border: 1px solid red;
float: left;
}
#container1:hover .textbox {
opacity: 1;
}
#title1 {
padding-top: 20px;
text-align: center;
color: #FFF;
font-family: "bebas";
font-size: 32px;
word-spacing: 2px;
letter-spacing: 1px;
text-decoration: underline;
}
#text1 {
padding-top: 40px;
text-align: center;
color: #FFF;
font-family: "bebas";
font-size: 16px;
word-spacing: 2px;
letter-spacing: 1px;
}
.textbox {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
opacity: 0;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.75);
-webkit-transition: all 0.7s ease;
transition: all 0.7s ease;
pointer-events: none;
}
<div id="container1">
<a href="firstcoding.html">
<img src="http://lorempixel.com/output/cats-h-c-361-362-10.jpg" />
</a>
<div class="textbox">
<p id="title1">First Coding
<br/>Attempt
</p>
<p id="text1">This brief was my first attempt at designing a website.</p>
</div>
You would do better to wrap the div inside the link and re-factor your code as suggested in the comments.
Related
I have an image description appear on hover. I make it transition up by changing the margin-top value. The problem is I want it to be able to take as much text as possible but still have everything appear over the image.
Here is a demo on JsBin.
.myslider{
overflow:hidden;
position: relative;
max-width:400px;
}
.myslider img{
width:100%;
}
.title{
position:absolute;
width: 100%;
height:20px;
padding-bottom: 2px;
margin-top: -20px;
transition: margin-top 200ms ease-in;
background:black;
opacity:0.6;
}
.title-text{
color:white;
float left;
padding-left:5px;
}
.nav-buttons{
background: white;
float:right;
padding: 0px 5px 0px 5px;
border: 1px solid black;
margin: 0px 5px 0px 0px;
cursor:pointer;
}
.myslider:hover .title{
margin-top: 0px
}
.description {
text-align: center;
position:absolute;
width: 100%;
margin-top:0px;
transition: margin-top 200ms ease-in;
color:white;
background:black;
opacity: 0.6;
}
.myslider:hover .description {
margin-top: -20px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="myslider">
<div class="title">
<span class="title-text">Image 1 </span>
<span class= "nav-buttons"> > </span>
<span class= "nav-buttons"> < </span>
</div>
<img src="http://placekitten.com/400/400">
<div class="description">Image Caption: Should accept as much text as posisble. more text, more text, more text</div>
</div>
</body>
</html>
Instead of using margin-top to animate, use transform property to do it using something like this:
.description {
text-align: center;
position: absolute;
width: 100%;
transition: transform 200ms ease-in;
color: white;
background: black;
opacity: 0.6;
}
.myslider:hover .description {
transform: translate(0, -100%);
}
and there you go! Cheers!
.myslider {
overflow: hidden;
position: relative;
max-width: 400px;
}
.myslider img {
width: 100%;
display: block;
}
.title {
position: absolute;
width: 100%;
height: 20px;
padding-bottom: 2px;
margin-top: -20px;
transition: margin-top 200ms ease-in;
background: black;
opacity: 0.6;
}
.title-text {
color: white;
float left;
padding-left: 5px;
}
.nav-buttons {
background: white;
float: right;
padding: 0px 5px 0px 5px;
border: 1px solid black;
margin: 0px 5px 0px 0px;
cursor: pointer;
}
.myslider:hover .title {
margin-top: 0px
}
.description {
text-align: center;
position: absolute;
width: 100%;
transition: transform 200ms ease-in;
color: white;
background: black;
opacity: 0.6;
}
.myslider:hover .description {
transform: translate(0, -100%);
}
<div class="myslider">
<div class="title">
<span class="title-text">Image 1 </span>
<span class="nav-buttons"> > </span>
<span class="nav-buttons"> < </span>
</div>
<img src="http://placekitten.com/400/400">
<div class="description">Image Caption: Should accept as much text as posisble. more text, more text, more text</div>
</div>
Also made some minor changes:
Used < and > for correct XHTML syntax
Added display: block to the image to remove the small whitespace below the image.
Don't use margin-top. Use bottom to anchor it to the bottom its parent.
I'm working in a module box which redirects the user to an external website.
I've managed to create the layout and the content is displayed properly, however when I added the hover effect, the div is no longer clickable and so does not redirect to the external website.
Here is my jsfiddle
And here is my code:
<div class="module-box">
<div class="module-dummy"></div>
<div class="module-body module-pinterest">
<a href="www.google.com">
<div class="module-pinterest-title">Some text</div>
<div class="module-pinterest-description">
Some other text</div>
</a>
</div>
and my CSS:
.module-box {
display: inline-block;
position: relative;
width: 100%;}
.module-dummy {
margin-top: 100%;}
.module-body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;}
.module-pinterest {
background-color: #7C56BE;}
.module-pinterest-title {
padding: 25px 25px 0px 25px;
color: #FFF;}
.module-pinterest-description {
padding: 25px 25px 0px 25px;
font-size: 22px;
line-height: 26px;
font-weight: bold;
color: #FFF;}
.module-pinterest:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.2);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;}
.module-pinterest:hover:after {
opacity:1;}
Thanks!!
Add pointer-events:none; to your .module-pinterest:hover:after css code, like so:
.module-pinterest:hover:after {
opacity: 1;
pointer-events:none;
}
Here is the JSFiddle demo
if you move all your .module-pinterest styles to the anchor, then it should work:
.module-pinterest a {
display:block;
width:100%;
height:100%;
background-color: #7C56BE;
}
.module-pinterest a:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.2);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.module-pinterest a:hover:after {
opacity:1;
}
Updated fiddle
Since you are using positioning for overlaying of color upon hover, convert your anchor to block and add position:relative and a z-index value:
.module-body a {
position: relative;
z-index: 9;
display:block;
}
Here is fiddle:
https://jsfiddle.net/kw5ybq9e/3/
I have this html/css popup code. I want multiple popups in my page. But when I click on another popup, the first popup's content comes on. How can I make them to show different content ? Thank you.
html
<div id="closed"></div>
Klik untuk memunculkan Popup
<div class="popup-wrapper" id="popup">
<div class="popup-container"><!-- Konten popup, silahkan ganti sesuai kebutuhan -->
<form action="http://www.syakirurohman.net/2015/01/tutorial-membuat-popup-tanpa-javascript-jquery.html#" method="post" class="popup-form">
<h2>Conent</h2>
</div>
</form>
<!-- Konten popup sampai disini--><a class="popup-close" href="#closed">X</a>
</div>
</div>
css
a.popup-link {
padding:17px 0;
text-align: center;
margin:7% auto;
position: relative;
width: 300px;
color: #fff;
text-decoration: none;
background-color: #FFBA00;
border-radius: 3px;
box-shadow: 0 5px 0px 0px #eea900;
display: block;
}
a.popup-link:hover {
background-color: #ff9900;
box-shadow: 0 3px 0px 0px #eea900;
-webkit-transition:all 1s;
-moz-transition:all 1s;
transition:all 1s;
}
/* end link popup*//*style untuk popup */
#popup {
visibility: hidden;
opacity: 0;
margin-top: -200px;
}
#popup:target {
visibility:visible;
opacity: 1;
background-color: rgba(255,255,255,0.7);
position: fixed;
top:0;
left:0;
right:0;
bottom:0;
margin:0;
z-index: 99999999999;
-webkit-transition:all 1s;
-moz-transition:all 1s;
transition:all 1s;
}#media (min-width: 768px){
.popup-container {
width:600px;
}
}
#media (max-width: 767px){
.popup-container {
width:100%;
}
}
.popup-container {
position: relative;
margin:7% auto;
padding:30px 50px;
background-color: #333;
color:#fff;
border-radius: 3px;
}a.popup-close {
position: absolute;
top:1px;
right:3px;
background-color: #fff;
padding:7px 10px;
font-size: 20px;
text-decoration: none;
line-height: 1;
color:#333;
}/* style untuk isi popup */.popup-form {
margin:10px auto;
}
.popup-form h2 {
margin-bottom: 5px;
font-size: 37px;
text-transform: uppercase;
}
Here is full code for minimalist popups.
$('.btn').click(function(){
$('.popup').hide();
$('#' + $(this).attr('data-popup')).show();
});
.popup {
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
display:none;
background:#000;
color:#fff;
padding:5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popup" id="popup1">
Popup 1
</div>
<div class="popup" id="popup2">
Popup 2
</div>
<button class="btn" data-popup="popup1">Open pop 1</button>
<button class="btn" data-popup="popup2">Open pop 2</button>
I have some text, and beneath it a button. No matter what I change the top margin to, the button still sticks to the bottom of the text.
I am trying to leave a small gap between the text and the button.
Here is a Jsfiddle: http://jsfiddle.net/24bk2t78/
#import url(http://fonts.googleapis.com/css?family=Nunito:300);
.homethree a { text-decoration: none; }
sup { font-size: 36px; font-weight: 100; line-height: 55px; }
.button
{
margin-top:30%!important;
text-transform: uppercase;
letter-spacing: 2px;
text-align: center;
color: #0C5;
font-size: 24px;
font-family: "Nunito", sans-serif;
font-weight: 300;
position:relative;
padding: 20px 0;
width: 220px;
height:30px;
background: #0D6;
border: 1px solid #0D6;
color: #FFF;
overflow: hidden;
transition: all 0.5s;
}
.button:hover, .button:active
{
text-decoration: none;
color: #0C5;
border-color: #0C5;
background: #FFF;
}
.button span
{
padding-right: 0;
transition: padding-right 0.5s;
}
.button span:after
{
content: ' ';
right: -18px;
opacity: 0;
width: 10px;
height: 10px;
background: rgba(0, 0, 0, 0);
border: 3px solid #FFF;
border-top: none;
border-right: none;
transition: opacity 0.5s, top 0.5s, right 0.5s;
transform: rotate(-45deg);
}
.button:hover span, .button:active span
{
padding-right: 30px;
}
.button:hover span:after, .button:active span:after
{
transition: opacity 0.5s, top 0.5s, right 0.5s;
opacity: 1;
border-color: #0C5;
right: 0;
top: 50%;
}
<div class="row text-center homethree">
<div class="col-md-4">
<h4 class="service-heading">A Range of Classes</h4>
<p class="text-muted">WE TEACH CHILDRENS CLASSES, FAMILY GROUPS & ADULTS.</p>
<span>page 1</span>
</div>
<div class="col-md-4">
<h4 class="service-heading">Passionate Instructors</h4>
<p class="text-muted">ALL OUR CLASSES ARE TAUGHT BY PASSIONATE, MOTIVATIONAL & INSPIRING INSTRUCTORS.</p>
<span>page 2</span>
</div>
<div class="col-md-4">
<h4 class="service-heading">Friendly Team</h4>
<p class="text-muted">NEW MEMBERS ARE ALWAYS WELCOME. TWO FREE LESSONS FOR ALL.</p>
<span>page 3</span>
</div>
</div>
The problem is that <a> tags are inline elements. Changing them to an inline-block or block style element will make your margins properly apply.
.button {
display: inline-block;
}
More info: The Difference Between “Block” and “Inline”
On a sidenote, why not use <button> tags instead of <a>? They would be more appropriate.
try this demo
Fiddle
.button{
float:left;
margin-top:0;
}
.col-md-4
{
float:left;
width:100%
}
I am using the following tutorial http://www.alessioatzeni.com/wp-content/tutorials/html-css/CSS3-Hover-Effects/index_3.html as a hover effect for two images I have. When you hover over them though, only the magnifying glasses are linked, I would like it so after you hover the entire area is linked. Is it at all possible? I have been playing around with it but cannot get it to work. Any help would be greatly appreciated.
Here is the HTML
<div class="view third-effect">
<!-- Image goes here -->
<div class="mask"><a href="#" class="info" title="Full Image">
<span class="glyphicon glyphicon-search"></span>
</a></div>
<div class="content">
</div>
</div>
And here is the CSS
.view {
width: 300px;
height: 200px;
margin: 10px;
float: left;
border: 5px solid #fff;
overflow: hidden;
position: relative;
text-align: center;
box-shadow: 0px 0px 5px #aaa;
cursor: default;
}
.view .mask, .view .content {
width: 300px;
height: 200px;
position: absolute;
overflow: hidden;
top: 0;
left: 0;
}
.view img {
display: block;
position: relative;
}
.view a.info .glyphicon .glyphicon-search {
/* background:url(../img/link.png) center no-repeat; */
position: relative;
top: 1px;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
content: "\e006";
display: inline-block;
text-decoration: none;
padding:0;
text-indent:-9999px;
width:20px;
height:20px;
}
.third-effect .mask {
opacity: 0;
overflow:visible;
border:100px solid rgba(0,0,0,0.7);
box-sizing:border-box;
transition: all 0.4s ease-in-out;
}
.third-effect a.info .glyphicon .glyphicon-search {
position:relative;
top:70px; /* Center the link */
opacity: 0;
transition: opacity 0.5s 0s ease-in-out;
}
.third-effect:hover .mask {
opacity: 1;
border:100px solid rgba(0,0,0,0.7);
}
.third-effect:hover a.info {
opacity:1;
transition-delay: 0.3s;
}
This worked OK in my test:
Modified CSS:
.view a.info {
background:url(/images/link.png) center no-repeat;
/*display: inline-block;*/
text-decoration: none;
padding:0;
text-indent:-9999px;
/*width:20px;
height:20px;*/
display: block;
width: 300px;
height: 200px;
}
Also comment out the "border:100px" parts (there are two places I found):
/*border:100px solid rgba(0,0,0,0.7);*/
That's it, the full thumbnail can now be clicked, while the hover effect with mag glass remains as before.