I'm trying to set up a landing page with a hero image as the background. I'm attempting to have two columns next to each other around the center of the screen. My plan was to use the body tag in CSS to set the background-image and set position: relative so that I could later use position: absolute for the columns with text in them to be in the center of the image/screen. However, I'm using React and I used the index.js component to set it to relative and to set the background and I then added a Home component That will contain the rest of the landing page, beginning with the two columns that must be set with position absolute.
In index.js styles component
body{
background-image: url(../src/assets/HeroImage.jpg);
height: 100vh;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
position: relative;
}
In Home styles component
.heroimage-text-container{
background-color: red;
height: 100px;
position: absolute;
top: 0;
left: 0;
}
What happens by trying it this way is that the heroimage-text-container disappears when the position is set to absolute. I know this would not be happening if this was all within the same component so I'm hoping someone here could help me fix this. Thank you.
You should use flex box in this case. Absolute using the same class it will be overlapped because they will have the same properties.
body {
background-image: url("https://images.unsplash.com/photo-1506716442075-1e2e0e5b1256?ixlib=rb-1.2.1&auto=format&fit=crop&w=1343&q=80");
height: 100vh;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
position: relative;
}
.App {
font-family: sans-serif;
text-align: left;
display: flex;
flex-direction: row;
}
.heroimage-text-container {
background-color: red;
height: auto;
margin: 10px;
padding: 10px;
}
Take a look at the sandbox
https://codesandbox.io/s/bold-tdd-d39oc
Related
I am creating a website using WordPress. My client needs a similar design to be created in WordPress. In design, there are blog posts that are separated by a divider. Check the screenshot, I want to create something similar to this:
https://i.stack.imgur.com/xG4Nr.png
I am confused about how to cut a border in two halves and place an SVG in the center. Will someone guide me on how to do that? Need it done via CSS.
Class Name: .ast-separate-container .ast-article-post
I was using Astra theme! Thanks to botivegh for helping me 🤍
here is an example how to achieve this, just adjust to your own classes:
<style>
div.your-container {
width: 100%;
display: inline-block;
position: relative;
}
hr.your-hr {
display: inline-block;
width: calc(50% - 20px);
}
.your-img {
display: inline-block;
background-image: url(https://svgur.com/i/byb.svg);
width: 20px;
height: 20px;
background-size: 20px 20px;
background-position: center center;
}
</style>
<div class="your-container">
<hr class="your-hr" />
<div class="your-img"></div>
<hr class="your-hr" />
</div>
EDIT
I'm leaving the general answer above. But here is the css you need to add and it will do the trick. Everything is set that the image is 20px. If you want to change that, you need to adjust the background-size, width, height and left attributes. Hope this will help.
.ast-separate-container .ast-article-post::after{
content: "";
position: absolute;
bottom: -12px;
z-index: 10;
left: calc(50% - 10px);
background-image: url(https://svgur.com/i/byb.svg);
width: 20px;
height: 20px;
background-size: 20px 20px;
background-position: center center;
}
I have a web page which I'd like to set full screen image right when users enter the page. I don't want it to be fixed or anything. Just at the size of the window.
Now, I also have a footer which is positioned absolutely at the bottom of the web page. Here is the styles for the footer:
html {
height: 100%;
box-sizing: border-box;
}
body {
position: relative;
margin: 0;
min-height: 100%;
padding-bottom: 80px;
color: white;
background: white;
font-family: "Quicksand";
fill: currentColor;
}
/* Footer Section */
footer {
display: flex;
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 80px;
align-items: center;
justify-content: center;
background-color: $accent-color;
color: #fff;
}
Now, when I try to set my full screen image like this:
.fullscreen-bg {
height: 100%;
background-image: url("/assets/images/scorpion.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
The image doesn't show at all, but when I change min-height: 100% to height: 100%, The image suddenly shows up, but the footer now is at the bottom of the viewport, not the page. Here is an image that will explain this perfectly:
https://i.gyazo.com/d47e2e1fcdeaf4f8f8cab8b847c00f43.png
As you can see, the footer now jumps up and resides at the bottom of the screen.
If I change this attribute back to min-height: 100%, the image doesn't show at all:
https://i.gyazo.com/b3d8b941222ac16455d220f25da8bfbf.png
How can I fix this? I want the image to be full screen but also I don't want the footer to jump up from the bottom of the page. How can I combine these 2 behaviors?
Use height: 100vh; it will cover 100% height for all screen sizes.
Here is my code:
#my_div:before
{
/* displaying the image */
content: url("img path");
/* centering the image */
display: block;
text-align: center;
/* making the image responsive */
max-width: 100%;
}
<div id="my_div"></div>
I'm trying to make the image responsive through the max-width:100% property but it is not working
My Question: Is it possible to do such a thing?
Edit
The question is not a duplicate, I want the dimensions to scale automatically on screen resize while the other question sets a fixed size to the image
Try this:
#my_div:before
{
/* displaying the image */
content: url("img path");
/* centering the image */
display: block;
text-align: center;
/* making the image responsive */
max-width: 100%;
height: auto;
}
If this doesn't work, try removing the :before pseudo-element
#my_div
{
/* displaying the image */
content: url("img path");
/* centering the image */
display: block;
text-align: center;
/* making the image responsive */
max-width: 100%;
height: auto;
}
Without seeing the context of your html, this is the best solution I can offer. We'll need more information in order to understand your situation better.
I confess I'm not entirely sure what effect you are after but I think this might be a better option for you.
Don't put the image in the content property...make that pseudo-element 100% size of the div and use a background image.
A couple of options for you.
.my_div {
position: relative;
height: 150px;
border: 1px solid grey;
width: 75%;
margin: 1em auto;
}
.my_div:before {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
content: '';
background-image: url(http://lorempixel.com/g/400/200/);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.cover:before {
background-size: contain;
}
<div class="my_div"></div>
<div class="my_div cover"></div>
JSfiddle Demo
Finally got my main parallax image to scale on mobile with background-size: 100% auto, but now there's a large empty space after the image where the div isn't scaling down to mobile size. Please help! Here's the site.
css
.bcg {
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% auto;
height: 100%;
width: 100%;
}
.hsContainer {
display: table;
table-layout: fixed;
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}
.hsContent {
max-width: 450px;
margin: -150px auto 0 auto;
display: table-cell;
vertical-align: middle;
color: #ebebeb;
padding: 0 8%;
text-align: center
}
background-attachment: fixed; does not tend to be supported by mobile browsers. In my experience it tends to cause some undesirable behaviour.
This might help: Background-attachment: fixed not working on android/mobile
In addition: I think the p tag is causing your problem. Inspecting the elements shows that the P tag is taking about 20-30px height. but has no content in it.
For some reason my header is being pushed down in firefox. It works fine in safari and chrome. I tried making the header position absolute but it sill is pushed down, when it should float up to the left corner of its parent- it doesn't. So this made me think the body was being pushed down, not the header.
so I started to investigate my background-image position on my body tag, but I have tried all kinds of combinations of positioning the image with no luck, and also
.home-body {
position: relative;
top: 0; left: 0;
}
I tried :contain instead of :cover- didn't work.
Then I though it had to do with height: auto, but no.
I have been experimenting with the homepage, although it is happening on all the pages.
here is the site:
http://lindseypod.com/v10/
my body tag:
body {
font-family: 'Roboto', sans-serif;
font-size: 15px;
line-height: 1.5;
font-weight: 100;
padding: 0;
margin: 0;
}
I have a body.home-page with a background-image with a css cover property:
.home-page {
background: url(images/home_2.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
thenI have a header tag with elements inside of it:
header {
width: 100%;
background-color: rgba(255,255,255,0.8);
}
.header-content is within header:
.header-content,
.footer-content,
.content,
.bars-content {
width: 96%;
height: auto;
margin: 0 auto;
color: rgba(255,255,255,1);
max-width: 960px;
}
Add this style:
#home-mobile{
overflow:auto;
}
The large margin-top on .home-content > h2 is the source of the problem.
One sensible way to fix it is to add overflow: hidden to .home-content.
This is probably happening in Firefox due to a bug (?) with the handling of collapsing margins.