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;
}
Related
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 proplem with center img in the div. I read and doing all answers in the questions about center align. And display: flex help me, but it doing my slick-slider jumping. 3 screen it seems good and next jump with no slides 1 second and next good. You can see it in my site. How can i centralize my img in the div without flex and position: absolute? Or how can I doing that without jump slider? I hope guys, you understand my English, and sorry for that simple question...
div {
display: flex!important;
justify-content: center;
align-items: center;
outline: none;
height: 100%;
max-height: 100%;
img{
width: 50%;
}
}
<div class="partners multiple-items">
<div>
<img src="img/logo-adata.png">
</div>
</div>
Do you need the img tag?
One way to achieve this is to use background-image instead of img. Simple remove the img tag, then you can center the image as
.img__wrapper {
background-image: url(img/news-img-1.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
}
Here is how it can be done with the img tag
.img__wrapper {
height: 100%;
position: relative;
}
.img__wrapper > img {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
margin: auto;
}
Try to use
display: table-cell;
vertical-align: middle;
.partners
{
width: 500px;
height: 500px;
border: 1px #aaa solid;
text-align: center;
display: table-cell;
vertical-align: middle;
}
.item{
width: 300px;
margin: auto;
}
<div class="partners multiple-items">
<div class="item">
<img src="http://via.placeholder.com/300x300">
</div>
</div>
div {
display: flex!important;
align-items: center;
outline: none;
height: 100%;
max-height: 100%;
img{
margin: 0 auto;
width: auto;
max-height: 65%;
}
}
It's solve my problem & slider don't jump
div.partners div{
height:500px;width:500px;text-align:center; vertical-align:middle;display:table-cell;
}
i have a parent container inside two sub containers are there each container have a fixed height and width in each sub containers i have a loader loader gif.
.parent-container{
display: flex;
justify-content: space-evenly;
border: 7px solid black
}
.sub-container-one{
width:400px;
height: 300px;
border: 3px solid blue;
}
.sub-container-two{
width: 300px;
height: 300px;
border: 3px solid red;
}
.loader{
display: block;
top: 0;
left: 0;
width: 50%;
height: 100%;
position: absolute;
background-image: url('http://loadinggif.com/images/image-selection/3.gif');
background-repeat: no-repeat;
background-position: center;
}
.second-loader{
margin-left:50%;
}
<div class="parent-container">
<div class="sub-container-one">
<div class="loader"></div>
</div>
<div class="sub-container-two">
<div class="loader second-loader"></div>
</div>
</div>
how can is show the same loader in both sub div at the center , i have added one more class, right now loader is showing not to the center.
when i have given
justify-content: center
it works , but how can i align the loader to the center of the both div making
justify-content: space-evenly;
Also for IE will this work ?
It Worked. Made the css for the loader as below, removed the position and made width to 100%
.loader{
display: block;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('http://loadinggif.com/images/image-selection/3.gif');
background-repeat: no-repeat;
background-position: center;
}
<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;
}