Text Overlap Video tag CSS - html

I'm not sure as to why when I drag my browser around my text and video overlap. I want to prevent this:
Here is a jsfiddle example:
https://jsfiddle.net/liondancer/m3xug7vo/
example:
Here is the CSS regarding the particular page:
.wrapper {
width: 950px;
margin: auto; /* Centering blocks */
/*position: relative;
display: block;*/
}
.index {
}
.video-container {
position: relative;
min-width: 100%;
min-height: 100%;
/*width: auto;
height: auto;*/
z-index: -100;
background: no-repeat;
/*background-size: cover;*/
display: block;
width: 100vw;
height: 100vh;
object-fit: cover;
}
.title-area {
height: 100%;
width: 100%;
vertical-align: middle;
.container {
width: 100%;
padding-left: 20px;
padding-right: 20px;
margin: 0 auto;
position: relative;
}
}
.index-aboutus {
position: relative;
min-width: 100%;
min-height: 100%;
height: 100%;
display: block;
}
.index-ourwork {
position: relative;
min-width: 100%;
min-height: 100%;
height: 100%;
}
.index-instructors {
position: relative;
min-width: 100%;
min-height: 100%;
height: 100%;
}
The HTML:

The video container is using a height of 100vh, there is one thing you have to think of:
The viewport-percentage lengths are relative to the size of the
initial containing block. When the height or width of the initial
containing block is changed, they are scaled accordingly. However,
when the value of overflow on the root element is auto, any scroll
bars are assumed not to exist.
See http://www.w3.org/TR/css3-values/#viewport-relative-lengths
An easy way to fix this would be to add a class to the parent div of video-container and add a property to set it to overflow: hidden;
It would look like the following:
.video-containerParent {
overflow: hidden;
}
Please see the following jsFiddle for an example:
https://jsfiddle.net/m3xug7vo/1/
The following site has an interesting article about viewport units:
https://web-design-weekly.com/2014/11/18/viewport-units-vw-vh-vmin-vmax/

Related

Responsively resize an image using CSS3, relative to the width of its parent element, without exceeding its original size

I started building a Tribute page on CodePen.io, followed the user stories and got 9 out of 10 of the tests. I've been stuck on resizing the image using CSS3. I googled, tried the answers but none worked for me.
The CSS code is :
#img-div {
text-align: center;
display: block;
filter: grayscale(100%);
width: 100%;
}
img {
padding-top: 10px;
height: auto;
max-width: 330px;
}
Here is the link to the CodePen page https://codepen.io/dansia/pen/NWxNMJP look at it and help me solve this challenge.
I used this to get the image to the center and to make it relative to the width of the parent.
#image {
display: block;
max-width: 100%;
margin-left: auto;
margin-right: auto;
}
You can also use width: 100%; to make the image bigger so it's in the center of the page, but that way you just fool the program, which is not fair.
I used this:
#image {
width:100%;
height:auto;
max-width:500px;
margin-left:auto;
margin-right:auto;
display:block;
}
Have you tried to call it from your div?
#img-div {
text-align: center;
display: block;
filter: grayscale(100%);
width: 100%;
}
#img-div img {
padding-top: 10px;
height: auto;
max-width: 330px;
}
<div id=“img-div”>
<img href=“something”/>
</div>
I added margin-left (auto), margin-right (auto) and display (block) to img element and it worked for me. Finally got the 10/10.
The whole code is then :
#img-div {
text-align: center;
display: block;
filter: grayscale(100%);
width: 100%;
}
img {
padding-top: 10px;
height: auto;
max-width: 330px;
**margin-left: auto;
margin-right: auto;
display: block;**
}
Thank you for your suggestions.
the command
image {
max-width: 100%;
height: auto;
}
is usually enough. but the way that codepin tests for the code is searching for both width and max-width
however, people were saying that you should specify max-width to 330. I simply didn't know how to acquire the information that this image has this width so I had to figure out another way. so here it is (and it passed the test):
#img-div{
background-color: white;
}
#image {
max-width: 100%;
width: 100%;
display: block;
height: auto;
}
you can check it in my codepin project here: https://codepen.io/asserelfeki/pen/LYNOEVJ
I've been doing the same project.
#img-div {
margin: auto;
width: 97%;
padding-bottom: 10px;
}
#image {
max-width: 90%;
display: block;
margin: auto;
}
Why 90%? As for the challenge, we don't want the image to take the full width of the container.
After adding these properties, no matter how much I resize my page, the image will not exceed the container, it will be responsive
This is what i did
#img-div {
text-align: center;
display: block;
filter: grayscale(100%);
width: 100%;
}
img {
padding-top: 10px;
height: auto;
max-width: 330px;
**margin-left: auto;
margin-right: auto;
display: block;**
}
#img-div {
position: relative;
height: 500px;
width: 500px;
}
#image {
position: absolute;
max-width: 100%;
}
Please try this code for your reference
img
{
display: block;
max-width: 100%;
height: auto;
margin: 0 auto;
}
This is the Solution:
#image {
display: block;
width: 100%;
max-width: 100%;
height: auto;
}
#img-div{
width: 50%; <!--depends on the image resolution and its appearance in the page-->
background: white;
margin: auto; <!--centering the image-->
padding: 15px;
}
#image{
display: block;
margin: 0 auto;
max-width: 100%;
height: auto;
}
This link contains what you should need:
https://www.freecodecamp.org/forum/t/tribute-page-responsively-resize-img-relative-to-parent-element/203586
Code in case link doesn't help:
#image {
max-width: 250px; <!--Base width-->
width: 100%; <--Size according to parent use percentage-->
display: block;
margin: auto; <!-- center the image -->
}
try this i thing this is help ful for you....
#media (min-width:500px) {
/*Class name*/ {
/*properties*/
}
}
#media (max-width:499px) {
/*Class name*/ {
/*properties*/
}
}

Setting max and min height for hero div

So, I'm creating a landing page for a client and they want a full-screen hero div with a playing video in the background. The conventional way to do this is for it to be done through:
div.hero {
position: absolute;
width: 100%;
height: 100%;
}
However, I'm being awkward and I need the position to be declared as relative. I also want to limit the height so that you can't shrink the div below 640px, and can't stretch it more than 800px.
Here's my code:
div.hero {
position: relative;
width: 100%;
height: 100%;
max-height: 800px;
min-height: 640px;
display: block;
}
The issue occurs that the box does not become 100% height, and instead it scales to 640px.
How could I fix this?
Use 100vh instead of 100% in height and it will work.
div.hero {
position: relative;
width: 100%;
height: 100vh;
max-height: 800px;
min-height: 640px;
display: block;
background:red;
}
<div class="hero"></div>
you can use this:
html, body {height:100%; margin:0; }
div.hero {
position: relative;
width: 100%;
height: 100%;
max-height: 800px;
min-height: 640px;
display: block;
background:blue;
}
<div class="hero"></div>

Vertically center image when image is higher than container

I have a responsive design with a header image which is placed in a container. The image has width:100%; and height:auto; so it grows as you enlarge the viewport. I don't want to exceed a certain height so the container has a max-height. The image still grows but now the bottom part is cut off now because it aligns to the top of the container.
I would like the image to stay vertically centered in it's container so that parts of the image are cut off at the top and at the bottom. The outcome should look like this:
The header images are uploaded by users so they might have different heights therefore I cannot work with specific pixel-values. Is there a CSS-solution for this or do I have to use JavaScript?
Here is the code:
.wrapper {
width: 90%;
max-width: 600px;
margin: 1em auto;
background-color: #E9ADAD;
}
.container {
text-align: center;
height: auto;
line-height: 200px;
max-height: 200px;
overflow: hidden;
}
img {
width: 100%;
height: auto !important;
vertical-align: middle;
}
<div class="wrapper">
<div class="container">
<img src="http://placehold.it/600x300/C00000/FFFFFF&text=Image+vertically+centered">
</div>
</div>
And I prepared a fiddle.
You can use absolute positioning for your image , negative top/bottom values and margin:auto; to verticaly center the image in the container :
.wrapper {
width: 90%;
max-width: 600px;
margin: 1em auto;
background-color: #E9ADAD;
max-height: 200px;
}
.container {
position:relative;
padding-bottom:40%;
overflow: hidden;
}
img {
position:absolute;
top:-50%; bottom:-50%;
margin:auto;
width: 100%;
height: auto;
}
<div class="wrapper">
<div class="container">
<img src="http://placehold.it/600x300/C00000/FFFFFF&text=Image+vertically+centered">
</div>
</div>
Not so long ago there was only a javascript way to do this but now we have some css rules: object-fit and object-position
They work just like the background-size rules cover and contain:
.container img{
width: 100%;
height: auto;
}
#supports(object-fit: cover){
.container img{
height: 100%;
object-fit: cover;
object-position: center center;
}
}
The problem with this approach is that is very new and doesn't work on ie or Edge yet.
Pen here: http://codepen.io/vandervals/pen/MwKKrm
EDIT: Please, see that you need to declare the width and the height of the image, or it won't work.
.wrapper {
width: 90%;
max-width: 600px;
margin: 1em auto;
}
.container {
height: 200px;
overflow: hidden;
}
.imgWrapper {
position: relative;
width: 200%;
height: 200%;
top: -50%;
left: -50%;
}
img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
height: auto;
width: 50%;
}
<div class="wrapper">
<div class="container">
<div class="imgWrapper"><img src="http://placehold.it/600x300"></div>
</div>
</div>
http://jsfiddle.net/ghygpw8t/5/
inspired by: https://css-tricks.com/perfect-full-page-background-image/
Try like this: Demo
If image size is small it will be arranged in vertical middle and if its big, it will fit in box.
CSS:
.wrapper {
width: 90%;
max-width: 600px;
margin: 1em auto;
}
.container {
text-align: center;
line-height: 200px;
overflow: hidden;
background-color:#ccc;
vertical-align:middle;
height: 200px;
border:2px solid green;
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
img {
width: 100%;
max-height: 196px;
border:2px solid red;
vertical-align: middle;
line-height: 196px;
}
Hope this is what you want!
On the element you want centered.
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
on its parent.
.parent { transform-style: preserve-3d; }
Use a polyfill to render cross browser styles.

Get CSS DIV to fill all height between other DIVs

I have a modal dialog for a workflow that displays content roughly of a fixed height, but also displays an embedded PDF for a user to review.
I'd like to maximize the height of the PDF for the user's screen size, so the dialog scales vertically, but I can't get the PDF to fill all the remaining space within the dialog's div.
Here is the Html:
<div class="container">
<div class="popUp">
<div class="popUpHeader">Header</div>
<div class="fixedContent">Fixed Height Content</div>
<div class="resizeableContent">I should fill all the free vertical space in .popUp</div>
<div class="popUpFooter">Footer</div>
</div>
</div>
and CSS I'm using:
body, html {
margin: 0;
height: 100%;
}
.container {
height: 100%;
min-height: 100%;
background: #F8F8FF;
}
.popUp {
background: lightgrey;
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 70%;
height: 90%;
}
.popUpHeader {
width: 100%;
background: darkgrey;
text-align: center;
}
.popUpFooter {
width:100%;
background:darkgrey;
text-align:center;
position: absolute;
bottom: 0;
}
.fixedContent {
height: 10em;
text-align: center;
background: #E1E1EE;
}
.resizeableContent {
background: #7d7f7c;
text-align: center;
width: 100% height: 100%;
}
JsFiddle: http://jsfiddle.net/trainman1124/pnbeoyb9/2/
Here is an image of the desired result:
Edit
Here is a sample JsFiddle using an embedded PDF, which is what actually needs to be done.
http://jsfiddle.net/trainman1124/pnbeoyb9/3/
Note, I've corrected the missing semicolon in the example and also added overflow:hidden
You could use the display: table; and display: table-row properties in order to fill the space.
Set the .container to fill 100% of the page and .popUp div to display: table; and fill it's parent.
Display all the children as display: table-row;, and then set heights for the popUpHeader and popUpFooter divs.
Allow your resizableContent div to fill the remaining space:
.resizeableContent {
background: #7d7f7c;
width: 100% height: 100%;
display: table-row;
}
Check out this CodePen
Modify Popup class to make its color same as resiseableContent
.popUp {
background: #7d7f7c; /* Modified here */
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 70%;
height: 90%;
overflow: hidden;
}
Depending on what browsers you need to support (This wont work earlier than IE9), one solution would be to use calc and vh units.
Something like:
.popUp {
background: lightgrey;
margin: auto;
height: calc(100vh - 10em); /* Height of viewport minus your .fixedContent div, you may also want to include the height of the header */
overflow: hidden;
}
The updated fiddle has the heights set to % instead. That works as you want I think?
Update
http://jsfiddle.net/batcave/pnbeoyb9/7/
.popUpFooter {
width:100%;
background:darkgrey;
text-align:center;
position: absolute;
bottom: 0;
height: 7%;
}
.resizeableContent {
background: #7d7f7c;
text-align: center;
width: 100%;
height: 80%;
}
.fixedContent {
height: 10%;
text-align: center;
background: #E1E1EE;
}

position absolute with height 100%

I am having a problem with displaying a div. For some reason it is not displaying the inner div.
The position of parent div is relative where as the child div is absolute.
Here is the demo http://jsfiddle.net/squidraj/6R3Hr/6/
HTML Code :
<div class="page-center">
<div class="question_slide inidfeedback">Test</div>
</div>
CSS Code :
.question_slide {
background: #000000;
height: 569px;
width:100%
}
.question_slide {
overflow: hidden;
position: absolute;
top: 0;
width: 100%;
}
.page-center {
margin: 0 auto;
max-width: 1100px;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
}
Just interchange their positions.
.question_slide {
overflow: hidden;
position: relative;
top: 0;
width: 100%;
}
.page-center {
margin: 0 auto;
max-width: 1100px;
overflow: hidden;
position: absolute;
text-align: center;
width: 100%;
}
Here is a demo:http://jsfiddle.net/6R3Hr/3/
Give it a height style. Since the only content is relatively positioned, it doesn't have any inherent height value and because the overflow is hidden, it's not onscreen.
http://jsfiddle.net/squidraj/6R3Hr/2/
.page-center {
margin: 0 auto;
max-width: 1100px;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
height:20px;
}
Edit:
If overflow:hidden is a must, then you must specify a height for your relative div:
.page-center {
margin: 0 auto;
max-width: 1100px;
position: relative;
text-align: center;
width: 100%;
overflow:hidden;
height:100px;
}
Just choose how much height will work for you.
Here's a working jsfiddle with your code.