<style>
.parallax {
background-image: url("Cpage.png");
min-height: 700px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.box{
position: absolute;
top: 600px;
left: 300px;
width: 900px;
height:600px;
background-color:rgb(0, 32, 45);
font-size:36px;
border-radius: 50%;
}
.cap img{
position: relative;
height:130px;
width:170;
left: 340px;
}
</style>
<div class="parallax">
<div class="box" >
<div class="cap"><img src="Capture.png"/></div>
<p style="color: white;text-align: center;">
LEARNING TOWARDS BETTER FUTURE!<br>
</p>
</div>
</div>
The problem is that when I switch screens. When I go from 15 inch screen to 13 inch screen the div moves. It is not in middle of screen anymore. May be it is because of the "left:" It really gets messy when screen is smaller then that. How can I fix it ?
You can use Flex to help you center it:
.parallax {
display: flex;
align-items: center; // vertical centering
justify-content: center; // horizontal centering
background-image: url("Cpage.png");
min-height: 700px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
And remove top/left attributes from .box.
Fiddle
.box{
width: 400px;
height:400px;
background-color:rgb(0, 32, 45);
font-size:36px;
border-radius: 50%;
display: block;
margin: 0 auto;
}
Related
So I'm more of a backend than a frontend dev,
I'm having some difficulty on css.
<div className="--Hero">
<div className="--Hero-container-text">
<h1>this is me</h1>
<p>hello</p>
note: className is because of react.
I want the text to stay relative to the background image on hero-container-text as seen below.
another example showing a different viewport.
Here's the css.
.--Hero {
width: 100%;
height: 90vh;
background-image: url("./images/homepage/manpass.svg");
background-size: contain;
background-position: bottom;
background-repeat: no-repeat;
display: flex;
justify-content: center;
align-items: center;
}
.--Hero-container-text {
position: fixed;
left: 60%;
top: 40%;
padding: 0 60px;
}
You should add position:relative; to your --hero and position:absolute; to your
--Hero-container-text
you set the div you want to technicaly be your canvas with a position: relative;
Avoid using percenteges for the positioning since they will most likely break ,instead use left 0 right 0 with auto margin , the code will look something like this :
.--Hero {
width: 100%;
height: 90vh;
background-image: url("./images/homepage/manpass.svg");
background-size: contain;
background-position: bottom;
background-repeat: no-repeat;
display: flex;
justify-content: center;
align-items: center;
position:relative;
}
.--Hero-container-text {
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
i´m building a website that has different background images as you scroll down.
The problem I am facing is that each background image is not fitting the screen (in terms of the height). My images won't fit the whole screen unless I set them to have 1100px and therefore will not be fitting the 100% of my height, but let's say they will be going down, on those 20% who are going to come as I scroll down.
I would like to have my images fit 100% of the screens height, without being cut
and going bellow the page.
.container {
background-size: 100%;
background-size: cover;
margin-top: 1vh;
}
.parallax {
background: url("quem-somos.png") ;
background-size: cover;
width: 100%;
height: 100%;
}
.parallax2{
background: url("servicos.png") no-repeat center;
background-size: cover;
height: 1100px;
width: 100%;
background-attachment: scroll;
}
.parallax3{
background: url("depoimentos.png") no-repeat center;
background-size: cover;
height: 1100px;
width: 100%;
background-attachment: scroll;
}
.parallax4{
background: url("comecando.png") no-repeat center;
background-size: cover;
height: 1100px;
width: 100%;
background-attachment: scroll;
}
.parallax5{
background: url("sac.png") no-repeat center;
background-size: cover;
height: 1000px;
background-attachment: scroll;;
width: 100%;
}
.parallax6{
background: url("onde-atuamos.png") no-repeat center;
background-size: cover;
background-attachment: scroll;
height: 1000px;
width: 100%;
}
I have put all of the images inside the container
<div class="container">
<div class="parallax" id="about">
</div>
<div class="parallax6" id="operations">
</div>
<div class="parallax2" id="servicos">
</div>
<div class="parallax3" id="Depoimentos">
</div>
<div class="parallax4" id="Comecando">
</div>
<div class="parallax5" id="sac">
</div>
</div>
You can use this to set the div height to the screen height, you have to make sure html and body have a min height of the screen and also set the background-size: cover
Also .image1 .image2 in my case are direct children of the body element in my example
html, body {
margin: 0;
width: 100%;
min-height: 100vh;
}
.image1 {
width: 100%;
height: 100vh;
background-color: red;
}
.image2 {
width: 100%;
height: 100vh;
background-color: blue;
}
You can have the child divs do the heavy lifting by setting heights to 100vh - the margin on top of the container.
https://jsfiddle.net/x2h0mat7/
Here's a working example with the original html:
<div class="container">
<div class="parallax" id="about">
</div>
<div class="parallax6" id="operations">
</div>
<div class="parallax2" id="servicos">
</div>
<div class="parallax3" id="Depoimentos">
</div>
<div class="parallax4" id="Comecando">
</div>
<div class="parallax5" id="sac">
</div>
</div>
and the css:
.container {
margin-top: 1vh;
}
.container>div {
min-height: calc(100vh - 1vh);
height: 100%;
width: 100%;
background-size: cover;
background-repeat: no-repeat;
z-index: 2;
display: flex;
overflow: hidden;
background-attachment: scroll;
}
.parallax {
background: url("https://via.placeholder.com/1600x1200/0000FF/");
}
.parallax2 {
background: url("https://via.placeholder.com/1600x1200/990000/") no-repeat center;
}
.parallax3 {
background: url("https://via.placeholder.com/1600x1200/ffee66/") no-repeat center;
}
.parallax4 {
background: url("https://via.placeholder.com/1600x1200/66eeff/") no-repeat center;
}
.parallax5 {
background: url("https://via.placeholder.com/1600x1200/ee66ff/") no-repeat center;
}
.parallax6 {
background: url("https://via.placeholder.com/1600x1200/ffee66/");
}
How do I set a fixed size of a background image?
I set the width and height right now but when I increase or decrease my browser window image gets blocked. How can Ifix that?
Image will be blocked slowly when I decreased window size:
Here is my code :-
.bg{
height: 600px;
width: 100%;
border-bottom-left-radius: 80%;
border-bottom-right-radius: 80%;
background-image: url("/assets/images/interview.jpg");
background-size: cover;
display: flex;
justify-content: center;
}
A couple of new lines. Added comments on them.
.bg{
height: 600px;
width: 100%;
border-bottom-left-radius: 80%; /*I'd remove this and edit the original photo*/
border-bottom-right-radius: 80%; /*I'd remove this and edit the original photo*/
background-image: url("https://i.pinimg.com/originals/3b/8a/d2/3b8ad2c7b1be2caf24321c852103598a.jpg");
background-size: contain; /*From cover to contain*/
background-position: top !important; /*New - Can change to center*/
background-repeat: no-repeat !important; /*New*/
display: flex;
justify-content: center;
}
<div class="bg">
</div>
You need to set the position of you bg component to fixed
You new CSS class will look like this:
.bg{
height: 600px;
width: 100%;
border-bottom-left-radius: 80%;
border-bottom-right-radius: 80%;
background-image: url("/assets/images/interview.jpg");
background-size: cover;
display: flex;
justify-content: center;
//modifications
background-repeat: no-repeat;
position:'fixed';
top:0;
left:0;
}
I am trying to adjust my logo at the center of the webpage, but whenever I adjust it in my CSS file, the background is getting affected by the changes so there will be white spaces on top.
.bgimage {
width: 1903px;
height: 1000px;
background-image: url(https://drive.google.com/uc?id=1ZtitWTmH3qglyS7uv4X32GDQv35fmhwG);
background-attachment: fixed;
background-size: cover;
margin-top: 60px;
display: block;
}
.bgimage .ETLOGO {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 80px;
width: 40%;
height: 50%
}
<div class="bgimage">
<img src="https://drive.google.com/uc?id=1vXkFqCQzC7sagYCBOuAwDQMf-uhJTmAo" class="ETLOGO">
</div>
Here is a photo of my website.
I think what you wanted was padding at the top of the logo, instead of margin. Try this:
.bgimage {
background-attachment: fixed;
background-image: url(https://upload.wikimedia.org/wikipedia/commons/0/0f/MOS6581_chtaube061229.jpg);
background-position: center;
background-size: cover;
height: calc(100vh - 50px);
width: 100vw;
}
.bgimage .ETLOGO {
display: block;
height: 50%;
margin: 0 auto;
padding-top: 40px;
}
<div class="bgimage">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Intel-logo.svg/440px-Intel-logo.svg.png" class="ETLOGO">
</div>
I have a problem with my website. The picture looks great on the desktop but on my phone it looks terrible because its zoomed in.
How can I solve this?
It don´t work with
background-size:cover;
The div with the background have two classes
.content{
color: white;
font-family: "Another Typewriter";
width:100%; height:1000px;
font-size: 300%;
padding-left: 15%;
padding-right: 15%;
padding-top: 10%;
text-align: center;
background-size: cover;
}
.parallax{
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
#xyz{background-image: url(URLtoimage);}
Div Container:
<div id="xyz" class="parallax content">
<legend class="text-center content-headline">XYZ</legend>
Some text
</div>
How I've assumed you're using background-attachment: fixed; , it can't work on many mobile browser you must use media query to change it on scroll for little screen.
.parallax{
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
#media screen and (max-width: 600px) {
.parallax {
background-attachment: scroll;
}
}
Maybe you could change it to background-size: contain when the screen width is smaller than 767px
use background-size:100% 100%; Check the snippet view.
body{
margin:0;
}
.bg-img {
background: url('http://www.planwallpaper.com/static/images/6942095-abstract-background-wallpaper.jpg') no-repeat center;
background-size: 100% 100%;
min-height: 100vh;
width: 100%;
}
<div class="bg-img">
</div>