简体   繁体   English

如何在一页上使用vh和vw CSS没有滚动响应式网页?

[英]How do I use vh and vw CSS for one page no scroll responsive web pages?

I have a webpage in which I am trying to make no scroll but fill whatever view the user has with an advertisement on the left and end and a Google Map filling most of the page. 我有一个网页,其中我试图不滚动但填写用户的任何视图左侧和末端的广告和填充页面的大部分的谷歌地图。 Currently, My CSS for the map and the advertisement block look like this: 目前,我的地图和广告块的CSS看起来像这样:

.side-col{
        width: 25%;
        float: left;
      }

      .map-col{
        width: 75%;
        float: right;
        padding-left: 20px;
      }
      @media(max-width: 991px){
        .side-col{
          width: 30%;
          float: left;
        }

        .map-col{
          width: 70%;
          float: right;
        }
      }

I did some research and did some reading on vh and vw 我做了一些研究并对vh和vw进行了一些阅读

But when I changed my code from using percentage for width to using vw and adding in a vh to fill 100% of the height it just placed my advertisement block oddly below my map block. 但是当我将代码从使用宽度百分比更改为使用vw并添加一个vh来填充100%的高度时,它只是将我的广告块奇怪地放在我的地图块之下。

You can find my whole CSS file here on the webpage. 你可以找到我的整个CSS文件在此网页上。

The end goal I am attempting is a banner ad on the left-hand side with the rest of the space filled by the google map on the desktop. 我正在尝试的最终目标是左侧的横幅广告,其余部分由桌面上的Google地图填充。 On mobile small banner ad at the bottom with the rest the google map. 在底部的移动小横幅广告与其余谷歌地图。 No scrolling on either. 也没有滚动。

Keep the % widths and use vh for for heights. 保持%宽度并使用vh表示高度。 Also use display: inline-block instead of floats, much better for layouts. 也可以使用display:inline-block而不是float,更适合布局。

 .side-col{ width: 25%; height: 100vh; vertical-align: top; display: inline-block; } .map-col{ width: 75%; height: 100vh; vertical-align: top; display: inline-block; } 

if they dont fit on the same row still then there may be some default margins around the map which are taking up extra space. 如果它们仍然不适合同一行,那么地图周围可能会有一些默认的边距占用额外的空间。 You can use the calc() function to reduce the % widths in pixel increments. 您可以使用calc()函数以像素为增量减少%宽度。

For example if you want to have padding left of 20px on the map then: 例如,如果你想在地图上留下20px的填充,那么:

width: calc(75% - 20px)

Try using display: grid; 尝试使用display: grid; in your parent element. 在您的父元素中。

.parent-element {
    display: grid;
    grid-template-columns: 30vw 1fr;
    grid-template-rows: 100vh;
    justify-items: center;
    align-items: center;
}

Make sure to use floats as little as possible. 确保尽可能少地使用floats Using grid system in css will help to make your code short and effective at the same time. css使用网格系统将有助于使您的代码同时简短有效。

Visit https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout for more css grid layout. 访问https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout以获取更多css网格布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM