Is it possible to forcibly align the entire page to the center or eliminate the right margin?

We appreciate you taking the time to read this post in advance.

Below is a link to the reproduction:

Purpose: The goal here is to center the div.home-text (blue area) and eliminate the margin-right to prevent visitors from inadvertently scrolling to empty space on the right.

Issue: While this works seamlessly on desktop and larger screens, I couldn't figure out why I am unable to center the page area and remove the margin-right with no value. (Refer to the image below)

https://i.sstatic.net/44rXR.jpg

This issue only occurs on a specific page, Home. I suspect that this might be related to the 'react-pdf' hook I used... but adjusting the margin-left or removing the margin-right with no value did not resolve the problem.

Could it be an incorrect media query setup...? What steps should I take?

// Home.js

import React from "react";
import "./Home.css";

// pdf
import { Document, Page } from "react-pdf/dist/esm/entry.webpack5";

import HomePDF from "../../pdf/resume.pdf";

function Home() {
  return (
    <>
      <div className="home-wrapper">
        {/* layer very back */}
        <div className="home-content">
          <div className="home-text">
            {/* profile picture, box */}
            <img
              className="profile"
              src={require("../../images/me-photo.jpg")}
            />
            <hr />
            {/* pdf */}
            <div className="pdf">
              <Document file={HomePDF}>
                <Page scale={1.5} pageNumber={1} />
                {/* <Page size="A4" style={styles.page} /> */}
              </Document>
            </div>
            <hr />
          </div>
        </div>
      </div>
    </>
  );
}

export default Home;


// Home.css
.home-wrapper {
    /* width: 100%;
    margin: 0 auto;
    height: 100%;
    display: block;
    text-align: center; */

    /* width: 100%;
    height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center; */

    width: 100%;
    align-items: center;
}

.home-content {
    margin: 0 auto;
    width: auto;
    height: auto;
    display: block;
    text-align: center;
}

.profile {
    border-radius: 20%;
    height: auto;
    width: 280px;
    /* insurance */
    margin-right:auto;
    margin-left: auto;
    margin-top: 1rem; 
    margin-bottom: 1rem;
}

.home-text {
    width: auto;
    height: auto;
    margin: 0;
}



.react-pdf__Page__canvas {
    margin-right: auto;
    margin-left: auto;
    margin-top: 1rem;

}

.react-pdf__Page__canvas {
    width: 600px;
    height: 800px;
}

@media only screen and (max-width: 600px) {
    .home-wrapper {
        width: 100%;
    }

    .home-text {
        max-width: 400px;

    }

    .pdf {
        max-width: 300px;
    }

    .react-pdf__Page__canvas {
        max-width: 390px;
        max-height: 550px;
    }
}

Answer №1

It appears that the issue lies in maxing out the width of containers instead of focusing on the size of the pdf itself.

Here is a revised solution:

@media only screen and (max-width: 600px) {
    .react-pdf__Page__canvas {
        max-width: 390px;
        max-height: 550px;
    }
}

This adjustment seemed to yield positive results.

Additionally, consider using a percentage of the viewport for margin consistency across different screen widths. For example, max-width:90vw will ensure the pdf occupies 90% of the screen's width.

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

Sometimes the last column might not be visible in an HTML table within a collapsed Bootstrap element while using Chrome browser

I've encountered a strange issue when trying to wrap an HTML table inside a collapsing div element using Bootstrap. The last column is not consistently displayed in Chrome (44.0.2403.107 m) depending on the window width, but it works fine in Firefox. ...

Creating dynamic routes with Map in ReactJS: a beginner's guide

In the sample code below, I have added a column to the children property that includes my component. I am attempting to pass this to my Route element using map in order to dynamically populate the React Route. navLink.js export const navLinks = [ { ...

Is it possible to alter the color of the text "midway" within a character on a website?

In some desktop applications, I've noticed a cool feature where the color of text changes as the background evolves. This allows for multiple colors on a single character, which is especially useful when displaying progress bars with percentages insid ...

Tips for integrating HTML content within links when using the wp_nav_menu function

Is there a way to add custom bullet points before each link in the navigation menu, except for the first one? Can I modify the wp_nav_menu(); loop to achieve this? This is the current navigation code: <?php wp_nav_menu( array( 'theme_location&apo ...

Is there a way I can twirl or tilt this ribbon text to enhance its readability?

I only want to rotate or flip the text on a ribbon box, not the entire box itself. If you try to rotate the box directly, it may disrupt the string animation. (function(){ var STATE_CLOSED = 0, STATE_DETACHED = 1, STATE_OPENED = 2, TAG_HEIGHT = 30, TA ...

Tips for successfully passing two parameters on the eventHandler of Material-UI Toggle

When looking at the documentation for the Material-UI Toggle component, it mentions the following: http://www.material-ui.com/#/components/toggle onToggle - Callback function that is fired when the toggle switch is toggled. Signature: function(event: ob ...

Reports of missing packages in the React Starter Kit have caused confusion among users

While I may be new to React/JS, I have a wide range of experience in different technologies, including some work with Angular/JS. Therefore, my encounter with the Node/JS ecosystem is not completely fresh. The journey began when I encountered a missing pe ...

Employ the power of AJAX to selectively display or conceal a specific group of images

Have you ever thought about showcasing a large number of images on a non-CMS website? Say you have 50 images that can't all be displayed at once. One idea is to display the first 15, then allow users to click "Next" to reveal the next batch of 15, and ...

Do not engage with the website while animations are running

I'm working on a JavaScript project where I want to create textareas that grow and center in the window when clicked, and shrink back down when not focused. However, I ran into some issues with the .animate() function that are causing bugs. During QA ...

Resolve issue with header in scrollable material-ui popover

Material-UI allows for a fixed header and footer in a Dialog with long, scrolling content. I am looking to achieve the same effect but within a popover. For example: <Popover> <Header>Fixed header</Header> <Content>long long ...

Enable scrolling feature for the table

I have integrated a bootstrap table into my React application, but I am facing an issue where the table is not scrollable. Whenever new content is loaded, it increases the height of the table instead of making it scrollable. Below is the code for my table ...

Employing XPATH to locate specific text content enclosed within one div and nested within another div

<?xml version="1.0" encoding="UTF-8"?> <div id="app" class="grid bg-local font-body justify-center" style="background-image: url(&quot;/img/picture.jpg&quot;);"> <div data-v-f7g8b ...

Error encountered during GitHub action for building and deploying to Firebase

Every time I push to my GitHub repo, I encounter this error. The build works fine on my machine, but when using actions, I keep running into a memory issue. I've successfully used this on other repos before and it worked perfectly, so I'm stumpe ...

Add to the current values of the REACT Form template property

I am new to working with REACT and I have been exploring whether it is possible to append a REACT Form control property value in order to enhance its functionality. To streamline the validation process, I have created a validation template that leverages ...

How can I use material-ui to perfectly align a form in the center?

I've been diving into learning Material-UI and decided to create a "form" based on their documentation. However, I found myself struggling with the flow of the documentation and ended up unsure if I used the correct tags to create the form : ...

Navigating through a HTML email Listserv with a click event scrolling feature

I am looking to create an interactive HTML email with a link that can scroll the recipient's browser to a specific section within the email. I am considering using Javascript and jQuery for this functionality. Can someone guide me on how to implement ...

What is the approach for incorporating JavaScript variables in Jade templates for writing inline CSS styles?

Struggling to inject CSS code dynamically? You're not alone. style(type='text/css') #header a#logo { background:url(constants.logo) no-repeat; } @media only screen and (-webkit-min-device-pixel-ratio: 1.5) { #header a#logo { ...

Troubleshooting window.print alignment problems with Javascript

Whenever I use window.print in my JavaScript code to print a specific div, I encounter alignment issues on the printed page. Below is the snippet of code that I am using for printing along with links to images showing the output and the layout after print ...

A guide on adjusting the header column width in React Bootstrap-Table-Next to match the data cell dimensions in real-time

https://i.sstatic.net/V6g3w.pngI'm experiencing difficulty adjusting the width of data cells in accordance with their corresponding header column widths. Here is the code snippet I am using to set the header width: columns: [ { ...

What is the best way to add custom styles to Material UI tabs in a React application?

I need help styling my material UI tabs within a react component. I am having trouble getting the styles applied correctly, specifically setting the background color and box shadow of the entire bar, as well as defining the indicator background color and u ...