The W3Schools online code editor allows you to edit code and view the result in your browser
With the Viewport Meta Tag - HTML Responsive Web Design - W3Schools
Solution : (I stripped most of your containers to make it simple to understand and work with)
html,
body,
.section-images {
height: 100%;
margin: 0;
}
.section-images {
margin: auto 2em;
text-align: center;
}
img {
display: block;
width: auto;
height: auto;
max-width: 100%;
max-height: 90%;
margin: 20px auto;
}
<section class="section-images">
<a href="#"><img src="http://i.imgur.com/hMRnvUx.jpg" /></a>
<div class="image-description">blabla3<br/>more blablah<br/>and more blablah</div>
<a href="#"><img src="http://i.imgur.com/lBuIEDh.jpg" /></a>
<div class="image-description">blabla2</div>
<a href="#"><img src="http://i.imgur.com/k8BtMvj.jpgg" /></a>
<div class="image-description">blabla3<br/>more blablah<br/>and more blablah</div>
</section>
Explanation :
This solution is based on the fact that percentages sizes (width and height) are relative the size of the parent element.
Considering is a direct child of .section-images start by setting :<body>
html, body, .section-images {
width:100%;
height:100%;
margin:0;
}
So the direct parent of the images equals viewport size.
Then, you can size your images easily using :
img{
width:auto;
height:auto;
max-width:100%;
max-height:90%;
}
Images will never exceed 100% width and 90% height of viewport while keeping their aspect ratio. And they will stay in the flow of the document.
You need to subtract to account for the 20px margins on each side of the second image:10px
img {
float: left;
width: calc((100% - 20px) / 3);
}
img {
float: left;
width: calc((100% - 20px) / 3);
}
img:nth-of-type(2) {
margin: 0 10px;
}
body {
margin: 0;
}
<img src="//placehold.it/200" />
<img src="//placehold.it/200" />
<img src="//placehold.it/200" />
I think your negative impression is right. It doesn't implement the features you'd expect in responsive design.
The key to your question is that Google Sites don't use a viewport declaration (meta viewport in the head element). If you don't have that, then device browsers treat you as a legacy desktop-only website. They assume you'll break completely below ~830px, and set a page min-width accordingly. That doesn't sound much like responsive design to me.
Google Sites don't let you write your own CSS or HTML HEAD, so you can't implement a more responsive design yourself.
To be fair, you can choose to not set a fixed page width. Also navigations buttons will reflow on relatively narrow windows, if you're using the "horizontal navigation" feature. The latter isn't great design but at least it's degrading gracefully.
There is an option "Automatically adjust site to mobile phones" under Manage site -> General. However many people suggest it's better not to use it :). I tried enabling it on an old site, previewing the page, and selecting "preview in mobile". At least on Firefox on my original netbook (800px width), it was not responsive. It didn't expand to use the 800px screen properly.
As an aside, the line-wrapping (or absence of it) is a pre-existing issue with my site. You could blame this on me for not testing it :). However it illustrates a limitation of the WYSIWYG editor in Google Sites. It doesn't show, check for, or filter out the formatting that causes this problem.
You have to apply
width: 100vw;
height: 100vh;
object-fit: contain;
To directly , you can use imgid or class directly but last method is not recommended as it will apply to all img tags in the documentimg
I have used red to show how much area image covers but as background so image ratio's are maintainedobject-fit: contain;
object-fitUse
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
To remove any unnecessary scroll bars as tags have some default horizontal and margin . So , here used the padding tagbody
.Image {
width: 100vw;
height: 100vh;
object-fit: contain;/*Can be cover , fill , none...*/
background-color: red;
}
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
<div>
<img src="https://www.hdnicewallpapers.com/Walls/Big/Rainbow/Rainbow_on_Mountain_HD_Image.jpg" class="Image" />
</div>
http://dev.opera.com/articles/view/an-introduction-to-meta-viewport-and-viewport/ gives you an introduction to the various aspects of the viewport meta tag. For optimizations across a range of screen sizes, you probably want to use in combination with media queries (also covered in the article above).<meta name="viewport" content="width=device-width">
Note that the Element Fusion tutorial you linked to uses semicolon delimiters between viewport values instead of commas - this is not correct. Be sure to use commas, like in your initial example :-)