Dropdown Menu with pure CSS and HTML - html

I have below CSS for a dropdown menu:
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
top: 30px;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
button, a {
border-bottom: 1px solid #e7e7e7;
border-radius: unset;
text-align: left;
display: inline-block;
width: 100%!important;
.icon {
margin-right: 15px;
top: 0.13em;
}
&:hover {
background-color: #e7e7e7 !important;
}
&:active {
background-color: #c7c7c7 !important;
}
}
}
.dropdown:hover .dropdown-content {
display: block;
}
And below markup:
<div class="dropdown">
<button class="material-icon-button">
<i class="icon icon-more_vert"></i>
</button>
<div class="dropdown-content" style="width: 295px;">
<button class="material-button">
<i class="icon icon-undo"></i>
<span>Button 1</span>
</button>
<button class="material-button">
<i class="icon icon-add_alert"></i>
Button 2
</button>
</div>
</div>
This works fine and shows menu on mouseover.
What I am trying to achieve is that, instead of mouseover, the dropdown is shown when the user actually clicks the button.
I have tried:
.dropdown:active .dropdown-content {
display: block;
}
But It doesn't seem to work, it show the menu on click but hides immediately.
I was wondering if this could be done without JavaScript and with pure css? if so, can someone please guide on this.
Thanks

There is a way to handle clicks with pure CSS.
It's not the best way (because that's not what CSS is made for) but it should work. Basically you'll have to use a checkbox with a label and style according to the state of the checkbox.
Here is an example: https://css-tricks.com/the-checkbox-hack/

try like below, hope it helps, comment if query
.c {
display: flex;
align-items: center;
justify-content: center;
height:100%;
width:100%;
}
.dd {
z-index:1;
position:relative;
display: inline-block;
}
.dd-a {
padding:10px;
background:white;
position:relative;
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
transition-duration: 0.2s;
-webkit-transition-duration: 0.2s;
}
.dd input:after {
content:"";
width:100%;
height:2px;
position:absolute;
display:block;
background:#C63D0F;
bottom:0;
left:0;
transform: scaleX(0);
transform-origin: bottom left;
transition-duration: 0.2s;
-webkit-transform: scaleX(0);
-webkit-transform-origin: bottom left;
-webkit-transition-duration: 0.2s;
}
.dd input {
top:0;
opacity:0;
display:block;
padding:0;
margin:0;
border:0;
position:absolute;
height:100%;
width:100%;
}
.dd input:hover {
cursor:pointer;
}
.dd input:hover ~ .dd-a {
box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.75);
}
.dd input:checked:after {
transform: scaleX(1);
-webkit-transform: scaleX(1);
}
.dd input:checked ~ .dd-c {
transform: scaleY(1);
-webkit-transform: scaleY(1);
}
.dd-a span {
color:#C63D0F;
}
.dd-c{
display:block;
position: absolute;
background:white;
height:auto;
transform: scaleY(0);
transform-origin: top left;
width: 100%;
}
.dd-c ul {
margin:0;
padding:0;
list-style-type: none;
}
.dd-c li {
margin-botom:5px;
word-break: keep-all;
white-space:nowrap;
display:block;
position:relative;
}
a {
display:block;
position:relative;
text-decoration: none;
padding:5px;
background:white;
color:#C63D0F;
}
a:before {
z-index:0;
content:"";
position:absolute;
display:block;
height:100%;
width:100%;
transform-origin:top left;
background:#C63D0F;
top:0;
left:0;
transform: scaleX(0);
-webkit-transform: scaleX(0);
}
a span {
display:block;
position:relative;
}
a:hover:before {
transform:scaleX(1);
-webkit-transform:scaleX(1);
}
a:hover span {
color:white;
}
<div class="c">
<div class="dd">
<div class="dd-a"><span>Dropdown menu</span></div>
<input type="checkbox">
<div class="dd-c">
<ul>
<li><span>Link</span></li>
<li><span>Link</span></li>
<li><span>Link</span></li>
</ul>
</div>
</div>
</div>

Related

CSS: transform 1 pixel shift on Chrome

In the actual version of the Chrome browser there is a little issue when transition of this code finishes: 1 pixel shift of the line height on the bottom (on hover of the links).
Also, I've noticed that in code snippets of jsfiddle and here it may not be visible, but on the CodePen and on my website this is what happens. Checked on Firefox - everything is fine and on every web site.
Here is snippet of Stack Overflow and CodePen:
https://codepen.io/Maxim222/pen/OQWWEB
body{
background:#111;
}
ul{
margin:0;
padding:0;
list-style:none;
}
ul li{
float:left;
position:relative;
}
li a{
padding:10px;
color:#fff;
text-decoration:none;
}
li a:before{
content:'';
-webkit-transform: scaleX(0);
transform: scaleX(0);
background-color: #fb0;
bottom: 0px;
height: 15px;
left: 0;
margin: 0;
padding: 0;
position: absolute;
width: 100%;
transition:all 1s;
}
li a:hover:before{
bottom:0;
transform: scaleX(1);
-webkit-transform: scaleX(1);
}
<div>
<ul>
<li>Hello</li>
<li>Worldsdfsdf</li>
</ul>
</div>
From what I know, it's not your fault, it's a "glitch" with the scaleX param. If you use 0.99 as a value instead of 1, it should work fine.
body {
background: #111;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
ul li {
float: left;
position: relative;
}
ul li a {
padding: 10px;
color: #fff;
text-decoration: none;
}
ul li a:before {
content: '';
-webkit-transform: scaleX(0);
transform: scaleX(0);
background-color: #fb0;
bottom: 0px;
height: 15px;
left: 0;
margin: 0;
padding: 0;
position: absolute;
width: 100%;
transition: all 1s;
}
ul li a:hover:before {
bottom: 0;
transform: scaleX(0.99);
-webkit-transform: scaleX(0.99);
}
<div>
<ul>
<li>Hello</li>
<li>Worldsdfsdf</li>
</ul>
</div>

Alignment issues css

I have alignemet issues between caret and the vertical menu, please any help.. i tried float: , position .. nothing work with caret.
The caret should be at the top of the page.
How can I change the background of the caret like to be like lines similar to mobile application.
<style>
nav {
/* Repeating background image */
background: url(http://weebtutorials.com/wp-content/uploads/2012/11/a.png);
width:210px;
margin:20px;
}
nav ul {
/* Removes bullet points */
list-style:none;
margin:0;
padding:0;
}
nav ul li {
/* Any child positioned absolutely will be positioned relative to this */
position:relative;
}
nav a {
color:#e8e8e8;
padding:12px 0px;
/* Fill all available horizontal space */
display:block;
/* Remove underline */
text-decoration:none;
/*
New CSS3 animations:
apply transition to background property, taking 1s to change it
*/
transition:background 1s;
-moz-transition:background 1s;
-webkit-transition:background 1s;
-o-transition:background 1s;
font-family:tahoma;
font-size:13px;
text-transform:uppercase;
padding-left:20px;
}
nav a:hover {
/*
RGBA background for t
background: RGBA(255,255,255,0.05);
color:#fff;
}
nav a:hover span {
background: #7d2c41;
transform:rotate(90deg);
-moz-transform:rotate(90deg);
-webkit-transform:rotate(90deg);
}
nav ul li:hover ul {
display:block;
}
nav ul ul {
position:absolute;
left:210px;
top:0;
border-top:1px solid #e9e9e9;
display:none;
}
nav ul ul li {
width:200px;
background:#f1f1f1;
border:1px solid #e9e9e9;
border-top:0;
}
nav ul ul li a {
color:#a8a8a8;
font-size:12px;
text-transform:none;
}
nav ul ul li a:hover {
color:#929292;
}
nav span {
width:12px;
height:12px;
background:#fff;
display:inline-block;
float:left;
margin-top:3px;
margin-right:20px;
position:relative;
transition:all 0.5s;
-moz-transition:all 0.5s;
-o-transition:all 0.5s;
-webkit-transition:all 0.5s;
}
nav span:before {
content:"";
width:12px;
height:2px;
background:#3a3b3b;
position:absolute;
left:0px;
top:5px;
}
nav span:after {
content:"";
width:2px;
height:12px;
background:#3a3b3b;
position:absolute;
left:5px;
position:top;
}
.caret-right {
border-left: 20px solid transparent;
border-right:20px solid transparent;
border-top: 20px solid #fff;
margin-right: 160px;
margin-top: 0px"
position: top;
float:right;
display: inline-block;
}
</style>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
</head>
<body>
<nav>
<ul>
<li class="current"><span></span> Home </li>
<li> <span></span>AI assisted backtesting
</li>
<li> <span></span>Best stocks to trade today </li>
<li> <span></span>Get free data </li>
</ul>
</nav>
<div class="btn-group cust-dropdown pull-right">
<button type="button" class="btn btn-default dropdown-toggle cust-dropdown" data-toggle="dropdown"><span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>About us</li>
<li>Documentation
</li>
<li>Pricing</li>
<li>Contact us</li>
<li>Register</li>
</ul>
</div>
you have syntax error on margin top semicolon & quote mark and position value
this is your code
.caret-right {
border-left: 20px solid transparent;
border-right:20px solid transparent;
border-top: 20px solid #fff;
margin-right: 160px;
margin-top: 0px"
position: top;
float:right;
display: inline-block;
}
should be
.caret-right {
border-left: 20px solid transparent;
border-right:20px solid transparent;
border-top: 20px solid #fff;
margin-right: 160px;
margin-top: 0px;
position: absolute;
top: 0;
right: 0;
display: inline-block;
}
You can play with this and come up with a design that fits your site..
https://jsfiddle.net/Hastig/u00v1yer/
Hamburger positioned with absolute.
Icon within hamburger also positioned/centered with absolute.
Make sure hanmurger is within a container that has at least position:relative;
Control the 3 bars width by adjusting their margin.
.hamburglar {
position: absolute;
top: 0; right: 0;
display: flex;
align-items: center;
flex-direction: column;
width: 40px;
height: 40px;
background-color: black;
cursor: pointer;
}
.hamburglar-line {
display: flex;
flex: 1;
width: 90%;
margin: 6px 0;
background-color: hsla(0, 0%, 50%, 0.5);
}
.hamburglar-line:nth-child(2) {
margin: 0;
}
.hamburglar .fa {
position: absolute;
top: 50%; left: 50%;
transform: translateY(-50%) translateX(-50%);
font-size: 36px;
color: hsla(0, 0%, 80%, 0.7);
}
.hamburglar .hamburglar-line,
.hamburglar .fa { transition: all 0.2s linear; }
.hamburglar:hover .hamburglar-line { background-color: hsla(0, 0%, 50%, 1); }
.hamburglar:hover .fa { color: hsla(0, 0%, 80%, 1); }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="hamburglar">
<div class="hamburglar-line"></div>
<div class="hamburglar-line"></div>
<div class="hamburglar-line"></div>
<i class="fa fa-caret-down"></i>
</div>
To move the button to the top right, you can:
.cust-dropdown{
position:absolute;
top:10px;
right:10px;
}
And now to add the burger menu icon, your button would look like:
<button type="button" class="btn btn-default dropdown-toggle cust-dropdown" data-toggle="dropdown">
<i class="glyphicon glyphicon-menu-hamburger"></i>
</button>
Please make a working fiddle. Or you can try this,
.caret-right{
position: absolute;
right: 0;
top: 0;
}

Dropdown items on same line + hover effect goes to far to the right

I have a navigation bar that I want to be able to use dropdown menus but the w3schools one that I found display items on same line + the hover background color change is too wide. could someone have a look at it and tell me what goes wrong?
https://fiddle.jshell.net/e7zLx39u/
you have .nav-item-holder a {display: inline}, where actually you want this to by display: block;
I would also add .nav-item-holder .dropdown-content a { padding-left: 0; padding-right: 0; } to make sure you don't have any jumps of the items when you hover them.
Here is a working version of your code, fix (with my 2 suggestion)
.nav-wrapper {
position: fixed;
color:#151618;
background-color:#151618;
width:100%;
border-bottom:4px solid #0bb1ff;
height:50px;
z-index:1;
margin-top:0 auto;
}
.nav-logo {
width:45px;
position:absolute;
z-index:2;
top:5%;
}
.nav-item {
float:left;
}
.dropbtn {
background-color: #151618;
display: inline-block;
height:100%;
padding-left:10px;
padding-right:10px;
color:#0bb1ff;
text-decoration: none;
border: none;
cursor: pointer;
}
.dropbtn:hover {
color:#fff;
height:100%;
background-color:#0bb1ff;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
background-color: #151618;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #151618;
border:3px solid #0bb1ff;
text-align: center;
width:180px;
}
/* Links inside the dropdown */
.dropdown-content a {
color: #0bb1ff;
text-decoration: none;
display: block;
padding: 0;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #0bb1ff; color:#fff; width:100%;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: inline-block;
clear:both;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #0bb1ff;
}
.dropdown:hover .dropbtn {
color:#fff;
}
.nav-item-holder {
z-index:3;
color:#151618;
font:14px verdana;
line-height:50px;
left:50px;
position:absolute;
}
.nav-item-holder a {
display: block;
padding-left:10px;
padding-right:10px;
color:#0bb1ff;
text-decoration: none;
}
.nav-item-holder a:hover {
position:relative;
color:#fff;
text-decoration: none;
background-color:#0bb1ff;
height:100%;
}
.nav-item-holder .dropdown-content a {
padding-left: 0;
padding-right: 0;
}
.active {
position:relative;
color:#fff;
text-decoration: none;
background-color:#0bb1ff;
height:100%;
}
.user-image {
width: 30px;
height: 30px;
position:absolute;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
-webkit-border-radius: 99em;
-moz-border-radius: 99em;
border-radius: 99em;
border: 2px solid #0bb1ff;
top:8px;
right:30px;
}
.nav-user {
line-height: 50px;
color:#fff;
position:absolute;
right:0;
}
.nav-user span {
display:inline-block;
position: absolute;
right:70px;
}
.nav-user-drop {
position:absolute;
display:none;
}
.nav-user:hover .nav-user-drop {
display:block;
}
.user-drop {
padding:5px;
text-align: center;
background-color:#151618;
color:#0bb1ff;
}
<div class="nav-wrapper">
<div class="nav-content">
<a class="nav-logo" href="/"><img src="/assets/images/templates/volcan.png" class="nav-logo"/></a>
<div class="nav-item-holder">
<div class="nav-item"><a href="" >Forum</a></div>
<div class="nav-item"><a href="" >Article</a></div>
<div class="dropdown">
<div class="dropbtn">Discover</div>
<div class="dropdown-content">
Top
Recent
Verified
</div>
</div>
</div>
<form>
<!--Gone add search bar-->
</form>
</div>
<div class="nav-user-drop">
Profile
Inbox
Settings
Sign Out
</div>
</div>
</div>
The sub items are set to inline-block. If you comment out the following line, that should sort that out, and they'll all stack beneath each other.
.nav-item-holder a {
/* display: inline-block; */
}
Not sure if that covers everything; let me know and I'll extend the answer.
Try it:
* {
box-sizing: border-box;
}
.nav-wrapper {
position: fixed;
color:#151618;
background-color:#151618;
width:100%;
border-bottom:4px solid #0bb1ff;
height:50px;
z-index:1;
margin-top:0 auto;
}
.nav-logo {
width:45px;
position:absolute;
z-index:2;
top:5%;
}
.nav-item {
float:left;
}
.dropbtn {
background-color: #151618;
display: inline-block;
height:100%;
padding-left:10px;
padding-right:10px;
color:#0bb1ff;
text-decoration: none;
border: none;
cursor: pointer;
}
.dropbtn:hover {
color:#fff;
height:100%;
background-color:#0bb1ff;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
background-color: #151618;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #151618;
border:3px solid #0bb1ff;
text-align: center;
width:180px;
}
/* Links inside the dropdown */
.nav-item-holder .dropdown-content a {
color: #0bb1ff;
text-decoration: none;
display: block !important;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #0bb1ff; color:#fff; width:100%;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: inline-block;
clear:both;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #0bb1ff;
}
.dropdown:hover .dropbtn {
color:#fff;
}
.nav-item-holder {
z-index:3;
color:#151618;
font:14px verdana;
line-height:50px;
left:50px;
position:absolute;
}
.nav-item-holder a {
display: inline-block;
padding-left:10px;
padding-right:10px;
color:#0bb1ff;
text-decoration: none;
}
.nav-item-holder a:hover {
position:relative;
color:#fff;
text-decoration: none;
background-color:#0bb1ff;
height:100%;
}
.active {
position:relative;
color:#fff;
text-decoration: none;
background-color:#0bb1ff;
height:100%;
}
.user-image {
width: 30px;
height: 30px;
position:absolute;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
-webkit-border-radius: 99em;
-moz-border-radius: 99em;
border-radius: 99em;
border: 2px solid #0bb1ff;
top:8px;
right:30px;
}
.nav-user {
line-height: 50px;
color:#fff;
position:absolute;
right:0;
}
.nav-user span {
display:inline-block;
position: absolute;
right:70px;
}
.nav-user-drop {
position:absolute;
display:none;
}
.nav-user:hover .nav-user-drop {
display:block;
}
.user-drop {
padding:5px;
text-align: center;
background-color:#151618;
color:#0bb1ff;
}
<div class="nav-wrapper">
<div class="nav-content">
<a class="nav-logo" href="/"><img src="/assets/images/templates/volcan.png" class="nav-logo"/></a>
<div class="nav-item-holder">
<div class="nav-item"><a href="" >Forum</a></div>
<div class="nav-item"><a href="" >Article</a></div>
<div class="dropdown">
<div class="dropbtn">Discover</div>
<div class="dropdown-content">
Top
Recent
Verified
</div>
</div>
</div>
<form>
<!--Gone add search bar-->
</form>
</div>
<div class="nav-user-drop">
Profile
Inbox
Settings
Sign Out
</div>
</div>
</div>
Remove the width from hover state and ad it to the class also subtract padding you gave her the sample
.dropdown-content a {
color: #0bb1ff;
text-decoration: none;
display: block;
width: calc(100% - 20px);
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #0bb1ff; color:#fff;}
First off, I don't know if this is totally a duplicate, so just putting the link here
Next, I changed the width of the box from 180px to 80px, and the problem was solved. But, generically, you might want to change .nav-holder-item {display : inline; } to { display: block; } in the css.
Hope this helps.

how would i add a transition on a div overlay

I would like to add a transition on the overlay but i can't work out which class it needs to be on to make it work. I'd like it to transition down from the top. Something along the lines of
-webkit-transform: translateY(-100%);
-ms-transform: translateY(-100%);
transform: translateY(-100%);
-webkit-transition: -webkit-transform 0.3s;
transition: transform 0.3s;
HTML
<ul class="about-image">
<li>
<div class="image"></div>
<div class="overlay"><div class="bt1">Dan Morris</div><div class="bt2">Multimedia Journalist</div></div>
</li>
</ul>
CSS
.image{
height: 252px;
width: 252px;
margin-left: auto;
margin-right: auto;
margin-top: 40px;
margin-bottom: 40px;
background-image: url(../images/danmorris_profile.png);
}
.overlay{
width:252px;
height:252px;
display:none;
position:absolute;
top:40px;
left:0px;
}
.overlay div {
position:relative;
display:inline-block;
top:40px;
margin: 40px 5px 0 0;
}
ul { list-style: none; width: 252px;
margin-left: auto;
margin-right: auto;
margin-bottom: 60px;
}
ul li {
position: relative;
display: inline-block;
width: 252px;
height: 252px;
}
li:hover .overlay {
display:block;
background-color:black;
opacity:0.75;
}
.bt1 {
background-color:orange;
width:50px;
height:50px;
}
.bt2 {
background-color:green;
width:50px;
height:50px;
}
Any help would be greatly appreciated. Thanks in advance
You need to apply the effect to the .overlay - Transition cannot be set to transform as it is not supported (Reference).
To get the effect you are after, try the following:
Remove your display: none; - this cannot be animated.
Style your .overlay completely but set top: -100%;, position: absolute;, and transition: top 0.3s ease-in-out;.
On hover, just change to top: 0;.
Finally, add overflow: hidden; to the li container.
ul {
list-style: none;
width: 252px;
margin: 40px auto 60px auto;
}
ul li {
position: relative;
display: inline-block;
width: 252px;
height: 252px;
overflow: hidden;
}
li:hover .overlay {
top: 0;
}
.overlay{
width:252px;
height:252px;
opacity: 0.75;
position:absolute;
background-color:black;
top:-100%;
transition: top 0.3s ease-in-out;
}
.overlay div {
position:relative;
display:inline-block;
top:40px;
margin: 40px 5px 0 0;
}
.bt1 {
background-color:orange;
width:50px;
height:50px;
}
.bt2 {
background-color:green;
width:50px;
height:50px;
}
<ul class="about-image">
<li>
<img src="http://placehold.it/252x252"></div>
<div class="overlay">
<div class="bt1">Dan Morris</div>
<div class="bt2">Multimedia Journalist</div>
</div>
</li>
</ul>
For convenience I have moved your .image to an element - but it will work with both. Also added some ease for smoothness.
Pen here

How to solve css issue to display image caption?

I want to display some image with caption.By default its showing image only but I want to display image with caption by default.I am giving my css and html code below :
<style type="text/css">
.caption-style-1{
list-style-type: none;
margin: 0px;
padding: 0px;
}
.caption-style-1 li{
float: left;
padding: 0px;
position: relative;
overflow: hidden;
margin-right:5px;
}
.caption-style-1 li:hover .caption{
opacity: 1;
}
.caption-style-1 .hover-effect{
margin: 0px;
padding: 0px;
float: left;
width:220px;
height:150px;
//background-color:#999;
margin-bottom:5px;
}
.hover-effect img{
margin: 0px;
padding: 0px;
float: left;
z-index: 4;
}
.hover-effect h1
{
font-size:20px;
border:solid 1px red;
}
.hover-effect p
{
font-size:13px;
margin:0;
padding:0;
}
.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: 150px;
width: 220px;
z-index: 5;
position: absolute;
}
.caption-style-1 .caption-text h1{
text-transform: uppercase;
font-size: 10px;
}
.caption-style-1 .caption-text .blur{
z-index: 10;
color: #fff;
position: absolute;
width: 220px;
height: 150px;
text-align: center;
background-color: rgba(0,0,0,0.65);
}
/** Nav Menu */
ul.nav-menu{
padding: 0px;
margin: 0px;
list-style-type: none;
width: 490px;
margin: 60px auto;
}
ul.nav-menu li{
display: inline;
margin-right: 10px;
padding:10px;
border: 1px solid #ddd;
}
ul.nav-menu li a{
color: #eee;
text-decoration: none;
text-transform: uppercase;
}
ul.nav-menu li a:hover, ul.nav-menu li a.active{
color: #2c3e50;
}
.opacity
{
opacity:0.2;
filter:alpha(opacity=20); /* For IE8 and earlier */
}
</style>
And my html code's are given below :
<ul class="caption-style-1">
<li>
<div class="hover-effect">
<div class="opacity"><img src="img/chaps_1x.jpg" width="220px" height="150px" alt=""></div>
<h1>Amazing Caption</h1>
<p>Whatever It Is - Always Awesome</p>
</div>
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<img src="img/chaps_1x.jpg" width="220px" height="150px" alt="">
</div>
</div>
</li>
</ul>
Any Idea?
Your HTML code is not written in well manner. If you using HTML5 then you may use HTML5 tags like figcaption with figure. The Caption tag is not showing in your style because they are behind the image.
So here is the way to move to front using z-index property.
.hover-effect h1
{
font-size:20px;
border:solid 1px red;
position:fixed;
z-index:999;
}
.hover-effect p
{
font-size:13px;
margin:0;
padding:0;
position:fixed;
z-index:999;
}
Here is the Demo. http://jsbin.com/yegiyico/1/