How to make background coverage a separate div?

I make a site with a side menu. 30% of the screen is the menu, and the rest is the content.

The contents of the div, I put the background image using the COVER method. I used the first example:   https://css-tricks.com/examples/FullPageBackgroundImage/css-1.php

However, this method works great when the image occupies the entire background. As in my example, I want the same to occupy 70% of the width, "eat" the corners of the image.

How can i fix this?

HTML:

<div id="esquerda" style="width: 30%; height: 500px">
 ....conteudo.....
</div>

<div id="direita" style="width: 70%; height: 500px">
   <img src="fundo.jpg" class="bg">

</div>

CSS

.bg {
    min-height: 100%;
    min-width: 1024px;

    width: 100%;
    height: auto;   

    position: fixed;
    top: 0;
    float: right;
}


@media screen and (max-width: 1024px){
     .bg {
        left: 50%;
        margin-left: -512px; 
     }
}
+4
source share
3 answers

background-image 3 ( xBrowser, Safari)
cover #bg

*{ box-sizing: border-box;}
html, body{ height:100%; }
body{ position:static; margin:0; }

#bg{
  background: url('http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg') 50%;
  background-size: cover;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 70%;
}
#menu{
  position: fixed;
  bottom: 0; top: 0; left: 0;
  width: 30%;
  background: rgba( 0, 0, 255, 0.4 );
}
#page{
  position: relative;
  border: 10px dashed #000;
  margin-left: 30%;
  width: 70%;
  height: 2000px;
}
<div id="bg">BG</div>
<div id="menu">FIXED</div>
<div id="page">SCROLLABLE</div>

CSS3 -, .

, " " #bg, , bg #page, background-attachment: fixed;, , , Safari , cover.

+3

background-image CSS. CSS, .

.bgImage {
    background-image: url("fundo.jpg");
}

<div>.

<div id="direita" class="bgImage" style="width: 70%; height: 500px">
   ...    
</div>
+1

Do it in a simple way - use background-image: url("fundo.jpg");div-style CSS .

+1
source

Source: https://habr.com/ru/post/1622004/


All Articles