0

Im currently trying to design a website for a friend, of course its to be a cross platform website, i have the following code included so the screen elements will change size accordingly

        * {
          box-sizing: border-box;
          }
         .row::after {
         content: "";
           clear: both;
           display: block;
}
[class*="col-"] {
    float: left;
    padding: 15px;
}
/* For mobile phones: */
[class*="col-"] {
    width: 100%;
}
@media only screen and (min-width: 600px) {
    /* For tablets: */
    .col-m-1 {width: 8.33%;}
    .col-m-2 {width: 16.66%;}
    .col-m-3 {width: 25%;}
    .col-m-4 {width: 33.33%;}
    .col-m-5 {width: 41.66%;}
    .col-m-6 {width: 50%;}
    .col-m-7 {width: 58.33%;}
       .col-m-8 {width: 66.66%;}
       .col-m-9 {width: 75%;}
       .col-m-10 {width: 83.33%;}
       .col-m-11 {width: 91.66%;}
       .col-m-12 {width: 100%;}
     } 

etc one for desktop too.

And it works for all my other elements but the difficulty arises when i try to put an image in a div. The image shows up but very small like thumb size. Initially i was using

max-height:100%; max-width:100%; 

now im using the code below and its the same problem occuring, a thumb size image HTML

 <div class="header">
    <div id="container">
    <img src="D:\kWebsite\images\websize\cakeA.jpg" alt="cake" />
    </div>

<h1>food</h1>
</div>
    <script type="text/javascript">
    (function() {

var img = document.getElementById('container').firstChild;
img.onload = function() {
    if(img.height > img.width) {
        img.height = '1000%';
        img.width = 'auto';
    }
};

}());
</script>

with this in the CSS

#container {
   width: 48px;
   height: 48px;
}

#container img {
   width: 100%;
 max-width:100%;
}

I do have the viewport in my html

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

but nothing works.

Thanks for your help in advance.

awnstosh
  • 71
  • 5

1 Answers1

0

You can add that image as a background to the div

#container {
  background-image: url("D:\kWebsite\images\websize\cakeA.jpg");
  background-size: contain;
  background-position: center center;
  background-repeat: no-repeat;
}

Or if you want it in one line, do it like this:

#container {
  background: rgba(0, 0, 0, 0) url("D:\kWebsite\images\websize\cakeA.jpg") no-repeat scroll center center / contain;
}
pol
  • 2,641
  • 10
  • 16