CSS: Hover effect over image with width: auto - html

I'm trying to make a caption appear whenever I hover on the image. I want the height of the image to be set to 200px, but the width to be auto. How can I make the span with the caption also correspond to the image width? Thanks!
HTML:
<div class="projects">
<a name="folder"></a>
<h1 class="heading">Projects</h1>
<p class="classProjectsInfo">Recent class projects</p>
<div class="classProjects">
<ul class="img-list">
<li>
<img src="checkers_cover.JPG">
<span class="description2"><span>Checkers61B</span></span>
</li>
<li>
<img src="cover_ngram.JPG">
<span class="description2"><span>NGramMap</span></span>
</li>
<li>
<img src="gitlet_cover.JPG">
<span class="description2"><span>Gitlet</span></span>
</li>
</ul>
</div>
</div>
CSS:
.classProjects {
text-align: center;
margin: 0;
padding: 0;
list-style-type: none;
}
.classProjects li {
display: inline-block;
padding: 5px;
margin: 10px;
position: relative;
height: 250px;
width: auto;
}
.classProjects img {
height: 250px;
width: auto;
}
ul.img-list {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
}
ul.img-list li {
display: inline-block;
height: 250px;
position: relative;
width: auto;
}
span.description2 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 250px;
left: 0;
position: absolute;
top: 0;
width: auto;
}
span.description2 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
span.description2 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 250px;
left: 0;
position: absolute;
top: 0;
width: auto;
opacity: 0;
}
ul.img-list li:hover span.description2 {
opacity: 1;
}

Related

Have pseudo border break out of parent with overflow: auto

I'm trying to create a horizontal/scrollable nav with gradient fades on each end. Setting the parent to overflow: auto almost solves my problem but hides my active link border, which I position absolute as a :before pseudo above its parent link. I was wondering if there was a way for me to keep the overflow while having my pseudo border break out of it? For the sake of this question, the gradient really doesn't matter per se but this structure needs to remain in tact.
ul {
margin: 0;
}
li {
display: inline-block;
}
.vertical-title {
height: 55px;
margin-bottom: 13px;
border-bottom: 3px solid #dceaec;
font-size: 22px;
line-height: 57px;
color: #111;
text-align: center;
text-transform: uppercase;
}
.vertical-title-wrapper {
padding: 0;
z-index: 0;
position: relative;
}
.hub-nav {
display: block;
padding: 0 15px;
width: 100%;
z-index: 1;
white-space: nowrap;
overflow: auto;
}
.hub-nav-link {
position: relative;
}
.hub-nav-link.active-path:before {
content: "";
display: block;
height: 3px;
width: 100%;
left: 0;
position: absolute;
top: -16px;
background-color: #007eff;
}
<div class="hub-wrapper">
<div class="vertical-title">
Page Title
</div>
<nav class="hub-nav">
<ul class="hub-nav-list">
<li class="hub-nav-list-item">
<a class="hub-nav-link active-path" href="">
There's supposed to be a border above me!
</a>
</li>
</ul>
</nav>
</div>
<div>
Content Below
</div>
Negative margins will do the trick:
ul {
margin: 0;
}
li {
display: inline-block;
}
.vertical-title {
height: 55px;
margin-bottom: 13px;
border-bottom: 3px solid #dceaec;
font-size: 22px;
line-height: 57px;
color: #111;
text-align: center;
text-transform: uppercase;
}
.vertical-title-wrapper {
padding: 0;
z-index: 0;
position: relative;
}
.hub-nav {
display: block;
padding: 0 15px;
width: 100%;
z-index: 1;
white-space: nowrap;
overflow: auto;
padding-top: 16px;
margin-top: -16px;
}
.hub-nav-link {
position: relative;
}
.hub-nav-link.active-path:before {
content: "";
display: block;
height: 3px;
width: 100%;
left: 0;
position: absolute;
top: -16px;
background-color: #007eff;
}
<div class="hub-wrapper">
<div class="vertical-title">
Page Title
</div>
<nav class="hub-nav">
<ul class="hub-nav-list">
<li class="hub-nav-list-item">
<a class="hub-nav-link active-path" href="">
There's supposed to be a border above me!
</a>
</li>
</ul>
</nav>
</div>
<div>
Content Below
</div>
So that you don't have to look for too long - I added these two lines into your snippet:
.hub-nav {
padding-top: 16px;
margin-top: -16px;
}

Cannot see the full image with a fixed position on safari

I have created a navbar using HTML and CSS. It works perfectly on IE, Opera, and Chrome.
However, on Safari the logo seems to be cut off. All I did was to add the position fixed to the logo to make the logo stick to the top of the page when the user scrolls down the page.
My HTML:
<div id="nav">
<div id="top-bar">
<div class="container">
<div class="left-right-nav">
<div class="left-nav-2">
<div>
<span></span>
<span><i class="fab fa-facebook"></i> <i class="fab fa-twitter"></i> <i class="fab fa-instagram"></i></span>
<span style="visibility: hidden;">ffff</span>
</div>
</div>
<div class="right-nav">
<div>
<span>01283 575 671</span>
<span>Join Now</span>
</div>
</div>
</div>
<div class="center-container">
<span style="padding:0;"><img src="https://via.placeholder.com/250x115" alt="" width="100%"></span>
</div>
</div>
</div>
<div class="nav-bg">
<div class="container">
<div class="left-right-nav">
<div class="left-nav">
<div>
<span>Facilties</span>
<span>Timetable</span>
<span>Blog</span>
</div>
</div>
<div class="right-nav">
<div>
<span>The Team</span>
<span>Events</span>
<span>Contact Us</span>
</div>
</div>
</div>
<div class="center-nav">
</div>
</div>
</div>
</div>
My CSS:
body{
margin:0;
}
#nav {
z-index: 999;
}
.left-container,
.center-container,
.right-container {
position: absolute;
display: inline-block;
margin: 0;
padding: 0;
width: calc(50% - 125px);
}
.left-container {
left: 0;
height: 50px;
overflow: hidden;
}
.left-container span {
margin: auto;
left: 0;
right: 0;
position: absolute;
}
.center-container {
width: 250px;
height: 115px;
z-index: 2;
left: 0;
right: 0;
margin: auto;
}
.right-container {
right: 0;
height: 50px;
overflow: hidden;
}
.right-container span:last-child {
background: #081F2D;
width: 40%;
float: right;
}
.right-container span:last-child a {
color: #FFDE00;
}
.left-right-container {
background: #FFDE00;
height: inherit;
}
.left-container span,
.right-container span {
padding: 15px 15px;
font-weight: 500;
text-transform: uppercase;
width: 59%;
display: inline-block;
}
.left-container span a,
.right-container span a {
display: block;
color: #081F2D;
text-decoration: none;
text-align: center;
font-size: 17px;
}
#top-bar {
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 0px;
overflow: hidden;
width: 100%;
min-width: 650px;
min-height: 50px;
position: fixed;
z-index: 999;
}
.nav-bg {
width: 100%;
position: absolute;
top: 50px;
height: 50px;
z-index: 2;
margin-top: -1px;
}
.left-right-nav {
background-color: #EEEEEE;
height: inherit;
}
.left-nav,
.left-nav-2,
.center-nav,
.right-nav {
position: fixed;
display: inline-block;
width: calc(50% - 125px);
}
.left-nav,
.left-nav-2{
left: 0;
}
.center-nav {
width: 250px;
height: 50px;
z-index: 1;
left: 0;
right: 0;
margin: auto;
}
.right-nav {
right: 0;
}
/*.left-nav:after, .right-nav:after {
content: '';
display: inline-block;
width: 100%;
}*/
.left-nav div,
.left-nav-2 div,
.left-nav-2 div,
.right-nav div {
margin: auto;
left: 0;
right: 0;
position: absolute;
background-color: #EEEEEE;
text-align: right;
margin-left: -20px;
}
.left-nav-2 div{
background-color: #FFDE00;
}
.left-nav div span {}
.right-nav div span {
float: left;
}
.left-nav div span,
.left-nav-2 div span,
.right-nav div span {
display: inline-block;
}
.left-nav span a,
.left-nav-2 span a,
.right-nav span a {
padding: 15px 40px;
display: block;
font-size: 1rem;
text-align: center;
color: #081F2D;
text-transform: uppercase;
font-weight: 600;
text-decoration: none;
background-color: #EEEEEE;
}
}
The codepen to my problem is https://codepen.io/anon/pen/xymdmP
Try adding position: fixed; and -webkit-transform: translate3d(0, 0, 0); instead of on image tag style.
https://codepen.io/anon/pen/MPZPPy
Thanks

How to move image to center of div using css?

I tried to add margin-left : 25%; to class .four but not work. how can i do ?
.one{
width: 100%;
}
.two{
margin: 0;
padding: 0;
border: 0;
background: transparent;
float: left;
position: relative;
width: 100%;
margin-bottom: 15px;
}
.three{
float: left;
list-style: none;
color: #333;
font-size: 19px;
width: 100%;
background: #fff;
border: 1px solid #ccc;
padding: 10px 0px;
}
.four{
margin-left: 10px;
width: 246px;
height: 138px;
margin-right: 16px;
display: inline-block;
position: relative;
float: left;
}
.five{
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100%;
margin-left: auto;
margin-right: auto;
overflow: hidden;
display: block;
cursor: pointer;
}
.six{
transform: translateY(-50%);
top: 50%;
left: 0;
background-color: transparent;
display: block;
position: absolute;
}
.seven{
width: 246px;
display: block;
margin-left: auto;
margin-right: auto;
max-width: unset;
}
<div class="one">
<ul class="two">
<li class="three">
<div class="four">
<a class="five" href="">
<div class="six">
<img class="seven" src="http://kawamono.com/img/cms/Hobby/Coin%20Bank/x100828-sanrio-hellokitty-mini-bank-ylw-SET.jpg.pagespeed.ic.iSCJA9hZBG.jpg">
</div>
</a>
</div>
</li>
</ul>
</div>
Change the css of .four to this:
.four {
width: 246px;
height: 138px;
margin: 0 auto;
position: relative;
}
.one {
width: 100%;
}
.two {
margin: 0;
padding: 0;
border: 0;
background: transparent;
float: left;
position: relative;
width: 100%;
margin-bottom: 15px;
}
.three {
float: left;
list-style: none;
color: #333;
font-size: 19px;
width: 100%;
background: #fff;
border: 1px solid #ccc;
padding: 10px 0px;
}
.four {
width: 246px;
height: 138px;
margin: 0 auto;
position: relative;
}
.five {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100%;
margin-left: auto;
margin-right: auto;
overflow: hidden;
display: block;
cursor: pointer;
}
.six {
transform: translateY(-50%);
top: 50%;
left: 0;
background-color: transparent;
display: block;
position: absolute;
}
.seven {
width: 246px;
display: block;
margin: 0 auto;
max-width: unset;
}
<div class="one">
<ul class="two">
<li class="three">
<div class="four">
<a class="five" href="">
<div class="six">
<img class="seven" src="http://kawamono.com/img/cms/Hobby/Coin%20Bank/x100828-sanrio-hellokitty-mini-bank-ylw-SET.jpg.pagespeed.ic.iSCJA9hZBG.jpg">
</div>
</a>
</div>
</li>
</ul>
</div>
I noticed that you want to center the image yet you are using float:left to .four, it is conflicting to the result you are expecting. And I changed your margins to margin:0 auto; to properly center it horizontally
You can add:
width: 100%;
To style for .four and .six, This will center the image sideways. Those divs does not have a with, so the the image will not center.
Hope this helps 😄
Oel Kristian Ek Hornnes

Space <li> evenly?

I have OCD and the following needs to be fixed (the spacing of word's in my navigation bar).
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: left;
width: 20%;
max-width: 80px;
display: block;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
All I need is the words to be evenly spread out with the image still intact in the middle like the picture dictates.
Notice how the word art is unevenly spread compared to the right side?
I am the first one to say that I am building my own website and I am new to CSS/HTML scripting.
Appreciate the help,
Thanks.
Use display: table / table-cell for the list / list items.
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
list-style: none;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul:before {
display: table;
content: " ";
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: none;
width: 1%;
max-width: 80px;
display: table-cell;
position: relative;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
Removing the float: left and the display: block from the nav ul li CSS selector and then adding
display: flex;
flex-flow: row wrap;
justify-content: space-between;
to the nav ul CSS selector will change the display from block to flexible boxes, allowing for the text to be more evenly spread out throughout the entire element
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
// float: left;
width: 20%;
max-width: 80px;
// display: block;
flex: 1;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
<body>
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
</body>
EDIT:
I added a few characters around the word art in the link to give it some spacing to resemble the other links.
is how you create whitespace in HTML
Something like this (with slightly changed markup)?
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
display: flex;
height: 30px;
}
nav ul {
display: flex;
height: 30px;
margin: 0;
padding: 0;
}
nav ul:nth-child(1), nav ul:nth-child(3) {
flex: 1;
justify-content: space-between;
}
nav ul:nth-child(1)::before, nav ul:nth-child(3)::before,
nav ul:nth-child(1)::after, nav ul:nth-child(3)::after{
content: '';
}
nav ul:nth-child(2) {
width: 18%;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
max-width: 80px;
display: block;
}
nav ul:nth-child(2) li {
width: 100%;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
left: 0%;
}
<div class="navContainer">
<nav>
<ul>
<li> art </li>
<li> download </li>
</ul>
<ul>
<li><img src="http://www.pd4pic.com/images/eye-black-fan-symbol-design-sun-flower-circle.png"></li>
</ul>
<ul>
<li> portfolio </li>
<li> product </li>
</ul>
</nav>
</div>
Try this, just change the nav percentage as per your requirement. Also for more accurate results you can add media query.
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
list-style: none;
max-width: 75%;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul:before {
display: table;
content: " ";
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: none;
width: 1%;
max-width: 80px;
display: table-cell;
position: relative;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 0;
left: 0;
}
<body>
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
</body>

Elements display in front of their container, but can't be interacted with

I'm currently working on a website and have encountered an interesting problem. I have a container which holds my navbar. For some reason, this container displays behind its contents (Which it should) but mouse interaction acts as if it's in front of its contents.
JSFiddle of my current code
https://jsfiddle.net/qzsxpgrq/
HTML
<div id="navbar">
<div id="bar">
<div id="navLeft">
<div class="navL navbutton">About</div>
<div class="navL navbutton">The Team</div>
</div>
<div id="navLogo">
<div id="logo">
<img src="http://www.epicyoobed.com/res/img/navLogo.png"/>
</div>
</div>
<div id="navRight">
<div class="navR navbutton">Programs</div>
<div class="navR navbutton">Contact</div>
</div>
</div>
</div>
CSS
html {
height: 100%;
font-family: arial;
}
body {
margin: 0;
padding: 0;
background-color: #BBB;
}
#navbar {
margin: 0;
padding: 0;
height: 80px;
width: 100%;
position: fixed;
display: block;
z-index: 1;
}
#bar {
display: block;
position: fixed;
width: 100%;
height: 40px;
background-image: url("http://www.epicyoobed.com/res/img/nav.png");
}
#navRight {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: left;
top: 0;
right: 0;
}
#navbar div div a {
display: block;
text-decoration: none;
padding-top: 5px;
color: #000;
width: 100%;
height: 100%;
font-size: 20px;
}
.current {
background-image: url("http://www.epicyoobed.com/res/img/nav_sel.png");
background-repeat: repeat-x;
}
.navL {
float: right;
}
.navR {
float: left;
}
.navbutton {
display: block;
position: relative;
width: 150px;
height: 100%;
text-align: center;
}
.navbutton:hover {
background-image: url("http://www.epicyoobed.com/res/img/nav_sel.png");
background-repeat: repeat-x;
}
#navLogo {
margin: auto;
height: 40px;
width: 100%;
position: absolute;
display: block;
z-index: 2;
}
#logo {
margin: auto;
height: 80px;
width: 80px;
}
#navLeft {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: right;
}
Xetanai Try adding a z-index of 3 to the #navLeft and navRight.
#navLeft {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: right;
z-index:3;
}
#navRight {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: left;
top: 0;
right: 0;
z-index:3;
}
The issue you're experiencing is because the logo is 100% width and has a z-index of 2. Effectively placing it above the left and right containers.