Getting absolutely positioned elements to flow with the rest of a layout - html

I have a slideshow which works by absolutely positioning images one on top of the other and then changing the z-index of whatever slide I want to appear. The problem is I'd like to move it to the center and have the "prev" link and the "next" link on either side of the slideshow.
I've been trying to create a container with relative positioning around the absolutely positioned items and can get the slideshow to move around, but the next link doesn't show up on the other side of the slideshow (and I hope not to use hacks with margins to mess up the flow of the page).
My goal is to be able to treat the slideshow box just like any other box that flows with the rest of the page. Is there a way to do that?
my html
<a id="prevLink" href="#">Prev</a>
<div class="container">
<ul id="slideshow">
<li class="current">First</li>
<li>Second</li>
<li>Third</li>
</ul>
</div>
<a id="nextLink" href="#">Next</a>
my css:
.container {
position: relative;
}
#slideshow {
position: relative;
list-style-type: none;
}
.current {
z-index: 99;
}
#slideshow li {
position: absolute;
width: 5em;
height: 5em;
background-color: #333;
font-size: 3em;
color: #fff;
}
Link to the slideshow: http://codepen.io/KenjiCrosland/pen/QyqVaz

A couple changes you need:
Set the #container to display:inline-block and give it a width so that it stays inline.
remove the default padding from #slideshow.
Try this CSS:
.container {
position: relative;
width:15em;
display:inline-block;
}
#slideshow {
position: relative;
list-style-type: none;
padding:0;
}
.current {
z-index: 99;
}
#slideshow li {
position: absolute;
width: 5em;
height: 5em;
background-color: #333;
font-size: 3em;
color: #fff;
}
Here's a fork of your Pen.

You need to give a width and height to .container and center it.
Set in absolute prev and next, add some padding to .container so it has room for buttons. http://codepen.io/anon/pen/MKERWZ
.container {
position: relative;
width: 15em;/* 3x5em of lis */
height:15em;
padding: 0 4em;/* room on left/right for buttons */
margin: auto;
background: gray;/* demo purpose, lets see where it stands */
}
#slideshow {
list-style-type: none;
margin:0 ;
padding:0;
}
.current {
z-index: 99;
}
#slideshow li {
position: absolute;
width: 5em;
height: 5em;
background-color: #333;
font-size: 3em;
color: #fff;
}
#prevLink,
#nextLink {
position:absolute;
top:50%;
line-height:0;/* to set in center without translate() */
}
#prevLink {left:0.75em;
}
#nextLink {right:0.75em;
}

Related

CSS: background image opacity in ul-li menu

I have a menu using ul/li items, and they have a background image.
All over the Internet, and in stackoverflow, there is information on how to hack background image opacity. For example: https://scotch.io/tutorials/how-to-change-a-css-background-images-opacity
But not for my particular use case when using menus. It seems particularly tricky. From everything I have tried, one of the solutions in the aforementioned website seems to work the best.
But still, the image is not vertically aligned. I cannot seem to be able to center the image in the menu...
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {float: left;}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {background-color: #4CAF50;}
.my-container {
position: relative;
overflow: hidden;
}
.my-container a {
position: relative;
z-index: 2;
}
.my-container img {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: auto;
opacity: 0.2;
}
<ul>
<li><div class="my-container">Aaaa <img src="http://www.joaobidu.com.br/jb/content/uploads/2012/03/cancer3.png"></img></div></li>
<li><div>Bbbb</div></li>
<li><div>Cccc</div></li>
<li><div>Dddd</div></li>
<li><div>Eeee</div></li>
</ul>
Hi,Please try this one.
If we will use top:-14px,It will affecting the modern browser like chrome and safari which is not accepting negative values.So we can use below format for background images.
.my-container {
background-image:url("http://www.joaobidu.com.br/jb/content/uploads/2012/03/cancer3.png");
background-size:cover;
background-repeat:no-repeat;
background-position:center;
}

CSS: div with display:table; within a list element no auto height?

I have an unordered list ul li where each li is floated but has a height value due to setting overflow:hidden; to the list-item.
So when hovering the element in the webinspector the list-item clearly has a height value of 288px.
Within each li i also have a div.caption with the following attributes:
.caption {
opacity: 0;
position: absolute;
height: 100%;
left: 0;
top: 0;
width: 101%;
text-align: center;
background-color: rgba(0,0,0,.6);
display: table;
}
<li>
<img src="#">
<div class="caption">some more elements in here</div>
</li>
The height of the list-item as mentioned above is automatic due to the height of the image within the li. (the webinspector clearly shows that the list-item has a height)
However my .caption div within the li is not automatically as high as the parent. I want the div.caption to be 100% as high as the list item.
What can I do here?
Example: http://jsfiddle.net/rgwcL8qt/1/ The overlay should always cover the entire image.
div.caption { display: table } with div.caption-in { display: table-cell } within creates a new block formatting context.
Changing to div.caption { display: block; } should solve your problem.
EDIT: Should you need to center the content inside the caption div then you ought to take a different approach:
.caption:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.3em;
}
.caption {
opacity: 0;
z-index: 1;
position: absolute;
height: 100%;
left: 0;
top: 0;
width: 101%;
text-align: center;
background-color: rgba(0,0,0,.6);
display: block;
cursor: pointer;
}
.caption-in {
display: inline-block;
vertical-align: middle;
text-align: center;
}
http://jsfiddle.net/vmg8jfed/
Try adding
<div style="clear: both"></div>
at the end of div containing .caption class.
Add the div.caption {bottom:0; display:block;}
Fiddel

Elements not overlapping with z-index

In my navigation I have a protruding red box. I want that red box to overlap all Divs bellow it. I set a margin for it so it would space it out among the other elements I put in the black box. The problem is that it's margin is also effecting the layout of separate elements' children bellow it. When I add a negative margin to the child elements of the section bellow it does overlap but I want the red box to be on-top. I use z-index and it doesn't seem to work.
Here's my example on Jsfiddle:
http://jsfiddle.net/1qsuvhnd/29/
HTML
<nav>
<div id="ribbon"></div>
</nav>
<div id="context">
<div class="link"></div>
</div>
CSS
#context {
width: auto;
padding: 20px;
height: 300px;
background-color: blue;
z-index: 1;
}
#context .link {
float: Left;
height: 260px;
width: 300px;
margin-left: -140px;
background-color: White;
z-index:1 !important;
}
nav {
width: auto;
height: 65px;
background-color: black;
z-index:99 !important;
clear:both;
}
nav #ribbon {
float: left;
margin: 0px 50px;
Width: 65px;
height: 130px;
background-color: red;
z-index= 99;
}
To use z-index, you need to specify a position (like absolute, fixed, or relative).
And the last line written is wrong:
z-index = 99;
The correct way to write it is:
z-index: 99;
How about: http://jsfiddle.net/1qsuvhnd/30/
change the ribbon to position: absolute; and fix the z-index = typo :D
Now you don't need that margin hack!!
nav #ribbon {
float: left;
margin: 0px 50px;
Width: 65px;
height: 130px;
background-color: red;
z-index: 99; /* take that equal out and make it a colon */
position: absolute; /* position: absolute to the rescue!!!! */
}
You need to specify a position CSS rule for the nav div for the z-index to work correctly, like this:
nav #ribbon {
float: left;
margin: 0px 50px;
Width: 65px;
height: 130px;
background-color: red;
z-index:99;
position: relative;
}
Here is the new jsFiddle link:
http://jsfiddle.net/1qsuvhnd/54/

Resizable fixed footer with absolute elements within it

I want to make my fixed footer resizable on my 320px viewport, together with the absolute elements inside it.
I manage to get the footer div resizable, but the elements inside it doesn't seems to stick within the footer div when i resize the windows.
Note: I'm trying to create a footer with a background image. This image have some clickable areas which i created using the unordered list.
Here is my HTML Code:
<footer>
<ul>
<li>Shoot Me
</li>
<li>Facebook
</li>
<li>Tumblr
</li>
<li>Instagram
</li>
<li>E-mail
</li>
</ul>
</footer>
Here is my CSS Code:
footer{
z-index:21;
display:block;
position:fixed;
bottom:0;
left:0;
right:0;
padding:0;
width:1280px;
height: 426px;
max-width: 100%;
background:url(../images/layout/footer.png) no-repeat center bottom;
background-size: 100%;
margin:0 auto;
pointer-events:none;
}
footer ul li {
display: inline;
width: 14%;
}
footer ul li img {
border: none;
padding-left: 8px;
}
footer ul li a.shootme-link{
position:absolute;
bottom:200px;
left:1080px;
width: 151px;
height: 33px;
background:url(../images/layout/shootme.png) bottom;
pointer-events:auto;
/* Hide the text. */
display: inline-block;
overflow: hidden;
font-size: 0px;
}
footer ul li a.shootme-link:hover {
background-position: 0 0;
}
footer ul li a.facebook-link {
position:absolute;
width:33px;
height:29px;
bottom:40px;
left:970px;
pointer-events:auto;
/* Hide the text. */
display: inline-block;
overflow: hidden;
font-size: 0px;
}
footer ul li a.tumblr-link {
position:absolute;
width:33px;
height:29px;
bottom:40px;
left:980px;
pointer-events:auto;
/* Hide the text. */
display: inline-block;
overflow: hidden;
font-size: 0px;
}
footer ul li a.instagram-link {
position:absolute;
width:33px;
height:29px;
bottom:40px;
left:1030px;
pointer-events:auto;
/* Hide the text. */
display: inline-block;
overflow: hidden;
font-size: 0px;
}
footer ul li a.mail-link {
position:absolute;
width:33px;
height:29px;
bottom:40px;
left:1055px;
pointer-events:auto;
/* Hide the text. */
display: inline-block;
overflow: hidden;
font-size: 0px;
}
I'm still very much noob in CSS3 so i hope someone could enlighten me on this and pardon for my bad English. Hope it's not that confusing. Thanks
Here is the fiddle: http://jsfiddle.net/5JWG5/
Full screen fiddle: http://jsfiddle.net/5JWG5/embedded/result/
Ok, I Hope this help you, first:
it's easier using divs instead of a list, so we can achieve the location of the elements better.
<footer>
<div class="shootme-link">
Shoot Me
</div>
<div class="social">
<a class="facebook-link" href=" " target="_blank" >Facebook</a>
Tumblr
Instagram
E-mail
</div>
</footer>
as you can see, i also reduce the number of classes, instead using one for each element, now i'm using just one name it "social", this will be a Div box that will nest the link elements.
Then, we will point to the links inside that div to give them size and we will float all to the left. using display: inline-block and text-align: left; (you could also use display: block; and float: left; but the you should give them a margin)
this is the new CSS
footer{
z-index:21;
display:block;
position: absolute;
margin: 0 auto;
bottom:0;
left: 0;
right: 0;
width:1280px;
height: 426px;
max-width: 100%;
background:url("http://jennisa.com/images/layout/footer.png") no-repeat right bottom;
background-size: cover;
pointer-events:none;
}
footer > .shootme-link {
display: block;
position:absolute;
bottom:200px;
right: 50px;
width: 151px;
height: 33px;
background:url("http://jennisa.com/images/layout/shootme.png") bottom;
pointer-events:auto;
/* Hide the text. */
text-indent: -999px;
overflow: hidden;
}
footer > .social {
position: absolute;
width: 163px;
height: 32px;
bottom: 46px;
right: 163px;
pointer-events: auto;
}
footer > .social > a {
background-color: blue;
width:33px;
height:29px;
display: inline-block;
text-align: left;
pointer-events:auto;
/* Hide the text. */
text-indent: -999px;
overflow: hidden;
}
there is a jsfiddle
for the background size I use the attribute cover instead 100% because this will kep the proportions of the image to cover all the div and also i positioned the image to the right, because is there where the elements are (the elements also are positioned absolute since the right.
you just delete background-color: blue; from the links (I used it to point the changes visually)
Hope this help you.
I'm not shure of what you're trying to do, i speak spanish, if that language works for you, you could explain better in it.
anyway, i think you could use position: relative; instead of position:absolute;.
"inline-block" has text capabilities, so you can use text-align: center; or use display:block; and float everything to the left.
but i don't see the point of "float" your elements if give them an absolute position.. may be you could use jsfiddle to explain your point better with an example.
is not necessary to use max-width: 100%;you just put the width at 100% of the size and declare the minimun width size, for example "320px" and the div will not be smaller than this size.
Hope this help you :)

Center aligning an element with firefox and 100% width

So Im trying to do a simple header where I have the text aligned central with a 2px border running underneath this.
The code I have works and should work perfectly on every other browser except firefox which is aligning the border right of the page as if the beginning of the border is aligned in the center. If I remove the text align center the border is placed perfectly but the text is aligned to the left obviously. Why is firefox doing this?
CSS:
.my-title {
position: relative;
margin-bottom: 70px;
padding-bottom: 15px;
}
.my-title:after {
position: absolute;
bottom: 0;
height: 2px;
background-color: #ffd500;
content: "";
width: 100%;
}
.align-center {
text-align: center;
}
Html:
<div class="row">
<div class="col-xs-12">
<hgroup class="my-title align-center">
<h1>Header</h1>
<h2>Sub-Header</h2>
</hgroup>
</div>
</div>
since your pseudo element is in position:absolute; it has no width in the flow of your content and follows text-align:center; set on parent.( as absolute it has, in the flow of content, 0 for heigh and width).
3 possibilities:
add the rule : left:0; no matter what text-align on parent will be, it will be drawn from left coordonates.
add the rule : display:block; so it behaves like a block element and ill ignore the text-align, it will do a break line and will be drawn from left or right (follows the direction/dir of document).
keep it in the flow:
.my-title {
position: relative;
margin-bottom: 70px;
padding-bottom: 15px;
}
.my-title:after {
height: 2px;
background-color: #ffd500;
content: "";
width:100%;
display:inline-block;
vertical-align:bottom;
}
.align-center {
text-align: center;
}
Using property left solved the problem:
.my-title:after {
left: 0;
}
Demo
Try this:
#-moz-document url-prefix()
{
.my-title
{
position: relative;
margin-bottom: 70px;
padding-bottom: 15px;
}
.my-title:after
{
position: absolute;
bottom: 0;
height: 2px;
background-color: #ffd500;
content: "";
width: 100%;
}
.align-center
{
text-align: center;
}
}