I'm trying to make it so that you get an explanation of my project when you hover over the image. If I set the span.text-content position to absolute, all of my list items align properly, but i get one box in the upper left corner and I can't see it at all once I scroll to lower images.
When I set the position to relative, it separates all of my images and the text box appears on the left side and below the image, but at least I get one for every image. I've been playing with the z-index because, at first, you could only see the word "Explanation" as a sliver behind the top image.
Finally, my -o-transition won't gray out and I'm not sure what that's about? I've checked jshint and I'm not throwing any errors. Thanks in advance for the help!
HTML
<li>
<!--Dance Class-->
<img src="images/dance.jpg" id="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food-->
<img src="images/tnf.png" id="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food Pitch-->
<img src="images/tnf-pitch.png" id="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Coaches Corner-->
<img src="images/coach.jpg" id="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Singularity2045-->
<img src="images/Singularity2045.png" id="port-img" width="697px" height="733px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Overtime-->
<img src="images/overtime.png" id="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
</ul>
**CSS:**
span.text-content {
/* allows me to adjust the filters and transparency of the outer span/image */
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
font-size: 1.5em;
height: 300px;
left: 0;
position:absolute;
top: 0;
width: 500px;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
z-index: 1;
}
span.text-content span {
/* For text alignment */
display: table-cell;
text-align: center;
vertical-align: middle;
}
ul.img-list li:hover span.text-content{
opacity: 1;
}
#port-img{
z-index: 1;
position: relative;
top: 69px
}
Codepen: http://codepen.io/anon/pen/wWPpQZ
HTML
<ul class="img-list">
<li>
<!--Dance Class-->
<img src="images/dance.jpg" class="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food-->
<img src="images/tnf.png" class="port-img" width="797px" height="307px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--That's Not Food Pitch-->
<img src="images/tnf-pitch.png" class="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Coaches Corner-->
<img src="images/coach.jpg" class="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Singularity2045-->
<img src="images/Singularity2045.png" class="port-img" width="697px" height="733px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
<li>
<!--Overtime-->
<img src="images/overtime.png" class="port-img" width="697px" height="500px"/>
<span class="text-content"><span>Explanation</span></span>
</li>
</ul>
CSS
li {
position: relative;
display: inline-block;
}
.text-content {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
font-size: 1.5em;
position:absolute;
display: block;
top: 0;
right: 0;
bottom:0;
left: 0;
opacity: 0;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
.text-content span {
display: block;
/* For text alignment */
position: absolute;
width: 100%;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
.img-list li:hover .text-content{
opacity: 1;
}
.port-img{
display: block;
}
Explanation
Changed id="port-img" to class as you should not have multiple elements with same id.
Anyway the most important part is that li element have position relative so all child elements positioned absolutely are positioned to each li element.
Different way to position text verticaly is used as it was easier to make explanation box 100% height.
Related
When nav-toggle is checked sidebar reduces width and span is not displayed. When nav-toggle is unchecked it all comes back, but span displays the moment nav-toggle is unchecked and takes vertical space until sidebar is wide enough.
.sidebar {
width: 345px;
transition: width 300ms;
}
#nav-toggle:checked+.sidebar {
width: 70px;
}
#nav-toggle:checked+.sidebar li a span:last-child {
display: none;
}
<input type="checkbox" name="" id="nav-toggle">
<div class="sidebar">
<div class="sidebar-brand">
<h2><span class="lab la-accusoft"></span> <span>Acusoft</span></h2>
</div>
<div class="sidebar-menu">
<ul>
<li>
<a href="" class="active"><span class="las la-igloo"></span>
<span>Dashboard</span>
</a>
</li>
<li>
<a href=""><span class="las la-users"></span>
<span>Customers</span>
</a>
</li>
</ul>
</div>
</div>
I need to delay displaying 'span' until after transition is finished or sidebar is wide enough.
You could try changing the display: none into an opacity: 0, and have another transition with a transition-delay
This may not be an exact answer but could help you in the right direction. https://jsfiddle.net/treckstar/9uqgmnfk/16/
body {
font-size: 16px;
}
.app {
display: flex;
flex-flow: row nowrap;
max-width: 100%;
padding: 20px 0px 0px 0px;
position: relative;
}
#nav-toggle {
position: absolute;
top: 0px;
left: 0px;
}
.nav-toggle-label {
position: absolute;
top: 0px;
left: 20px;
}
.main-content {
flex: 1 0 auto;
height: 50vh;
background: #eee;
padding: .5rem 2rem;
}
.sidebar {
flex: 0 0 20%;
padding: .5rem 2rem;
height: 50vh;
transition: all 1s ease;
background-color: #ccc;
}
#nav-toggle:checked+.sidebar {
flex: 0 0 5%;
padding: .5rem .5rem;
}
.sidebar ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.sidebar li a span {
opacity: 1;
transition: opacity .2s ease;
transition-delay: 1.25s;
}
#nav-toggle:checked+.sidebar li a span:last-child {
opacity: 0;
}
<div class="app">
<label class="nav-toggle-label" for="nav-toggle">Toggle</label>
<input type="checkbox" name="cb" id="nav-toggle">
<div class="sidebar">
<div class="sidebar-brand">
<h2><span class="lab la-accusoft"></span> <span>Acusoft</span></h2>
</div>
<div class="sidebar-menu">
<ul>
<li>
<a href="" class="active"><span class="las la-igloo"></span>
<span>Dashboard</span>
</a>
</li>
<li>
<a href=""><span class="las la-users"></span>
<span>Customers</span>
</a>
</li>
</ul>
</div>
</div>
<main class="main-content" role="main">
<h2>
Main Content
</h2>
</main>
</div>
I have a working navigation, but I want the transition between switching dropdown menus to be smoother. Right now, there is an uncomfortable 'blinking' when you hover between the various main menu links. I know it is caused because of the transition time, but I'm not sure how to fix it. I want the transition to be seamless, as if only the dropdown items themselves are changing (not the background).
Below is my code, and here is a link to a CodePen (https://codepen.io/zp12345/pen/mQzvXr). Any help is appreciated. Thanks!
HTML
<div class="nav-links">
<ul class="nav-primary" id="nav-primary">
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item One</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>1.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Two</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>2.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Three</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.1</h5>
</a>
</li>
<li class="nav-dropdown-item">
<a href="#link">
<h5>3.2</h5>
</a>
</li>
</ul>
</li>
<li class="nav-item-top">
<a href="#link">
<span class="nav-item-label">Item Four</span>
</a>
<ul class="nav-dropdown">
<li class="nav-dropdown-item">
<a href="#link">
<h5>4.1</h5>
</a>
</li>
</ul>
</li>
</ul>
</div>
SCSS
.nav-primary {
display: flex;
flex-grow: 1;
justify-content: center;
list-style-type: none;
padding-left: 0;
}
.nav-item-top .nav-item-label {
color: #383838;
font-size: 18px;
padding: 0 24px;
cursor: pointer;
}
.nav-item-top {
&:hover {
.nav-item-label {
color: #319644;
}
.nav-dropdown {
visibility: visible;
opacity: 1;
padding: 16px 0;
}
}
}
.nav-dropdown {
width: 100%;
left: 0;
position: fixed;
top: 60px;
transition: .2s;
opacity: 0;
z-index: 3;
padding: 0;
background-color: #133751;
color: #133751;
display: flex;
align-items: center;
justify-content: center;
visibility: hidden;
list-style-type: none;
.nav-dropdown-item {
transition: .2s;
padding: 12px 24px;
text-align: center;
color: #fff;
cursor: pointer!important;
}
h5 {
color: #fff;
margin: 0;
text-transform: none;
font-size: 16px;
}
}
.nav-dropdown-item {
a {
transition: all 0.2s;
text-decoration: none;
}
}
In your styles you can adjust the .nav-dropdown transition property to a higher time to make it seem more smooth.
.nav-dropdown {
transition: 2s;
}
As mentioned by #mike-tung, it is about timing of the transition.
You could use an opacity effect on nav-dropdown with low transition timing. It would run smoothly.
.nav-hover:hover {
.nav-dropdown {
transition: 0.3s ease;
opacity: 1;
}
}
.nav-dropdown {
transition: 0.2s ease;
opacity: 0;
...
}
And I see an issue that when you hover out the nav bar, the dropdown is immediately hidden, making it virtually impossible for user to access it.
Thus, I'd suggest you to reduce the top attribute ov nav-dropdown, so it stays right below the NAV menu, and then set the background color only to your .nav-dropdown-item.
.nav-dropdown-item {
width: 100%;
background-color: #133751;
...
}
And giving a padding top to .nav-dropdown:
padding: 20px 0 0; // I let the 0s to not mess with your original padding: 0;
The results would be something like this:
https://codepen.io/annabranco/pen/QJYWvm?editors=1100
Hope it helps! :)
I have three images acting as tabs. Each image has a semi-transparent overlay of orange. When you hover over it, the orange opacity will be darker. When you click on the image, the active state should look the same as the hover state.
So I did this:
.overlay:hover:after, .job-seekers-nav li.active {
opacity: .8!important;
transition: 1s ease;
}
But when I ran my code, I am able to do the hover effect but when I click on a certain image, it would load the right content, and once I hover off the image, the image will revert back to the original semi-orange color and not the darker hovered orange.
html
<div class="row main-container job-seekers-nav">
<!--job seekers tab-->
<ul>
<li>
<div class="col-sm-4">
<a data-toggle="tab" href="#light-industrial">
<div class="overlay border-bottom-yellow">
<img src="img/light-industrial.jpg" class="img-responsive center-images">
</div>
</a>
</div>
</li>
<li>
<div class="col-sm-4">
<a data-toggle="tab" href="#general-warehousing">
<div class="overlay border-bottom-yellow">
<img src="img/general-warehousing.jpg" class="img-responsive center-images">
</div>
</a>
</div>
</li>
<li>
<div class="col-sm-4">
<a data-toggle="tab" href="#administrative-work">
<div class="overlay border-bottom-yellow">
<img src="img/administrative-work.jpg" class="img-responsive center-images"/>
</div>
</a>
</div>
</li>
</ul>
<!--end of job seekers tab-->
</div>
css
.job-seekers-nav ul {
padding: 0;
}
.job-seekers-nav li {
display: inline;
list-style: none;
}
.overlay {
display:inline-block;
position: relative;
}
.overlay:after {
content:'';
top: 0;
left: 0;
z-index: 10;
width: 100%;
height: 100%;
display: block;
position: absolute;
background: #f4511e;
opacity: 0.5;
}
.overlay:hover:after, .job-seekers-nav li.active {
opacity: .8!important;
transition: 1s ease;
}
.border-bottom-yellow {
border-bottom: 30px solid #fce565;
}
Try this:
.overlay:hover:after,
.job-seekers-nav li.active .overlay:after
{
opacity: .8!important;
transition: 1s ease;
}
I've made a JSFiddle to illustrate what I have at the moment. Please view my code here:
Some of my CSS snippet code:
.subnav {
display: none;
position: absolute;
//top: 58px;
background: #dfe6e8;
padding: 24px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
transition: all .5s ease;
}
.subnav li {
margin-right: 0px !important;
min-width: 142px;
}
.subnav li a {
padding-bottom: 0px !important;
margin-bottom: 16px;
}
.subnav li:last-child a {
margin-bottom: 0px;
}
.has-dropdown:hover .subnav {
display: block;
}
I'm having problem to make my UL to stretch fullscreen. Here's what I'm trying to achieve as below:
Any help would be appreciated
To achieve this you have to make few structural and css changes. I edited your fiddle and made some changes to the navigation.
Html:
<div class="nav-container">
<nav class="top-bar">
<div class="container-fluid">
<div class="row nav-menu">
<div class="col-xs-12 columns">
<a class="navbar-brand" href="index.html"><img alt="Logo" class="logo logo-light" src="img/logo-light.png"> <img alt="Logo" class="logo logo-dark" src="http://www.subcablenews.com/links/images2/telenor.gif"></a>
<ul class="menu navbar-right">
<li>
ABOUT
</li>
<li class="has-dropdown">
PROGRAMMES
<ul class="subnav">
<li>
Programme 1
</li>
<li>
Programme 2
</li>
<li>
Programme 3
</li>
<li>
Programme 4
</li>
</ul>
</li>
<li class="has-dropdown">
PROJECTS
<div class="subnav subnav-halfwidth fullwidth">
<div class="col-sm-4">
<h6 class="alt-font">Project Lists</h6>
<ul class="subnav subnav-halfwidth">
<li>
Project 1
</li>
<li>
Project 2
</li>
<li>
Project 3
</li>
<li>
Project 4
</li>
</ul>
</div>
<div class="col-sm-4">
<h6 class="alt-font">Project Lists 2</h6><img alt="Logo" class="logo" src="http://www.subcablenews.com/links/images2/telenor.gif"></div>
<div class="col-sm-4">
<h6 class="alt-font">Project Lists 2</h6><img alt="Logo" class="logo" src="http://www.subcablenews.com/links/images2/telenor.gif"></div>
</div>
</li>
<li class="has-dropdown">
MEDIA
<ul class="subnav">
<li>
Media 1
</li>
<li>
Media 2
</li>
<li>
Media 3
</li>
<li>
Media 4
</li>
</ul>
</li>
<li>
CONTACT
</li>
</ul>
<ul class="social-icons text-right">
<li>
<i class="icon social_twitter"></i>
</li>
<li>
<i class="icon social_facebook"></i>
</li>
<li>
<i class="icon social_instagram"></i>
</li>
</ul>
</div>
</div><!--end of row-->
<div class="mobile-toggle">
<i class="icon icon_menu"></i>
</div>
</div><!--end of container-->
</nav>
</div>
Extra Css:
.subnav.fullwidth{
position: absolute;
right: -15px;
top: 58px;
width: 100vw;
background: #F6F4F4;
padding: 48px 64px 48px;
box-shadow: inset 0 1px 0 #e2e3df, 0 3px 6px rgba(113,111,111,.7);
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
-ms-transform: translateX(0);
-o-transform: translateX(0);
transform: translateX(0);
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
-moz-transition: opacity .3s 0s, visibility 0s 0s;
transition: opacity .3s 0s, visibility 0s 0s;
/* box-shadow: 1px 2px 5px #7D7D7D; */
}
.row{margin:0}
.top-bar .logo {
width: 150px;
}
.subnav li{float:none; display: block;}
Here is Updated Fiddle. Make sure you check the html as well. Because I made some changes in that too.
Read this to get better understand about bootstrap navigation. Hope this helps you.
It's because the parent elements aren't at 100% width. You can override this by using width:100vw; on any element that you want to take up the full width. Also, try and remember next time to only include css on your fiddle that's relevant to the html at question. It's a lot to sort through for someone trying to help when you include your entire stylesheet.
Im stuck in creating the following menu. Cant get it to center. Seems like img inside span is breaking the display.
DESIRED RESULT:
HTML:
<ul id="rounded-cats" class="cleardiv">
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
</ul>
CSS:
#rounded-cats {
text-align: center;
//display: table;
border: 1px solid red;
width: 100%
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline;
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}
JSFIDDLE:
http://jsfiddle.net/gtux2snu/
Look at this demo
I have made changes to #rounded-cats li and #rounded-cats span img styles.
#rounded-cats {
text-align: center;
//display: table;
border: 1px solid red;
width: 100%
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline-block;
width:150px;//added some width to each li
float:left;//floated elements left
text-align:left;//aligned category name with image
padding:20px;//add padding so it looks good and separated.
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important;
margin-top:18px;//centered img inside circle
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}
Look at this Fiddle
li{
display: table;
}
span{
display: table-cell;
}
I now got exactly what you want. Just like you want it. Take a look at the fiddle and let me know if this is what you want.
UPDATED!!!!!!!!!!!!!!!!!!!!!
My solution is to use float: left to li elements and clear float after 5n:
#maintCont {
position:relative;
width: 100%;
margin: 0 auto;
text-align: center;
}
#rounded-cats {
text-align: center;
border: 1px solid red;
display: inline-block;
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline;
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}
#rounded-cats > li {
float: left;
margin: 20px;
}
#rounded-cats > li:nth-child(5n) {
clear: left;
padding-left: 65px;
}
<div id="maintCont">
<ul id="rounded-cats" class="cleardiv">
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li> <a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
</ul>
</div>
You will have to make you li inline-block and give the span some padding :
demo
#rounded-cats li {
display: inline-block;
}
And the span :
#rounded-cats span {
width: 70px;
height: 70px;
padding: 21px; /* to get a span width and height of 112px */
/* code */
}
I think that this should do the trick:
http://jsfiddle.net/gtux2snu/15/
I added a div element to wrap the li content with relative position so the category name can be absolute positioned to the bottom. Also set the span circle to relative and the img to absolute with top: 50% and a negative half height margin-top.
<a href="#">
<div class="cats-wrap">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</div>
</a>
I changed this part of CSS:
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
position: relative; /* To contain the absolute positioned img */
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: inline-block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important;
position: absolute;
top: 50%; /* align all the img 50% top */
left: 50%;
margin-left: -35px;
margin-top: -35px; /* Half the img height so img is centered */
}
#rounded-cats .cats-wrap{ /* Wrapper element set to relative */
display: inline-block;
position: relative;
height: 140px; /* Add some height to the wrapper so the category name can fit */
}
#rounded-cats strong{
position: absolute;
bottom: 0; /* Category is aligned to the absolute bottom */
left: 0;
right: 0;
margin: auto; /* To center the category name */
}
I have fixed some issues in your css and you could simply do that like this:
DEMO
* {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
body {
margin:0;
}
#rounded-cats {
text-align: center;
border: 1px solid red;
width: 100%;
margin: 0;
padding: 0;
display: inline-block;
}
#rounded-cats li {
display: inline-block;
margin: 20px;
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span:before {
height: 100%;
content:" ";
vertical-align: middle;
display: inline-block;
}
#rounded-cats span img {
vertical-align: middle;
}
#rounded-cats a {
text-decoration: none;
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
<ul id="rounded-cats" class="cleardiv">
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
<li>
<span><img src="http://placehold.it/70" height="70" /></span>Category name
</li>
</ul>
Here's my code pen http://jsfiddle.net/dfrierson2/gtux2snu/19/
I seperated the elements into div's for centering, and I used lists for the inline display.
ul li {
list-style-type: none;
margin-left: 10px;
}
li {
display: inline-block;
}
li a {
color: #000;
text-decoration: none;
margin-bottom: 10px !important;
}
#rounded {
text-align: center;
//display: table-cell;
vertical-align: middle;
margin: 1em 0;
height: auto;
position: relative;
}
#rounded img {
margin-bottom: 55px;
position: relative;
}
#rounded-cats {
background: #c7c7c7;
width: 100px;
height: 100px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
text-align: center;
border-box: sizing;
margin-bottom: 45px;
padding: 20px;
position: relative;
}
<ul>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
<li>
<div id="rounded-cats">
<div id="rounded">
<img src="http://placehold.it/70" height="70" />
<a href="#">
<strong>
Category name
</strong>
</a>
</div>
</div>
</li>
</ul>