How to center content of an absolute div horizontally
5 answers
Here's an example of how it works. You can remove the .arrow css rule because it does nothing.
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: relative;
margin: 0 auto;
max-width: 960px;
}
.home .center {
position: absolute;
width: 100%;
bottom: 0;
top:30px;
text-align: center;
}
+2
source to share
Try the following:
HTML code:
<div class="home">
<div class="center">
<a class="arrow fa fa-long-arrow-down fa-3x" href="#"></a>
</div>
</div>
CSS code:
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: relative;
margin: 0 auto;
max-width: 960px;
}
.home .center {
position: absolute;
bottom: 0;
top:30px;
text-align: center;
}
.arrow {
}
+1
source to share
This should work, try it.
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: absolute;
margin: 0 auto;
max-width: 960px;
}
.center {
position: relative;
bottom: 0;
top:30px;
text-align: center;
}
.arrow
left: 0;
right: 0;
As an explanation as to why this works: well, the wrapper div must be absolute, and its content must be relative to the position of whatever is inside the wrapper, however you please. This way it will be easier for you if you want to add additional relative divs
+1
source to share