Ensure that the svg is stretched to cover 100% of the height of

I'm struggling to get my SVG to display correctly as the background on my website. Currently, it only appears as a small snippet behind one section of the site instead of spanning the entire page. Any assistance would be greatly appreciated.

Here is a fiddle I've created for reference: https://jsfiddle.net/bp123/ku5Ln2so/7/

Path: css

.landing-background {
  position: absolute;
  top: 0;
  min-width: 100vw;
  display: flex;
  justify-content: flex-start;
  overflow: hidden;
  z-index: -1;
  height: 100%;
  box-sizing: border-box;
  background-size: 1713px auto;
  background-position: center 350px;
  background-repeat: no-repeat;
}

Path: webpage

function HomePage(props) {
  return (
    <div>
      <div className="landing-background" style={{ backgroundImage: 'url(/img/background.svg)' }} />
      <Container fluid className="mt-5 mb-5 pt-5 pb-5">
        <Row className="mx-auto ">
          <Col md={10} className="mx-auto">
            <h1>My Simple Website</h1>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ornare magna sed semper pulvinar. Nam laoreet orci pharetra nisl convallis malesuada.</p>
          </Col>
        </Row>
      </Container>

      <Container fluid className="mt-5 mb-5 pt-5 pb-5">
        <div className="mx-auto section-width">
          <img src="/img/ipad.png" className="ipad" alt="" />
          <img src="/img/mobile.png" className="iphoneX" alt="" />

          <div className="second-section-copy">
            <h2 className="mt-5">Lorem ipsum dolor</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ornare magna sed semper pulvinar. Nam laoreet orci pharetra nisl convallis malesuada. </p>
          </div>
        </div>
      </Container>
    </div>
  );
}

Answer №1

Consider using the following CSS:

.hero-image {
  background-image: url(https://r1.res.office365.com/owalanding/v2.9/images/desktop.svg);
  position: fixed;
  top: 0;
  width: 99vw;
  display: flex;
  justify-content: flex-start;
  overflow: hidden;
  z-index: -1;
  height: 100%;
  box-sizing: border-box;
  background-size: 100% auto;
  background-position: center;
  background-repeat: no-repeat;
}

I have made adjustments to the styles like

position: fixed;background-size: 100% auto;background-position: center;
to achieve the desired outcome.

Here is a functioning example for you:

.landing-background {
  background-image: url(https://r1.res.office365.com/owalanding/v2.9/images/desktop.svg);
  position: fixed;
  top: 0;
  width: 99vw;
  display: flex;
  justify-content: flex-start;
  overflow: hidden;
  z-index: -1;
  height: 100%;
  box-sizing: border-box;
  background-size: 100% auto;
  background-position: center;
  background-repeat: no-repeat;
}
<!DOCTYPE html>
<html>

<body>
  <div class="landing-background"></div>
  <h1>My First Heading</h1>
  <p>My first paragraph.</p>

</body>

</html>

I trust this information will be beneficial for your needs.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to incorporate this video into this particular frame?

Does anyone know how to insert an image with a specific shape using SVG? I have the exact shape I want in an SVG file. Do I need to use relative or absolute positioning with respect to the SVG, or are there other solutions available? <svg width="90 ...

Generate a table containing information organized by category

I am looking to create a component Table that groups countries together. Here is my mockup: enter image description here I am struggling to find a solution for this issue. Can someone please assist me? ...

Is Your Website Optimized for All Devices?

Creating this website was just a little project for me. I've been experimenting with different methods to ensure it's compatible with all devices and fits perfectly on each screen. Unfortunately, I'm pretty clueless when it comes to @media ...

CSS auto width not applied to images causing a lack of scaling

I recently added this code to my webpage: image { margin: 0 2px 0 0; height: 100px; width: auto !important; overflow: hidden; text-align: center; } The goal was to scale all images to a maximum height of 100px and have the browser adj ...

Release a stationary element upon scrolling down the page

I have a calculator feature on my website which was coded in php. At the end of this calculator, there is a section that displays the results. While the results div works properly on desktop, I am looking to implement a fix for mobile devices. Specificall ...

Tips for aligning a dropdown button with the other elements in your navbar

I followed the code outline from a tutorial on We3schools, but I'm having an issue with the button not aligning correctly with the navbar. https://i.sstatic.net/fSRIT.png I attempted to adjust the code for proper alignment before publishing, but was ...

What are some tips for keeping design proportions consistent on mobile apps?

Hey there, I have a question that may seem basic to some, but as a newbie in coding, I appreciate your patience. I've been working on an Ionic app and I'm struggling with maintaining CSS proportions of HTML elements. For instance, here's th ...

Moving SVG fill in a continuous loop

After encountering a strange issue not too long ago, I decided to continue my CSS animation experiments with SVG, specifically focusing on colorization. Initially, I thought that applying the animation rules directly to the <g> tag grouping all the ...

The animation will only activate upon the initial click of the button

I'm looking to add a simple text animation to my website. The idea is that when a button is clicked, the text transitions from being fully transparent to fully visible, and then back to transparent. I've written some code to achieve this animatio ...

How to Align an Icon to the Right in a Bootstrap 4 Modal Title

I'm attempting to position two icons next to the close button within a Bootstrap 4 modal. Unfortunately, I am struggling to remove some unwanted margin-left that persists despite my best efforts. While inspecting the element, I was successful in achie ...

If a box in the grid contains a certain class, then JavaScript should be

I've set up a grid featuring a player, represented by a yellow box, along with obstacles denoted by black boxes marked with the .ob class. I want to prevent the player from moving into these obstacle squares when the 'UP' button is clicked. ...

Cannot see the toggler button in Bootstrap 4 Navbar

I recently implemented the toggler button (hamburger icon) code in my HTML, but I'm facing an issue where the hamburger icon doesn't appear and looks blank when I resize my screen or view it on a smaller viewport. Here's the snippet of my H ...

Bootstrap 4 radio buttons are not aligning properly with the padding

There seems to be an issue with the alignment of Bootstrap 4 custom radio buttons and my left padding. Here is a snippet: https://i.sstatic.net/vWTNo.png This is part of the code for displaying an item <div class="p-4"> <ul class="d-flex ...

Internet Explorer fails to accurately determine the height of a textarea based on the line-height

I need to adjust the display of a textarea to show 4 rows with a line height set to 200%. Take a look at the HTML code: <textarea rows="4" cols="50"> 1 2 3 4</textarea> and the accompanying CSS: textarea { line-height: 2; } It appears ...

Tablist with interactive Bootstrap navigation on both the left and right sides

How can I create interactive navigation tabs with two tabs aligned to the left ("First" and "Second") and one tab aligned to the right ("More")? Currently, I can switch between "First" and "Second" without any issues. However, once I select "More," I can s ...

Content contained within a rectangular box, adorned with ellipsis marks and centered alignment

My containers contain dynamic content with multiple lines of text. I want to display ellipsis (...) when the text exceeds the container size. Additionally, I aim to vertically align the text in the middle. I have set up a Codepen http://codepen.io/anon/pe ...

Adjust the size of a div container depending on the content it holds

If the element div.PageheaderDescription does not contain any img or div#cat-text, I'd like the height to be set to 0px to eliminate any white space. Below is my CSS code: .PageHeaderDescription { height: 320px; position: relative; width ...

Differentiate input elements with custom styling

I'm experiencing an issue while trying to style a specific form field in Angular 7. The style doesn't seem to be applying properly. Below is my form structure: <ul> <li> <mat-form-field *ngIf="number"> <input ma ...

Tips for incorporating a Font Awesome icon <i> within a select dropdown and customizing its appearance

I am facing an issue while trying to insert an icon into a select option. The error message I received is: Warning: validateDOMNesting(...): cannot appear as a child of <option> To indicate that certain fields are required, I am using asterisk ic ...

Iframe overlay feature functioning on Chrome but not on IE11

I have a Document viewer with a .less file containing the following styling: div.document-previewer-container { //height: 400px; //width: 300px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; //padding: 5px 2px; > div.document-preview { h ...