I have a two-column row in which I want one row—which contains some text—to keep it's height and size independent of the window size, and the other—which contains the video—to shrink and stretch with the window size.
I'm too much a beginner with CSS to have a better idea of how to do this by reading related answers here.
Here's the HTML. I didn't set height or width for the video because I want it to be variable and have the whole page overflow after the video's minimum width.
<!-- Originally tried with bootstrap grid, but that didn't work, that's why the class names -->
<div class="row upper-row">
<div class="text-column">
<!-- some paragraphs -->
</div>
<div class="video-column">
<div class="video">
<video controls>
<source src="<some source>" type="video/mp4">
</video>
</div>
</div>
</div>
Attempt at CSS:
Styles for the video are almost empty because, after trying so many things, nothing has worked and are too much to list here. I read about fit-content, object-fit, tried to use flexbox, but can't make this work.
.text-column {
width: 500px;
}
.video-column {
min-width: 500px;
}
UPDATE
Before seeing the three answers posted so far, I had started trying with Bootstrap's auto-layout columns, and it seems to work. The only thing that I haven't been able to sort out is that, after the video has reached it's min-width, the page doesn't overflow; instead, the video is wrapped into a second row and everything becomes a mess.
I have been reading a bit about the methods from the answers provided and I will checkout to a previous commit to try them. For now, this is what I have done. I have added a couple things, but the main content is the same.
HTML:
<div class="container">
<div class="row upper-row">
<div class="col-lg-auto text-column">
<!-- some paragraphs -->
</div>
<div class="col video-column">
<div class="player-container">
<div class="video">
<video controls>
<source src="<some source>" type="video/mp4">
</video>
</div>
</div>
</div>
</div>
</div>
CSS:
.player-container {
/*This width seems to control the actual video size. If I use 100%, it allows the video to get too big and overflow the screen.*/
width: 90%;
/*This is the height that seemed most appropriate for this div to actually contain the video height*/
height: 100%;
/*I use this position because I am overlaying some things on the video*/
position: relative;
top: 5%;
left: 4%;
}
.video {
/*This is to do the overlap*/
position: absolute;
top: 0%;
left: 0%;
}
video {
min-width: 10%;
max-width: 100%;
min-height: 10%;
max-height: 100%;
}
With this, the text-column stays the same width and the video column successfully shrinks with the window, but, as I said, it doesn't overflow after the min-width has been reached.
You can achieve this by using media queries in css or giving the container your desired width and height auto it will make it also responsive
There are many ways to achieve a two columns layout.
In my opinion, the simplest solution is with flex.
Solution on Codepen
However, I don't recommend this kind of solution since it's not responsive, as it does not scale well with the size of the screen and doesn't work well on mobile.
For a better solution, you would most likely cover the width of the whole screen with the 2 columns and just resize the video element as needed.
Better solution on Codepen
You could also make this work with a Grid layout instead of Flex.
Here is a good guide on how to realize common layouts with CSS grid.
You can use % for the responsiveness of your video.
.video-column video { width: 100%; }
Related
I have an iframe I want to add to my React.js website. The src of the iframe links to another responsive website (hereby known as "gallery"). This means the width and height of gallery will change depending on the website size. How do I adjust the width/height/styling of the iframe so that like gallery, the iframe also shows all of the webpage contents regardless of screen size?
I tried setting the width and height of the iframe to 100%. While the iframe did span the entire width of the device screen regardless of size, setting the height to 100% unfortunately did not do what I wanted it to. Only a small part of the iframe showed up and the rest was cut off with a scrolling bar. If I set scrolling to "no", the same small part of the iframe would still only show.
I also tried hardcoding the height of the iframe. If I set the height large enough to show all contents on larger screens, some of the content would still be cut off on smaller screens. If I set the height large enough for smaller screens like smartphones, there would be a ton of empty space at the bottom of my website on larger screens that I didn't want.
I am not sure what to do. Some of the things I tried (such as setting height to 100% and setting scrolling to no) were from stackoverflow itself, so I have tried looking at other posts. I'm not sure what to do.
I can share code if needed; this is a personal project, not a school project, so there aren't any consequences of sharing code.
Thanks in advance for the help!
My HTML CODE -
<div class = "container">
<iframe title = "gallery" class = "responsive" src="LINK" frameborder="0" allowfullscreen scrolling="no">
</iframe>
</div>
</div>
MY CSS CODE -
.container {
position: absolute;
width: 100%;
overflow: hidden;
padding-top: 66.66%;
}
.responsive {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
border: none;
}
This problem is way more complex than it should be, at one point a solution was part of the HTML 4 spec, but it got dropped I expect due to being to hard to reliable work out the night of the content.
I wrote a library a while ago that tackles these problems, it is called iframe-resize-react and should work in most situations
I have a website that I am making for a friend, and on the mobile homepage, the footer is perfectly aligned. However, when you go over to either the pics or vids page, the footer is moved over to the left side. The css file can be found here. I have no idea why this is happening, and any help to understand why this is happening, and how to fix it would be great.
Just a quick note, to access the mobile version on desktop, use chrome, open up dev tools, and click on the phone icon in the top left of the dev tools pane. Set the width to 617, and the height to 1002.
Thanks!
Your content is overflowing from the pf-content class, making the page larger than 100% width that the footer is filling.
There are a range of ways to solve this:
Add overflow hidden to pf-content (Will look nasty on small screens)
Set a min width on the whole page body{ min-width: 1200px; }
Make the videos reactive, e.g. display inline blocks which will then wrap to a new line if the page is to small. (Could also be done with media queries used to scale the videos)
I would suggest making the page more responsive, and getting the videos to flow onto new lines if the page is too small to contain multiple. As a general rule tables aren't a great way to structure anything (other than an actual data table) you'd be much better off with a more flexible element. Though this will be more work on your part.
The width of the two iframes for video are set to 520px each which exceed the resolution you were testing on.
The iframes were placed in a table, with a fixed number of columns, causing an issue of overflow.
You can place the iframes in div instead, then change the way they are displayed in css. i.e. you can do a 2 column-like structure in the desktop.css if preferred and a responsive one in the mobile.css
<div class="video-container">
<iframe src="https://player.vimeo.com/video/146191500?title=0&portrait=0" width="520" height="293" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>
</div>
<div class="video-container">
<iframe src="https://player.vimeo.com/video/141281580?title=0&portrait=0" width="520" height="293" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>
</div>
<style>
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 35px;
height: 0;
overflow: hidden;
}
.video-container iframe {
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
}
</style>
Not sure why I can't get this to work. I'm certain I've used this method before but can't find anything on it and can't get the issue resolved. I have a container div that contains a video. The height and width of the video will always adher to the 16:9 ratio of the original video. The video is fixed as I will be adding more content to the container (.featured) div that will overlay over the video. I need the height of the container to equal the height of the video in order to solve my problem (not to mention help out with responsive issues i will run into). My code is as follows:
<div class="featured">
<video loop id="featured-content" class="featured-video" poster="/sites/all/themes/merge/img/poster-frame.jpg">
<source src="/sites/all/themes/merge/img/Atlanta-Test.mp4" type="video/mp4" >
</video>
<div class="main-wrap">
<h1>Learn</h1>
</div>
</div><!--end featured-->
And my sass:
.featured{width: 100%; height: auto;
#featured-content{width: 100%; height: auto;position: absolute;}
}
Problem is the content from the rest of my site is coming up over the top of the video. Need the container div to match the height the video's auto height but can't get it to work for some reason. Any help is much appreciated!
You should be able to drop the height specification, and try adjust display type to inline-block:
.featured {
width: 100%;
display:inline-block;
}
Fiddle (added red border for clarity)
You need to float the video.
#featured-content {
float: left;
}
http://codepen.io/PanosAngel/pen/jqabxJ
I am using fullPage.js
This may sound very noobish, but can't figure how to set a section to have a height of less than 100%, I have tried setting it in the css using .section and #section1 (eg. height: 80%;), but this has no effect...
Many thanks.
Max
The same question was answered in the plugin's github issues forum.
This is a FULL PAGE plugin.
There's no such option
It is not an option the plugin offers.
If you want to do it, you would need to do it by yourself. Probably by overwriting the height property of the sections and slides after the plugin is rendered (on the afterRender callback) and after it gets resized (afterResize).
You can try it with by adding CSS styles as well, by adding things like:
#section1,
#section1 .fp-slide,
#section1 .fp-tableCell{
height: auto !important;
}
UPDATE
Now fullpage.js provides a way to create smaller sections than the viewport (or even bigger ones when using autoScrolling:false or scrollBar:true.
Adding the class fp-auto-height on each section will do it as stated in the documentation.
UPDATE 2
fp-auto-height won't allow you to use percentages, but there's an extension that gives you that possibility. Offset Sections.
It also allows you to show the section in the middle of the view-port showing parts of both the previous and the next one.
This is what I came up with I changed
$(window).height();
to
var windowsHeight = $('.universal-container').height();
so lets say we have 4 divs
<div class="main-container">
<div class= "1st-div-holder">
</div>
<div class= "2nd-div-holder">
<div class= "section">
<div class= "universal-container">
</div>
</div>
</div>
</div>
now on our css we can do something like this
.main-comtainer{
width:100%;
height:100%;
}
.1st-div-holder{
height:10%;
width:100%;
position:fixed;
}
.2nd-div-holder{
height: 90%;
position: absolute;
bottom: 0;
}
this way the height is automatically picked up without taking up the whole window.
A lot of sites have embedded Youtube videos. Youtube works on phones now. If responsive design is going to be a thing, why shouldn't it be a thing for iframes that contain Youtube videos?
After searching for days (on and off) I couldn't find a clear, simple solution to the problem (I'm new to HTML/CSS). It's easy to scale iframe width, but to keep height relative I found chunks of javascript, jQuery, and php, all pretty esoteric to a beginner at web design. I wanted a simple method of scaling an iframe's height to always keep a certain aspect ratio, no matter how the width changes.
To keep this from being an unanswered question, the method's below. Here are the initial settings for your iframe:
<iframe src="//www.youtube.com/embed/example_url" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
That's it.
I was wondering if anyone had any other solutions as well.
The solution was nested divs. A little hackey, I know, but it's a really easy solution to a problem that had too many solutions. Youtube videos keep an aspect ratio of 16:9 in this example. Your HTML should look like this:
<div id="outer">
<div id="inner">
<iframe src="//www.youtube.com/embed/example_url" frameborder="0" allowfullscreen="allowfullscreen"></iframe>
</div>
</div>
And your stylesheet:
#outer{
max-width: 640px;
max-height: 360px;
width: 100%;
height: 100%;
}
#inner{
height: 0px;
padding-bottom: 56.25%;
}
#inner iframe{
width: 100%;
height: 100%;
}
The outer div sets the maximum height and width and allows itself to scale, while the inner div uses the padding attribute to match its height to the width of the containing div (I'm pretty sure). The value should be set at (height*100/width)%, the ratio of the height to the width. The iframe then stretches to fill the whole containing div. Whitespace fills on web, so you should be just fine putting text underneath.
I can't remember exactly where I found it. It was done with images somewhere else on Stack Overflow, but I think it's relevant to have it set up to work for iframes since embedded Youtube videos are so common.
Here's a JSfiddle with the working thing.
With the introduction of the aspect-ratio property in CSS, you don't need any clever workarounds, wrappers, or JS.
iframe {
aspect-ratio: 16 / 9;
height: auto;
width: 100%;
}
The property already has excellent support across browsers making it suitable for the majority of sites: https://caniuse.com/mdn-css_properties_aspect-ratio
Working Example