为什么屏幕上的元素不是全屏?

huangapple go评论85阅读模式
英文:

Why elements on screen are not fullscreen?

问题

我没有将我的 React 网页应用程序全屏显示,因为页面上的元素数量太少。

CSS:

html {
  height: 100%;
  width: 100%;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  display: block;
  position: fixed;
  object-fit: cover;
  z-index: -2;
  right: 0;
  bottom: 0;
  background-image: linear-gradient(rgba(0, 0, 0, 0.527), rgba(0, 0, 0, 0.5)), url("./assets/background-img.png");
  background-repeat: no-repeat;
  background-position: center top;
  background-position-y: -24em;
  background-size: 100% 100%;
}

JSX:

return (
  <>
    <Navbar />
    <div className='header-div'>
      <h3 className='text-above'>
        -------   A HIKING GUIDE
      </h3>
      <div className='main-text'>
        Be Prepared For The Mountains And Beyond!
      </div>
    </div>
  </>
);

我尝试过的一切都在代码中,但我无法解决问题。希望能得到你的帮助。

英文:

I don't have my web-app on react full-screen, having so small amount of elements on the page.
为什么屏幕上的元素不是全屏?
为什么屏幕上的元素不是全屏?
为什么屏幕上的元素不是全屏?
Css:

html {
  height: 100%; width: 100%;
}
* {
  margin: 0; padding: 0; box-sizing: border-box;
}

body {
  min-height: 100vh;
  display:block;
  position: fixed;
  object-fit: cover;  
  z-index: -2;
  right: 0;
  bottom: 0;
  background-image: linear-gradient(rgba(0, 0, 0, 0.527),rgba(0, 0, 0, 0.5)), url(&quot;./assets/background-img.png&quot;);
  background-repeat: no-repeat;
  background-position: center top;
  background-position-y: -24em;
  background-size: 100% 100%;
}

Also have some other styles for h-s, etc, but I suppose it's not the cause of the problem, so I removed is.
JSX:

  return (
    &lt;&gt;
      &lt;Navbar /&gt;
      &lt;div className=&#39;header-div&#39;&gt;
        &lt;h3 className=&#39;text-above&#39;&gt;
          -------   A HIKING GUIDE
        &lt;/h3&gt;
        &lt;div className=&#39;main-text&#39;&gt;
          Be Prepared For The Mountains And Beyond!
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/&gt;
  );

Everything i tried is in the code, and i can't figure it out. Hope on your help

答案1

得分: 0

这是你的背景定位,我已经将其注释掉。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body,html {
        height: 100%; 
        width: 100%;
        display:block;
        position: fixed;
        object-fit: cover;  
        z-index: -2;
        right: 0;
        bottom: 0;
        /* background-image: linear-gradient(rgba(0, 0, 0, 0.527),rgba(0, 0, 0, 0.5)), url("./assets/background-img.png"); */
        background-repeat: no-repeat;
        /* background-position: center top; */
        /* background-position-y: -24em; */
        background-size: 100% 100%;
                }
        * {
        margin: 0; padding: 0; box-sizing: border-box;
        }

    </style>
</head>
<body>
    
</body>
</html>
英文:

It's your background positioning, I commented it out.

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;title&gt;Document&lt;/title&gt;
    &lt;style&gt;
        body,html {
        height: 100%; 
        width: 100%;
        display:block;
        position: fixed;
        object-fit: cover;  
        z-index: -2;
        right: 0;
        bottom: 0;
        background-image: linear-gradient(rgba(0, 0, 0, 0.527),rgba(0, 0, 0, 0.5)), url(&quot;./assets/background-img.png&quot;);
        background-repeat: no-repeat;
        background-position: center top;
        /*background-position-y: -24em;*/
        background-size: 100% 100%;
                }
        * {
        margin: 0; padding: 0; box-sizing: border-box;
        }

    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    
&lt;/body&gt;
&lt;/html&gt;

huangapple
  • 本文由 发表于 2023年7月12日 21:43:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定