We are building a web application with google map that covers all the main page.
It looks great but when I open it on another computer, with slightly different resolution or screen size, the map size does not change accordingly.
I tried working with "%" instead of "px" but it is even worse and the map disappears.
I found some solutions that use "!important" but it didn't work for me, can't figure out why.
Here is my CSS (Cascading Style Sheets) for the map:
#google-container {
position: relative;
width: 100%;
height: 200px;
background-color: #e7eaf0;
}
#media only screen and (min-width: 768px) {
#google-container {
height: 300px;
}
}
#media only screen and (min-width: 1170px) {
#google-container {
height: 710px;
}
}
#cd-google-map {
position: relative;
}
#cd-google-map address {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
padding: 1em 1em;
background-color: rgba(211, 104, 104, 0.9);
color: white;
font-size: 13px;
font-size: 0.8125rem;
}
#media only screen and (min-width: 768px) {
#cd-google-map address {
font-size: 15px;
font-size: 0.9375rem;
text-align: center;
}
}
Here is my html (the map is being built in the main.js file):
<section id="cd-google-map">
<div id="google-container"></div>
<div id="cd-zoom-in"></div>
<div id="cd-zoom-out"></div>
<div id="addNewReviewButton" ng-controller="NavCtrl">
<button style="border-color: transparent; background-color: transparent;">
<ng-md-icon icon="add_circle" style="fill: #d43f3a" size="120" ng-click="addNewReview()"></ng-md-icon>
</button>
</div>
</section>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAl8UrwCupLjkdVfx_IXugrryC8ES32Cz8&language=iw&?v=3.exp&sensor=false&libraries=places"></script>
<script src="js/main.js"></script>
Here is an image of how it looks on my device, when on others it fits perfectly:
You can use vw (viewport width) and vh (viewport height) instead of %
like :
height: 100vh;
It looks like your problem is this CSS:
#media only screen and (min-width: 768px) {
#google-container {
height: 300px;
}
}
If you remove that, you can use percentage sizing (or vh/vw sizing)
proof of concept fiddle
I just resolved it you need to change to:
height: 100vh;
and to make these following changes:
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
Hope that help you as much it helped me.
You may use absolute positioning to fit the whole container to the edges of the browser:
Markup
<div class="map">
the map is here ...
</div>
CSS
.map{
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
This gives you a fullscreen map layout.
parent is set to relative, then the IFRAME is treated as child of that parent with position:absolute values.
padding-bottom: (height*100)/width;
for e.g.:
padding-bottom: 56.22% /*(768*100)/1366) - common screen resolution.*/
.table {
width: 100%;
height: 100%;
position: relative;
}
iframe {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 100%;
padding-bottom: 56.22%;
}
<div class="parent">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3774.2135216027964!2d72.83238461524519!3d18.921940761713312!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3be7d1c73993eebd%3A0x9e8c8bfbd74a913a!2sGateway+of+India%2C+Apollo+Bandar%2C+Colaba%2C+Mumbai%2C+Maharashtra+400001!5e0!3m2!1sen!2sin!4v1450701184011"
frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
Related
I've been working on this all day but even with all my googling, I haven't figured it out.
Basically I would like to have the same effect as on www.tesla.com
The video is fullsize, but resizes according to the size of the window, and at the same time crops it a bit but keeps the video centered (try it out on Tesla website it's great). If it gets too small, it displays an image instead (for mobile).
I'm running the site on a jekyll theme with GitHub pages : https://alanlemoine.github.io/personal
My issues:
On my 13" screen, the video is too big and a vertical scroll bar
appears. I would like to have it fit the window, without scroll bars.
Even if it crops the video at the bottom (something with "overflow:
hidden" I think ?)
When resizing the window, the whole video is resized. I would like to
have it resized like www.tesla.com where it crops it but keeps
it centered.
I don't want the video to be completely fullscreen. I need the
navigation bar at the top. So in a DIV is better.
Can you help ?
Thank you so much in advance.
Here is what I have:
/* Default hide the video on all devices */
#video {
display: none
}
/* Default display the image to replace the video on all devices */
#videosubstitute {
display: block;
width: 100%;
height: auto;
max-width: 100%
}
/* Medium Devices, Desktops */
#media only screen and (min-width: 992px) {
#video {
display: block
}
#videosubstitute {
display: none
}
}
#videoDiv {
width: 100%;
height: 360px;
position: relative;
}
#videoBlock,
#videoMessage {
width: 100%;
height: 360px;
position: absolute;
top: 0;
left: 0;
}
#video {
width: 100%;
}
#videoMessage {
padding: 0.4em;
margin: 0;
}
#videoMessage {
color: white;
z-index: 99;
}
#videoMessage h1 {
font-size: 3em;
color: #ffffff;
text-align: center;
}
<div id="videoDiv">
<div id="videoBlock">
<div><img src="http://www.imi21.com/wp-content/uploads/2016/11/t12.jpg" id="videosubstitute" alt="" width="800"></div>
<video preload="preload" id="video" autoplay="autoplay" loop="loop">
<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4"></source>
</video>
<div id="videoMessage">
<h1>Hello world</h1>
</div>
</div>
</div>
This is a relatively simple trick you can do with HTML 5 and some CSS.
First off you will need to absolutely position your video element, and hide its overflow. Then you will make it 100% the width and height of the page.
Next you will basically stretch the video to crop it based on the aspect ratio of the screen. There is a nifty thing called object-fit, which you can also just write as object-fit:cover which will give you the same effect, but it is not yet supported by IE so you will need both if you decide to use that.
I have included a codepen with a solution for you.
http://codepen.io/DrkDevil/pen/OpXxZV/
<nav>your navigation goes here.</nav>
<div class="flexCon" >
<div id="videoMessage">
<h1>Hello world</h1>
</div>
</div>
<div id="videoBg">
<video loop muted autoplay poster="img/videoframe.jpg">
<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4">
</video>
</div>
<style>
#videoBg { position: fixed; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden;}
#videoBg > video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
#media (min-aspect-ratio: 16/9) { #videoBg > video { height: 300%; top: -100%; }}
#media (max-aspect-ratio: 16/9) { #videoBg > video { width: 300%; left: -100%; }}
#supports (object-fit: cover) {#videoBg > video { top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }}
/* Demo Classes */
nav { position:fixed; width:100%; top:0; left:0; padding:20px; background:#fff; z-index:2;}
/* Center content with flexbox container */
.flexCon { height: 100vh; display: flex; justify-content: center; align-items: center; }
/* Position the content relative to the flex container */
#videoMessage { z-index:1; position:relative; }
</style>
Here is a really good explination of how you can achieve what you are looking for in a more in-depth.
https://fvsch.com/code/video-background/
First of all, the video is kinda scaled and I'd love it to fit in the whole screen. Besides that, I can't figure out how to make video responsive on all screen sizes.
HTML
<div class="spread-video">
<video src="https://b922bde52f23a8481830-83cb7d8d544f653b52d1a1621f05ea9d.ssl.cf3.rackcdn.com/video/landingpage.mp4" autoplay="" loop="">
</video>
</div>
CSS
.spread-video {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
Does anybody know how to achieve this? Thank you in advance!
Target the <video> instead of the parent div, see fiddle: https://jsfiddle.net/m1pz6zcu/4/
.spread-video > video {
width: 100%;
}
Since the aspect ratio of the video is different from that of the view port, a work around for the issue is to make the video width bigger then the viewport width, center it and hide the overflow. See fiddle: https://jsfiddle.net/m1pz6zcu/6/
.spread-video > video {
width: 200%;
margin-left: -50%;
}
.spread-video{
overflow: hidden;
}
Add the following css
.spread-video video {
width:100%;
}
https://jsfiddle.net/mlegg10/fsftz8rt/4/
/* Flexible iFrame */
.flexible-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
}
.flexible-container iframe,
.flexible-container object,
.flexible-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<!-- Responsive iFrame -->
<div class="flexible-container">
<iframe src="https://b922bde52f23a8481830-83cb7d8d544f653b52d1a1621f05ea9d.ssl.cf3.rackcdn.com/video/landingpage.mp4" frameborder="0" style="border:0"></iframe>
</div>
Try this
position: relative;
padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
padding-top: 25px;
or this one
position: absolute;
width: 100%!important;
height: 100%!important;
I have a question about the display of a container.
First, I managed to simulate the attribute "object-fit: contain;" for an image by using a verticaly alligned strut and the attribute "text-align: center" (thank you IE).
See it there: http://codepen.io/babybackart/pen/vGQeoK
html:
<body>
<div class="plancheBox">
<div class="strut"></div><!--
--><img src="http://images.forwallpaper.com/files/thumbs/preview/23/236747__kitten-soft-fluffy-tender_p.jpg">
</div>
</body>
css:
body{
height: 100%;
width: 100%;
display: block;
text-align:center;
}
h1, h2{
font-family: Arial, sans serif;
font-weight: 300;
color: white;
}
.plancheBox{
background-color: green;
position: absolute;
display: block;
width: 90%;
height: 90%;
vertical-align: middle;
}
.strut {
height:100%;
display:inline-block;
vertical-align:middle;
}
.plancheBox img{
max-height: 100%;
max-width: 100%;
vertical-align:middle;
}
I wanted to add a text on the image so I put the image and a text-box in a bloc (the text-box is absolute to appear in front of the image).
See it there: http://codepen.io/babybackart/pen/BKGwZL
html:
<body>
<div class="plancheBox">
<div class="strut"></div><!--
--><div class="container">
<img src="http://eskipaper.com/images/photo-cat-1.jpg">
<div class="descriptionBox">
<h1>Joe le chat</h1>
<h2>Post haec Gallus Hierapolim profecturus ut expeditioni specie tenus adesset, Antiochensi plebi suppliciter obsecranti ut inediae dispelleret metum, quae per multas difficilisque causas adfore iam sperabatur.</h2>
</div>
</div>
</div>
</body>
css:
body{
height: 100%;
width: 100%;
display: block;
text-align:center;
}
h1, h2{
font-family: Arial, sans serif;
font-weight: 300;
color: white;
}
.plancheBox{
background-color: green;
position: absolute;
display: block;
width: 90%;
height: 90%;
vertical-align: middle;
}
.strut {
height:100%;
display:inline-block;
vertical-align:middle;
}
.container{
max-height: 100%;
max-width: 100%;
display:inline-block;
vertical-align:middle;
}
.container img{
max-height: 100%;
max-width: 100%;
display:inline-block;
vertical-align:middle;
}
.descriptionBox{
background-color: blue;
position: absolute;
width: 60%;
margin: 0 20% 5% 20%;
bottom: 0;
}
The problem is that my .div ".container" doesn't act like my image in the first example, it overflows on the bottom when the windows' height is small.
Main question: Is there a way to make the ".container" act like the image in the first example ?
Extra-question: How to fix the ratio and the size of the text-box with the size of the image?
Thank you by advance for your answers !
You try to size the container according to it's content and the content according to it's parent at the same time. This does not work. One of it needs to have set some dimensions.
According to your examples it's the image, that should be fit into an container, so I dimension the container and let the image be sized according to it.
CSS:
.container {
height: 100%; /* not max-height */
width: 100%; /* not max-width */
overflow: hidden;
position: relative;
}
.container img {
max-height: 100.1%; /* ".1" just to avoid small lines due to browser rendering */
max-width: 100.1%; /* ".1" just to avoid small lines due to browser rendering */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
The position: absolute is needed to "fit" the image inside your container an position it at the same time. The 50% moves the top-left border of the image to the center of the container, and the transform moves the image by half its width and height back - so it's centered.
Since the above is outdated as per the more information provided by the OP. You'd need additional JS for that:
JS:
$('.plancheBox img').each( function() {
var $img = $(this),
$plancheBox = $img.closest('.plancheBox');
$img.css({
'max-height' : $plancheBox.height(),
'max-width' : $plancheBox.width()
});
$img.closest('.container').css({'position' : 'relative'});
});
CSS:
[...]
.container{
display: table;
margin: 0 auto;
position: absolute;
}
.container img{
max-height: 100%;
max-width: 100%;
width: auto;
height: auto;
}
.descriptionBox{
background-color: blue;
position: absolute;
bottom: 5%;
right: 20%;
left: 20%;
}
[...]
example fiddle: jsfiddle.net/jpu8umd6/2
In case a portrait plancheBox is possible: jsfiddle.net/jpu8umd6/3
When resizing the browser should be considered by JS, add an event handler, that resets the css-changes and calculate the needed values again.
See: jsfiddle.net/jpu8umd6/4
JS:
// calculateImageDimension() contains the JS described above
var resizeEnd;
$(window).on('resize', function() {
clearTimeout(resizeEnd);
resizeEnd = setTimeout(function() {
$(window).trigger('resize-end');
}, 200);
});
$(window).on('resize-end', function() {
$('.plancheBox img').css({
'max-height' : 'none',
'max-width' : 'none'
})
$('.plancheBox .container').css({'position' : ''});
calculateImageDimension();
});
Since .descriptionBox has position: absolute; the (surrounding) .container should probably have position:relative;
https://codepen.io/eye-wonder/pen/EKGPmZ
I am using bootstrap to implement the responsive web design. I am facing issue to apply "left" property as %. What I found is, instead of taking the % of total browser width, it takes the % of #media width define which really breaking the responsive nature of application.
.image-container {
width: 173px;
top: -69px;
left: 50%;
margin-left: -86px;
max-width: 336px;
overflow: hidden;
position: absolute;
}
#media (min-width: 660px) {
.image-container {
left: 63%;
}
}
#media (min-width: 831px) {
.image-container {
top: -91px;
left: 80%;
width: 30%;
}
}
#media (min-width: 1280px) {
.image-container {
left: 85%;
}
}
I found following
1. At >1280 width, left=1280*.85 is used
2. At > 831, left=831*.80 us used
3. At > 660, left=660*.63 is used
Following is HTML markup snippet
<div class="bottom-section">
<div class="parent-container">
<div class="image-container">
<img class="card-art" src="/img/application/cardarts/thumbnails/img.png">
</div>
</div>
</div>
Following is parent container css
.parent-container {
padding-left: 0;
width: 100%;
padding-top: 68px;
max-width: 970px;
margin: 0;
position: relative;
}
#media (min-width: 660px) {
.parent-container {
padding-top: 20px;
}
}
This is a surprising behavior for me. My understanding is, left=x% should alwasy look for parent element and apply the % of that. I am new to media query and using bootstrap to implement the responsive web design.
Here is a fiddle to play with.
The example below has an gray div (#outer) with a child orange div (#inner). #inner will fill the page proportionally on width only. Is it possible to have #inner scale proportionally based on width and height using only CSS? Please, no Javascript solutions as I am aware of how to accomplish it that route, but would prefer a CSS solution if possible.
http://jsfiddle.net/Gchr4/
CSS
body, html {
margin: 0;
padding: 0;
height: 100%;
}
#outer {
background-color: #EFEFEF;
width: 100%;
height: 100%;
}
#inner {
background-color: #ff9933;
width: 100%;
padding-top: 50%;
}
HTML
<div id="outer">
<div id="inner"></div>
</div>
Javascript example of what I am attempting to achieve: http://jsfiddle.net/Q4Qdy/
Use height:100% for the #inner.
However, due to your padding, the height will add 50% to it. This will be fixed by using box-sizing:border-box, but this still has some browser issues. So if you don't have to add padding, i would suggest to remove it.
working example
#inner {
background-color: #ff9933;
width: 100%; height: 100%;
padding-top: 50%;
box-sizing: border-box;
}
It is possible using media queries (and min-aspect-ratio, in particular) and viewport units: http://jsfiddle.net/79Fhb/.
HTML:
<div id="outer">
<div id="inner"></div>
</div>
CSS:
body, html {
margin: 0;
padding: 0;
height: 100%;
}
#outer {
background-color: #bbb;
height: 100%;
}
#inner {
background-color: #ff9933;
}
#inner:before {
content: "";
display: block;
padding-top: 50%;
}
#media screen and (min-aspect-ratio: 2/1) {
#inner {
height: 100%;
width: 200vmin;
}
}