I have a list of links, and I want the visual effect of the border at the bottom or the top of the link to change its width on hover. I tried to do that, but the width of border change and the text move up and down.
I want the text be fixed and border width change behind the text!
<ul>
<li>
<div class="first">first</div>
</li>
<li>
<div class="second">second</div>
</li>
</ul>
ul {
list-style-type:none;
background-color:#eee;
height:30px;
}
ul li {
display:inline-block;
margin-right: 5px;
height:30px;
}
div {
height:30px;
line-height:30px;
}
div.first {
border-bottom-color: #aaa;
border-bottom-width: 2px;
border-bottom-style: solid;
transition: border 1s ease;
}
div.second {
border-top-color: #aaa;
border-top-width: 2px;
border-top-style: solid;
transition: border 1s ease;
}
div:hover {
border-width:30px;
}
Demo:JSFiddle
ok i fixed it by adding height to the div instead of border, and increase the height on hover and here is the example on fiddle
a div {
background-color:#333;
height:2px;
line-height:30px;
transition: height 0.3s ease;
}
a div:hover {
height:30px;
}
Thank you all for help
Here's a fiidle:
http://jsfiddle.net/ym7tynws/2/
All you have to do now is work on z-index of the second tab.
CSS:
.nav {
list-style:none;
width:200px;
}
.nav li {
margin:0;
text-align:center;
width:50%;
display:block;
float:left;
position:relative;
}
.nav li a {
position:relative;
display:block;
padding:0;
cursor:pointer;
}
a .menu-link {
background-color:#eee;
height:30px;
line-height:30px;
border-bottom-style:solid;
border-bottom-width:2px;
border-bottom-color:#333;
transition: border 0.3s ease;
}
a div:hover {
border-bottom-width:30px;
}
.second {
height:30px;
line-height:30px;
position: relative;
background-color:#eee;
transition: height 0.3s ease;
}
.second:before{
background: #333;
height: 2px;
width: 100%;
position: absolute;
content: "";
display: inline-block;
left: 0;
}
.second:before {
top: 0;
}
.second:hover:before {
transition: height 0.3s ease;
height:30px;
}
HTML:
<ul class="nav">
<li>
<a><div class="menu-link">About</div></a>
</li>
<li>
<a><div class="second">Contact Us</div></a>
</li>
What you want isn't possible because the border itself occupies space in the document, it is part of the box model so it's height is taken into consideration. If you want changes in height to not affect the rest of the document you must remove the element from the normal document flow.
I'd suggest that you create a fake border using height on a pseudo-element and absolutely position it against the parent element, like this:
.first,
.second {
height:30px;
line-height:30px;
position: relative;
}
.first:after,
.second:before{
background: #aaa;
height: 2px;
width: 100%;
position: absolute;
content: "";
display: inline-block;
left: 0;
}
.first:after {
top: 100%;
}
.second:before {
top: 0;
}
.first:hover:after,
.second:hover:before {
height:30px;
}
Here's an update of your Fiddle:
http://jsfiddle.net/jkaL3a6m/
The other option would be to use the box-shadow property instead of border to create a fake 'border'.
Related
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 am trying to change a text in a button HERE. The transition in the color works fine, but the transition on the span positions do not work.
Here is my code:
<style>
#btnIniciarFacturacion{
width: 200px;
height: 30px;
}
#btnIniciarFacturacion {
position: relative;
-webkit-transition: 2s;
transition: 2s;
overflow: hidden;
}
.btnIniciarFacturacion-content {
position: absolute;
left:0;
top:0;
font-size: 20px;
font-weight: bolder;
}
#btnIniciarFacturacion:hover{
background-color: orange;
}
#btnIniciarFacturacion .btnIniciarFacturacion-top{
top:0;
}
#btnIniciarFacturacion:hover .btnIniciarFacturacion-top{
top:-50px;
}
#btnIniciarFacturacion .btnIniciarFacturacion-bottom {
top:50px;
}
#btnIniciarFacturacion:hover .btnIniciarFacturacion-bottom {
top:0px;
}
</style>
<button class="" id="btnIniciarFacturacion">
<span class="btnIniciarFacturacion-top btnIniciarFacturacion-content" id="spanTotalFacturado"> TOTAL !##</span>
<span class="btnIniciarFacturacion-bottom btnIniciarFacturacion-content">Iniciar FacturaciĆ³n</span>
</button>
You're missing the transition style on the span elements:
.btnIniciarFacturacion-content {
position: absolute;
left:0;
top:0;
font-size: 20px;
font-weight: bolder;
transition: 2s;
}
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.
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.
Wondering if this is the best method to add an image to the beginning and end of my navigation. As it stands my navigation looks like this:
But realistically I would like to add this corner piece to the edges of it:
Here is my CSS of me trying to implement it:
#menu-top {
position:relative;
margin:0 -10px 0;
padding:.25em 0 0;
border-width:0;
color:#fff;
text-align:left;
background: url( http://www.leaguememe.co.uk/wp-content/uploads/2014/01/Horizontalbannermiddletop.png );
min-height:50px;
}
#menu-top:before {
content:'';
z-index: 20;
background: url( http://www.leaguememe.co.uk/wp-content/uploads/2014/01/Horizontaltop_left.png );
position:absolute;
left:0;
/* bottom:-5px; */
bottom: 0px;
width:0;
height:0;
display:block;
border-color:transparent #222 transparent transparent;
border-style:solid;
border-width:0px 10px 5px 0;
}
#menu-top:after {
content:'';
position:absolute;
right:0;
bottom:-5px;
width:0;
height:0;
display:block;
border-color:transparent transparent transparent #222;
border-style:solid;
border-width:0 0 5px 10px;
}
#menu-top ul {
position:relative;
margin:0;
padding:.5em 30px;
list-style-type:none;
text-align:center;
}
#menu-top ul:before {
content:'';
position:absolute;
top:4px;
left:-5px;
width: 34px;
height: auto;
display:block;
background: url( http://www.leaguememe.co.uk/wp-content/uploads/2014/01/Horizontaltop_left.png );
}
#menu-top ul:after {
content:'';
position:absolute;
top:4px;
right:-5px;
width:27px;
height:39px;
display:block;
}
#menu-top li {
display:inline;
margin:0 .25em 1em;
padding:0;
line-height:2.5em;
}
#menu-top li a {
background-color: #111;
color: #e9d6d6;
cursor: pointer;
display: inline-block;
font-weight: bold;
text-align: center;
line-height: 1;
outline: 0;
padding: .45em .6em;
white-space: nowrap;
-webkit-transition: background-color, -webkit-box-shadow 0.2s linear;
}
#menu-top li a:hover,
#menu-top li a:active {
text-decoration:none;
}
Am I getting the use of :Before and :After wrong?
You could do this a number of ways, including the use of pseudoelements. In the following, I placed two elements at the top left, and top right of my nav element. I then assigned the new background image, and flipped the element to the right so it mirrors that on the left:
nav {
position: relative;
width: 703px; height: 45px;
background: url("http://i.stack.imgur.com/PMV59.png");
}
nav::before, nav::after {
content: "";
display: block;
width: 95px; height: 50px;
position: absolute; top: -8px; left: -5px;
background: url("http://i.stack.imgur.com/IqsBV.png");
}
nav::after {
left: auto; right: -5px;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
Which results in the following:
I should note that the transform property was only used because you provided the left corner image only. This property is not going to be supported in Internet Explorer 8 (which does support :before and :after). If you'd like the above to support IE8, you'll need to abandon the transform, and instead provide a different background for the :after pseudoelement.
Demo: http://jsfiddle.net/NXP3g/1/