I am making a personal website with a parallax background which takes 100% of the screen size, however when I change the screen size to the minimum size the text goes out of the div, I use a padding-top percentage. I do know quite a bit of css but I don't want to fiddle around and mess everything up, I've looked everywhere but no answer came close to my problem. Basically I just want to vertically and horizontally center my content even when I resize my screen.
Here's my CSS:
.wrapper {
width: 100%;
/* whatever width you want */
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 52.50%;
/* 16:9 ratio */
display: block;
content: '';
}
.main {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/* fill parent */
background-image: url('/storage/images/background.jpeg');
/* let's see it! */
color: white;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.text {
margin-top: 15%;
text-align:center;
}
And my HTML:
<div class="row">
<div class="wrapper">
<div class="main">
<div class=text>
<img src="/storage/images/image.jpg" style="border-radius:100%; width:150px; height:auto;">
<h1>My name</h1>
</div>
</div>
</div>
</div>
Use :
.main {
text-align: center;<-----------------------
//More code..........
}
.text {
max-width: 150px;
text-align: center;
display: inline-block;
margin-top: 15%;
}
.text img {
border-radius:100%;
width:70%;
height:auto;
}
.text h1 {
margin: 0;
padding: 0;
}
.wrapper {
width: 100%;
/* whatever width you want */
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 52.50%;
/* 16:9 ratio */
display: block;
content: '';
}
.main {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/* fill parent */
background-image: url('http://justcuteanimals.com/wp-content/uploads/2016/10/baby-bear-pictures-cute-animal-pics.jpg');
/* let's see it! */
color: white;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
text-align: center;
}
.text {
max-width: 150px;
text-align: center;
display: inline-block;
margin-top: 15%;
}
.text img {
border-radius:100%;
width:70%;
height:auto;
}
.text h1 {
margin: 0;
padding: 0;
}
<div class="row">
<div class="wrapper">
<div class="main">
<div class=text>
<img src="http://justcuteanimals.com/wp-content/uploads/2016/10/baby-bear-pictures-cute-animal-pics.jpg">
<h1>My name</h1>
</div>
</div>
</div>
</div>
Related
Good morning everyone
How can I place the different DIVs on top of each other?
I have a row that contains left and right DIVs.
In the right I have image and in the left text.
I also have a DIV that needs to be placed between the text and the background.
I've tried and gotten a few things, but I can't get the right DIV sticky-top in the right place.
I don't want to use Java but only CSS
.infosite-container {
margin: 0 auto;
width: 100%;
position: relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background: red;
top: 50%;
left: 50%;
z-index: 999;
transform: translate(-50%, -50%);
}
.infosite-left-content {
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index: 99;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index: 99;
}
.uptxt {
position: relative;
z-index: 9999;
}
<section class="infosite" id="infosite-section">
<div class="container-fluid infosite-container">
<div class="row">
<div class="col-md-6 infosite-left-content">
<div class="">
</div>
</div>
<div class="sticky-top">
<p>Sticky Top</p>
</div>
<div class="col-md-6 infosite-right-content">
<div class="uptxt">
</div>
</div>
</div>
</div>
</section>
Can I get some help. I am sorry but I am not an expert.
Thanks
It's not working because you're parent is way larger than it's child. Because the div's could have different widths I suggest you to put the sticky-top div into the infosite-left-content class.
Like this:
<div class="container-fluid infosite-container">
<div class="row">
<div class="col-md-6 infosite-left-content">
<div class="sticky-top">
<p>Sticky Top</p>
</div>
</div>
<div class="col-md-6 infosite-right-content">
<div class="uptxt">
</div>
</div>
</div>
</div>
</section>
Second you need to adjust you css accordingly:
/* InfoSite ---------------------------------- */
.infosite-container {
margin: 0 auto;
width: 100%;
position:relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background:red;
top:50%;
right:-75px;
z-index:999;
transform: translateY(-50%)
}
.infosite-left-content {
position: relative;
background-color: blue;
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index:100;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index:99;
}
.uptxt {
position: relative;
z-index:9999;
}
/* ---------------------------------------------- */
I hope this works for you :D
Thank you for your response and possible solution.
Unfortunately it doesn't work as I would like, the sticky DIV stays on top of everything and not between the two divs.
I attach a picture of the result of how I would like its visualization.
Insert the sticky DIV between the background and the descriptive text that should appear as the last layer.
A possible solution is to use a single background DIV, ok it works, but I would like to have two of them so I can insert two images for example.
Thanks
Your css should be like this:
.infosite-container {
margin: 0 auto;
width: 100%;
position:relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background:red;
top:50%;
right:-75px;
z-index:500;
transform: translateY(-50%)
}
.infosite-left-content {
position: relative;
background-color: blue;
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index:100;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index:900;
}
.uptxt {
position: relative;
z-index:9999;
}
You can change the order in which the elements are stacked on top of each other with z-index - the greater it is, the higher the element will be !
I have an image, and a text-group that holds text.
<div class="container">
<img src="https://images.unsplash.com/photo-1603221580671-2d3aa6824923?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<div class="text-group">
<h1>Moon</h1>
<h1>Star</h1>
</div>
</div>
I want the first word to always be positioned half on the image and half off the image like this.
The Problem: When I add more text into the text-group, it pushes the first word up.
Without adding a height to my text-group and without changing the bottom position of my text-group, how can I prevent my text from being pushed up when more text is added? In other words, how can I achieve the result below?
Full HTML and CSS
* {
margin: 0;
padding: 0;
}
.container {
position: relative;
}
img {
width: 100%;
height: 300px;
object-fit: cover;
}
.text-group {
position: absolute;
bottom: -15%;
}
h1 {
color: green;
font-size: 5rem;
}
<div class="container">
<img src="https://images.unsplash.com/photo-1603221580671-2d3aa6824923?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<div class="text-group">
<h1>Moon</h1>
<h1>Star</h1>
</div>
</div>
you might not need position. A negative top margin on the first h1 is plenty enough, no need then to mind img's height.
* {
margin: 0;
padding: 0;
}
.container {
/* position: relative; */ /*optionnal i believe */
}
img {
width: 100%;
height: 300px;
object-fit: cover;
}
.text-group {
/* position:absolute */ /*optionnal i believe */
}
.text-group h1:first-child {
margin-top: -0.7em;
}
h1 {
color: green;
font-size: 5rem;
}
<div class="container">
<img src="https://images.unsplash.com/photo-1603221580671-2d3aa6824923?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<div class="text-group">
<h1>Moon</h1>
<h1>Star</h1>
</div>
</div>
works the same with position:
* {
margin: 0;
padding: 0;
}
.container {
position: relative;
}
img {
width: 100%;
height: 300px;
object-fit: cover;
}
.text-group {
position: absolute
}
.text-group h1:first-child {
margin-top: -0.7em;
}
h1 {
color: green;
font-size: 5rem;
}
<div class="container">
<img src="https://images.unsplash.com/photo-1603221580671-2d3aa6824923?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<div class="text-group">
<h1>Moon</h1>
<h1>Star</h1>
</div>
</div>
You have to position your position:absolute; from the top instead of the bottom. Because it will fix it from the top:
.text-group {
position: absolute;
top: 81%;
}
DEMO
* {
margin: 0;
padding: 0;
}
.container {
position: relative;
}
img {
width: 100%;
height: 300px;
object-fit: cover;
}
.text-group {
position: absolute;
top: 81%;
}
h1 {
color: green;
font-size: 5rem;
}
<div class="container">
<img src="https://images.unsplash.com/photo-1603221580671-2d3aa6824923?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<div class="text-group">
<h1>Moon</h1>
<h1>Star</h1>
</div>
</div>
Use:
top: 85%;
instead of:
bottom: 15%;
This is an easy fix
Just change the text-group class to this, changing the position to absolute, this makes the element positioned absolutely to its first positioned parent.
.text-group {
position: absolute;
top: 80%;
}
You can learn more about css positioning here, as it as been explained in full details https://medium.com/#leannezhang/difference-between-css-position-absolute-versus-relative-35f064384c6
I need the images and links that are in the footer to be at the bottom of the footer, and the footer needs to still be at the bottom of the page.
I have tried using position: absolute and bottom properties and played with the margin properties but nothing I do seems to work any help would be much appreciated here.
body {
padding: 0;
margin: 0;
}
.headerBackgroundImage {
/* The image used */
background-image: url("../Images/headerImage.jpg");
min-height: 318px;
/* Center the image */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/* Needed to position the navbar */
position: relative;
}
/* Code that applies only to the logo to position it and make sure it is infront of the background */
#logo {
position: relative;
display: block;
margin-left: 850px;
width: 15%;
top: 20px;
}
/* Position the navigation bar container inside the image */
.container1 {
position: absolute;
bottom: 0px;
}
/* Another container for the second part of the navigation bar */
.container2 {
position: absolute;
bottom: 0px;
right: 0;
}
/* The navigation bar */
.topnav {
overflow: hidden;
}
/* The links/words in the navigation bar */
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: underline;
font-size: 50px;
font-weight: bold;
}
/* What happens to the links/words in the navigation bar once it is hovered over */
.topnav a:hover {
text-decoration: none;
}
.ImageColumn {
float: right;
width: 780px;
}
#ImageColumnImages {
width: 100%;
height: 40%;
padding-bottom: 10px;
}
footer {
left: 0;
bottom: 0;
height: 318px;
width: 100%;
overflow: hidden;
position: static;
}
.footerBackgroundImage {
/* The image used */
background-image: url("../Images/FooterImage.png");
min-height: 318px;
/* Center the image */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/* Needed to position the navbar */
position: relative;
}
#footerImages {
height: 100px;
width: 100px;
padding-bottom: 10px;
position: sticky;
bottom: 0;
}
.footerLinks a {
color: #f2f2f2;
font-size: 20px;
padding-right: 10px;
text-decoration: underline;
font-weight: bold;
}
.footerLinks a:hover {
text-decoration: none;
}
.test {
bottom: 0px;
}
<body>
<div class="headerBackgroundImage">
<img src="../Images/logo.png" id="logo">
<div class="container1">
<div class="topnav">
Attractions
Restaurants
</div>
</div>
<div class="container2">
<div class="topnav">
Hotels
Transport
</div>
</div>
</div>
<div class="ImageColumn">
<img src="../Images/indexImage1.png" id="ImageColumnImages">
<img src="../Images/indexImage2.png" id="ImageColumnImages">
<img src="../Images/indexImage3.png" id="ImageColumnImages">
<img src="../Images/indexImage4.png" id="ImageColumnImages">
</div>
<footer>
<div class="test">
<div class="footerBackgroundImage">
<img src="../Images/facebook.png" id="footerImages">
<img src="../Images/instagram.png" id="footerImages">
<img src="../Images/twitter.png" id="footerImages">
<div class="footerLinks">
Contact Us
Refrences
</div>
</div>
</div>
</footer>
</body>
Using display: flex on the footer makes this work. By aligning the content with flex-end it positions itself on the bottom of the page.
Learning grids and flex boxes really makes life easier.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
footer {
/*Added display flex and align-items*/
display: flex;
align-items: flex-end;
height: 318px;
width: 100%;
overflow: hidden;
position: static;
}
.test {
/*Set the div test to 100%*/
width: 100%;
}
.footerBackgroundImage {
...
/*added background color for testing purposes */
background-color: #e3e3e3;
}
body {
padding: 0;
margin: 0;
}
.headerBackgroundImage {
/* The image used */
background-image: url("../Images/headerImage.jpg");
min-height: 318px;
/* Center the image */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/* Needed to position the navbar */
position: relative;
}
/* Code that applies only to the logo to position it and make sure it is infront of the background */
#logo {
position: relative;
display: block;
margin-left: 850px;
width: 15%;
top: 20px;
}
/* Position the navigation bar container inside the image */
.container1 {
position: absolute;
bottom: 0px;
}
/* Another container for the second part of the navigation bar */
.container2 {
position: absolute;
bottom: 0px;
right: 0;
}
/* The navigation bar */
.topnav {
overflow: hidden;
}
/* The links/words in the navigation bar */
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: underline;
font-size: 50px;
font-weight: bold;
}
/* What happens to the links/words in the navigation bar once it is hovered over */
.topnav a:hover {
text-decoration: none;
}
.ImageColumn {
float: right;
width: 780px;
}
#ImageColumnImages {
width: 100%;
height: 40%;
padding-bottom: 10px;
}
footer {
display: flex;
height: 318px;
width: 100%;
overflow: hidden;
position: static;
align-items: flex-end;
}
.test {
width: 100%;
}
.footerBackgroundImage {
/* The image used */
background-image: url("../Images/FooterImage.png");
/* Center the image */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/* Needed to position the navbar */
background-color: #e3e3e3;
width: 100%;
}
.footerImages {
height: 100px;
width: 100px;
padding-bottom: 10px;
}
.footerLinks a {
color: #f2f2f2;
font-size: 20px;
padding-right: 10px;
text-decoration: underline;
font-weight: bold;
}
.footerLinks a:hover {
text-decoration: none;
}
.test {
bottom: 0px;
}
<body>
<div class="headerBackgroundImage">
<img src="../Images/logo.png" id="logo">
<div class="container1">
<div class="topnav">
Attractions
Restaurants
</div>
</div>
<div class="container2">
<div class="topnav">
Hotels
Transport
</div>
</div>
</div>
<div class="ImageColumn">
<img src="../Images/indexImage1.png" id="ImageColumnImages">
<img src="../Images/indexImage2.png" id="ImageColumnImages">
<img src="../Images/indexImage3.png" id="ImageColumnImages">
<img src="../Images/indexImage4.png" id="ImageColumnImages">
</div>
<footer>
<div class="test">
<div class="footerBackgroundImage">
<img src="../Images/facebook.png" class="footerImages">
<img src="../Images/instagram.png" class="footerImages">
<img src="../Images/twitter.png" class="footerImages">
<div class="footerLinks">
Contact Us
Refrences
</div>
</div>
</div>
</footer>
</body>
Set the footer to have margin: 100%;. That should put it to the bottom.
I have tried giving the panel a z-index of 1000,
and positioning it as absolute, and the hero image as relative.
But the panel is still not moving to the front.
`
<!--hero-->
<section class="hero">
<section class="container">
<h1>TITLE</h1>
subtitle lorem ipsum
<br><br>
<button type="button" class="btn btn-default"><a href="sobre.php"><b>saiba mais<b></button>
</section>
</section>
<!--hero-->
<!-- painel de foreground----->
<div class="overlay">
<h3>about us something something<h3>
</div>
<!-- painel de foreground---->`
CSS:
`
.overlay{
width:60%;
position:absolute;
left:0;
z-index: 1000;
background-color:#fff;
border:1px solid #fff;
width:300px;
height:120px;
padding-left:30%;
}
.hero {
width: 100%;
background: url("../img/hero/2.png"); no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
display: table;
position:relative;
z-index:-1;
}
.hero .container {
display: table-cell;
text-align: center;
vertical-align: middle;
height: 689px;
}
`
Like so:
https://cdn.elegantthemes.com/blog/wp-content/uploads/2016/07/material-overlap-divi-contact-form.png
I have just made an demo.. You just have to give position relative to that element and move it with to or bottom with some z-index.Hope this will help.
html,
body {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
.container {
max-width: 80%: width:100%;
margin: 0px auto;
}
.simpleText {
width: 48%;
margin: 20px 2% 20px 0;
padding: 20px 0;
text-align: left;
float: left;
}
/* Positioned Element */
.panelPosition {
width: 48%;
margin: 20px 0% 20px 2%;
padding: 10px 0;
background: green;
text-align: center;
display: inline-block;
float: left;
height: 200px;
position: relative;
bottom: -80px;
z-index: 2;
}
footer {
width: 100%;
padding: 100px 0;
background: red;
text-align: center;
float: left;
position: relative;
z-index: 1;
}
<div class="container">
<section>
<div class="simpleText">
<h3>Hello Demo !!</h3>
</div>
<div class="panelPosition"> Positioned Element</div>
</section>
</div>
<footer>
I am footer
</footer>
all you need is here: www.w3schools.com If you still need help, you need to show us what you did so far...
img {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
I am new to this so please excuse me.
I am working on my first website coding and, I am having so much difficulties with centering my button. I want to place the button on the middle of the window.
I will attach the code below:
/* Hide Scroll */
html, body {
overflow:hidden;
}
/* Home Page - Background Image */
body {
background: url(Image-2.jpg);
background-repeat: no-repeat;
background-size: cover;
position: relative;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
}
/* Mains */
#Mains-Logo {
margin-top: 42px;
margin-left: 80px;
}
#Mains-Basket {
float: right;
margin-top: 48px;
margin-right: 96px;
}
#Mains-SP {
text-align: center;
margin-top: 785px;
margin-left:810px;
}
/* Button */
.Button-SN {
text-align: center;
min-height: 100%;
min-width: auto;
}
.SN {
border: 5px solid #fcfcfc;
padding: 8px 25px;
margin: auto;
}
<body>
<img id="Mains-Logo" src="Logo.png">
<img id="Mains-Basket" src="Basket.png">
<!-- THIS RIGHT HERE -->
<div class="Button-SN">
<a class="SN" href="#">SHOP NOW</a>
</div>
<!-- END -->
</body>
<footer>
<img id="Mains-SP" src="SP.png">
</footer>
This question has already been answered in stack overflow, here are some useful links to solve your problem.
align text in middle/center of page and button on bottom/center
How to center a button within a div?
trying to align html button at the center of the my page
How to center html element in browser window?
Remove the wrapper .Button-SN.
Add:
.SN{
position:absolute;
display: inline-block;
top:50%;
left:50%;
width:150px;
border: 5px solid #fcfcfc;
line-height: 40px;
margin-top:-20px;
margin-left:-75px;
}
Use clear:both to clear floated direction.
.Button-SN {
clear: both;
min-height: 100%;
min-width: auto;
text-align: center;
}
Try adding this to your button CSS:
display: flex;
justify-content: center; /*centers items on the line (the x-axis by default)*/
align-items: center; /*centers items on the cross-axis (y by default)*/
position:absolute;
Let me know how you get on!
Thanks
Method #01:
Wrap both images in a div and set layout of parent with overflow: hidden.
/* Hide Scroll */
html, body {
overflow:hidden;
}
/* Home Page - Background Image */
body {
background: url(Image-2.jpg);
background-repeat: no-repeat;
background-size: cover;
position: relative;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
}
/* Mains */
.image-holder {
overflow: hidden;
}
#Mains-Logo {
margin-top: 42px;
margin-left: 80px;
}
#Mains-Basket {
float: right;
margin-top: 48px;
margin-right: 96px;
}
#Mains-SP {
text-align: center;
margin-top: 785px;
margin-left:810px;
}
/* Button */
.Button-SN {
text-align: center;
min-height: 100%;
min-width: auto;
}
.SN {
border: 5px solid #fcfcfc;
display: inline-block;
vertical-align: top;
padding: 8px 25px;
margin: auto;
}
<body>
<div class="image-holder">
<img id="Mains-Logo" src="Logo.png">
<img id="Mains-Basket" src="Basket.png">
</div>
<!-- THIS RIGHT HERE -->
<div class="Button-SN">
<a class="SN" href="#">SHOP NOW</a>
</div>
<!-- END -->
</body>
<footer>
<img id="Mains-SP" src="SP.png">
</footer>
Method #02:
Add clear: both to the styles of .Button-SN.
/* Hide Scroll */
html, body {
overflow:hidden;
}
/* Home Page - Background Image */
body {
background: url(Image-2.jpg);
background-repeat: no-repeat;
background-size: cover;
position: relative;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
}
/* Mains */
#Mains-Logo {
margin-top: 42px;
margin-left: 80px;
}
#Mains-Basket {
float: right;
margin-top: 48px;
margin-right: 96px;
}
#Mains-SP {
text-align: center;
margin-top: 785px;
margin-left:810px;
}
/* Button */
.Button-SN {
text-align: center;
min-height: 100%;
min-width: auto;
clear: both;
}
.SN {
border: 5px solid #fcfcfc;
display: inline-block;
vertical-align: top;
padding: 8px 25px;
margin: auto;
}
<body>
<img id="Mains-Logo" src="Logo.png">
<img id="Mains-Basket" src="Basket.png">
<!-- THIS RIGHT HERE -->
<div class="Button-SN">
<a class="SN" href="#">SHOP NOW</a>
</div>
<!-- END -->
</body>
<footer>
<img id="Mains-SP" src="SP.png">
</footer>
Try
.Button-SN {
text-align: center;
margin: 0 auto;
}
You can try this:
vertical-align:middle;