How to have aspect ratio by parent height? - javascript

I want to have aspect ratio controlled by parent height.
Every example I search in stackoverflow and codepen are examples of aspect-ratio by width size.
In my example I have two div. there height is controlled by wrap div. so in the first div there is a div inside that should display in 16:9 aspect-ratio.
This is mean if the height is 200px then the width should be 355px (200*(16/9)).
Please keep in mind that height can change because I use vh.
How to do that with css?
Here is my example code in codepen
.wrap { display:grid;grid-template-columns:1fr;grid-template-rows:30vh 70vh; }
.item { border:1px solid red; }
.aspect-ratio { background:blue; height: 100%; }
<div class="wrap">
<div class="item">
<div class="aspect-ratio">aspect ratio should be 16:9</div>
</div>
<div class="item"></div>
</div>

you can use css calc();
.wrap { display:grid;grid-template-columns:1fr;grid-template-rows:30vh 70vh; }
.item { border:1px solid red; }
.aspect-ratio { background:blue; height: 100%; width: calc(30vh * 16 / 9); }
<div class="wrap">
<div class="item">
<div class="aspect-ratio">aspect ratio should be 16:9</div>
</div>
<div class="item"></div>
</div>

Related

How to display responsive 5 poker card images with correct aspect ratio?

I want to display 5 poker cards laid side by side with horizontal margin just like on a poker table. I tried this but I can't make it display:
I also want this to be responsive that is it preserves aspect ratio when resized.
.card {
width: 100%;
height: 100%;
background-size: cover;
}
.is2d .two.hearts {background-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgY2xhc3M9ImNhcmQiIGZhY2U9IjJIIiBoZWlnaHQ9IjMuNWluIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIiB2aWV3Qm94PSItMTIwIC0xNjggMjQwIDMzNiIgd2lkdGg9IjIuNWluIj48c3ltYm9sIGlkPSJTSDIiIHZpZXdCb3g9Ii02MDAgLTYwMCAxMjAwIDEyMDAiIHByZXNlcnZlQX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hyZWY9IiNWSDIiIGhlaWdodD0iMzIiIHg9Ii0xMTQuNCIgeT0iLTE1NiI+PC91c2U+PHVzZSB4bGluazpocmVmPSIjU0gyIiBoZWlnaHQ9IjI2Ljc2OSIgeD0iLTExMS43ODQiIHk9Ii0xMTkiPjwvdXNlPjx1c2UgeGxpbms6aHJlZj0iI1NIMiIgaGVpZ2h0PSI3MCIgeD0iLTM1IiB5PSItMTMxLjIzNCI+PC91c2U+PGcgdHJhbnNmb3JtPSJyb3RhdGUoMTgwKSI+PHVzZSB4bGluazpocmVmPSIjVkgyIiBoZWlnaHQ9IjMyIiB4PSItMTE0LjQiIHk9Ii0xNTYiPjwvdXNlPjx1c2UgeGxpbms6aHJlZj0iI1NIMiIgaGVpZ2h0PSIyNi43NjkiIHg9Ii0xMTEuNzg0IiB5PSItMTE5Ij48L3VzZT48dXNlIHhsaW5rOmhyZWY9IiNTSDIiIGhlaWdodD0iNzAiIHg9Ii0zNSIgeT0iLTEzMS4yMzQiPjwvdXNlPjwvZz48L3N2Zz4=')}
<div class="poker is2d">
<div class="middle">
<div class="card two hearts"></div>
<div class="card two hearts"></div>
<div class="card two hearts"></div>
<div class="card"></div>
<div class="card"></div>
</div>
</div>
As Armedin said, you do not have any content inside your div. Width and height 100% won't do anything.
I suggest you to put the image not as background, as it won't change the dimensions of the div. Use img tag and display: inline; for the card div.
.card {
width: 100%;
height: 100%;
background-size: cover;
display:inline;
}
<div class="poker is2d">
<div class="middle">
<div class="card two hearts"> <img src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgY2xhc3M9ImNhcmQiIGZhY2U9IjJIIiBoZWlnaHQ9IjMuNWluIiBwcmVzZXJ2ZUFzcGV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aHJlZj0iI1hIMiIgc3Ryb2tlPSIjODhmIiBmaWxsPSIjRkZDIj48L3VzZT48dXNlIHhsaW5rOmhyZWY9IiNWSDIiIGhlaWdodD0iMzIiIHg9Ii0xMTQuNCIgeT0iLTE1NiI+PC91c2U+PHVzZSB4bGluazpocmVmPSIjU0gyIiBoZWlnaHQ9IjI2Ljc2OSIgeD0iLTExMS43ODQiIHk9Ii0xMTkiPjwvdXNlPjx1c2UgeGxpbms6aHJlZj0iI1NIMiIgaGVpZ2h0PSI3MCIgeD0iLTM1IiB5PSItMTMxLjIzNCI+PC91c2U+PGcgdHJhbnNmb3JtPSJyb3RhdGUoMTgwKSI+PHVzZSB4bGluazpocmVmPSIjVkgyIiBoZWlnaHQ9IjMyIiB4PSItMTE0LjQiIHk9Ii0xNTYiPjwvdXNlPjx1c2UgeGxpbms6aHJlZj0iI1NIMiIgaGVpZ2h0PSIyNi43NjkiIHg9Ii0xMTEuNzg0IiB5PSItMTE5Ij48L3VzZT48dXNlIHhsaW5rOmhyZWY9IiNTSDIiIGhlaWdodD0iNzAiIHg9Ii0zNSIgeT0iLTEzMS4yMzQiPjwvdXNlPjwvZz48L3N2Zz4='/></div>
<div class="card two hearts"></div>
<div class="card"></div>
<div class="card"></div>
</div>
</div>
Edit: If you do not want to use img you can put the img to invisible and then use the background image as the div would still have the dimensions of the img tag inside. Not a good solution, but it would work.
Learn flex or grid; both very useful for things like this.
Flex example:
html, body {
height: 100%;
margin: 0;
}
.card {
border: 1px black solid;
border-radius: 15px;
flex-grow: 1;
padding: 5px;
margin: 5px;
}
.container {
display: flex;
height: 100%;
}
<div class="container">
<div class="card">1</div>
<div class="card">2</div>
<div class="card">3</div>
<div class="card">4</div>
<div class="card">5</div>
</div>

Resize div with jquery javascript and stretch background image

I have a box div and it has header and body. Contains a div that has a background image.
setInterval(function(){
var height = $(".box").height();
$(".box").height(height+2)
}, 1000);
.box{
height: 100%;
background-color: #22ff2f;
width:350px;
}
.box-header{position:inherit; background-color:#9ed;width:100%;}
.box-body{}
.window{
background-position: center;
background-size: cover;
background-image: url('http://dailybestlike.com/wp-content/uploads/2015/07/simple-ideas-products-11.jpg');
min-height:190px;
width:100%;
height:100%;
position:relative;
text-align:center;
overflow:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box">
<div class="box-header">
header
</div>
<div class="box-body">
<div class="window">
</div>
</div>
</div>
my .box is a resizable box, so it will be resize with mouse
But image does not stretch the box. I want to do this with CSS properties. I do not want to set size with javascript. Is this possible?
WORKÄ°NG DEMO
Try this,
<div class="box">
<div class="box-header">
header
</div>
<div class="box-body">
<div class="window">
</div>
</div>
</div>
JS CODE :
setInterval(function() {
var height = $(".window").height();
$(".window").css({
'height': height + 100
});
}, 1000);
This code will stretch your image.
You need to add height for your .box-header, and thanks it you will be can calc your .box-body height. Now your height:100%; in .window will be work properly.
Check this:
setInterval(function(){
var height = $(".box").height();
$(".box").height(height+2)
}, 1000);
.box{
height: 100%;
background-color: #22ff2f;
width:350px;
}
.box-header{
position:inherit;
background-color:#9ed;
width:100%;
height: 20px;
}
.box-body{
height: calc(100% - 20px);
}
.window{
background-position: center;
background-size: cover;
background-image: url('http://dailybestlike.com/wp-content/uploads/2015/07/simple-ideas-products-11.jpg');
min-height:190px;
width:100%;
height:100%;
position:relative;
text-align:center;
overflow:hidden;
}
<div class="box">
<div class="box-header">
header
</div>
<div class="box-body">
<div class="window">
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
If you want to have a dynamic height of the header, you can dynamically calculate it in javascript.
Don't change .box height if you want the background image to resize, change .window height!
https://jsfiddle.net/t87tjmmk/
setInterval(function(){
var height = $(".box").height();
$(".window").height(height+2); }, 1000);
I achieved what you want here.
See Demo here
HTML
<div class="box">
<div class="box-header">
header
</div>
<div class="box-body">
<div id='w' class="window">
</div>
</div>
</div>
JavaScript
var w=document.getElementById('w');
var x=192;
setInterval(function(){
var height = $(".box").height();
$(".box").height(height+2);
w.style.minHeight=x+"px";
x+=2;
},90);
CSS
.box{
height: 100%;
background-color: #22ff2f;
width:350px;
}
.box-header{position:inherit; background-color:#9ed;width:100%;}
.box-body{}
.window{
background-position: center;
background-image: url('http://dailybestlike.com/wp-content/uploads/2015/07/simple-ideas-products-11.jpg');
min-height:190px;
width:100%;
height:100%;
position:relative;
text-align:center;
overflow:hidden;
background-repeat:no-repeat;
background-size: 100% 100%;
}

Resize image according to div width

I have a div width that resizes according to the browser width, right now it is set to 80%.
What I'm trying to accomplish is depending on the image size, I would like the image to take up the whole div width. If it's a small image, keep image size and center.
In my fiddle, any image width over 800px should start from the right and expand according to the div re-size. It should always touch the right side and expand with the div width.
If the image width is smaller than or equal to 500px, it should stay it's size and resize according to div but stay in middle of div only.
The problem is, I'm not sure how to only affect certain images, I would like a solution that detects the image size because the images might switch.
.parent{
border:1px solid purple;
height:100%;
width:80%;
float:Right;
}
.child{
border:1px solid red;
height:100%;
background:gray;
text-align:center;
}
.child-img{
display:inline-block;
max-width:100%;
margin:0 auto;
}
.image-wrapper{
width:100%;
background:orange;
}
img{
width:auto;
height:100%;
width:100%;
}
<div class="parent">
<div class="child">
<div class="image-wrapper">
<img src="http://cdn.bulbagarden.net/upload/thumb/0/0d/025Pikachu.png/250px-025Pikachu.png" alt="" class="child-img">
</div>
<div class="image-wrapper">
<img src="https://i.kinja-img.com/gawker-media/image/upload/unnbgkdbmsszmazgxkmr.jpg" alt="" class="child-img">
</div>
<div class="image-wrapper">
<img src="https://em.wattpad.com/62f9f1c9de49ad97d7834b1e58e16a99eb2dc3c7/687474703a2f2f6170692e6e696e672e636f6d2f66696c65732f7363525a66707a54694d7a4d48484e586b7247575277674b6878726537617531666736413834472d684c484c616c7271302d6f4152524f6f525a6e55387076415a41637a545a6b4c6442476f6144496336507834395030744245426d4a646e382f50696b616368752e66756c6c2e313435323733332e6a7067?s=fit&h=360&w=360&q=80" alt="" class="child-img">
</div>
<div class="image-wrapper">
<img src="http://vignette3.wikia.nocookie.net/scratchpad/images/0/02/Pikachu.gif/revision/latest?cb=20150217015901" alt="" class="child-img">
</div>
</div>
</div>
Try using jQuery to detect the image's size.
$('.child-img').each(function() {
if ($(this).width() > 800) { $(this).addClass('right'); }
else if ($(this).width() < 500) {$(this).addClass('center');}
});
And the required css would be:
.child-img.right {
display: block;
max-width: 100%;
}
.child-image.center {
width: auto;
max-width: 100%;
display: inline-block'
}
.parent { text-align: center; }
I think you should be able to place the image in the background of the div and make its width and height percentage values.
background: url(img_flwr.gif);
background-size: 100% 100%;
background-repeat: no-repeat;

Count the number of child div inside parent div and align the child divs in the middle of the parent div

I have 8 child divs inside a parent div. I have to count the width of the parent div and divide the width with the number of child width and place them in the middle of the parent div using javascript
You can get the width of the parent and split it into 8. Then you can set the width of the children by using .css('width'). In my example I set the height the same as the width, so you can clearly see there are 8 divs. If you want the height to be max, just set the css to 100%.
HTML
<div class="outer">
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
</div>
JS
var countDiv = $('.inner').length,
outerWidth = $('.outer').css('width').replace('px', ''),
singleWidth = outerWidth / countDiv + 'px';
$('.inner').css('width', singleWidth)
.css('height', singleWidth);
CSS
.outer {
background-color: red;
width: 200px;
height: 200px;
display: table-cell;
vertical-align: middle;
}
.inner {
box-sizing: border-box;
border: 1px solid black;
background-color: yellow;
float: left;
}
JSFiddle here

Div size = to another div

I have two divs. One div contains an image, and the other will contain a text caption that will be layed over the image.
How can I make the caption div width be equal to the image div in a fluid design?
The page is designed using a fluid layout and thus the image will can size with the browser size is changed.
<div id="captions">Captions</div>
<div id="image"></div>
Is there a way to do this in CSS?
You could put both elements into your div and then set the width
<div id="yourdiv">
<img id="yourimg" src="" />
<p class="yourtext">Here some Text</p>
</div>
and then set the width of .yourtext
.yourtext {
width: 100%;
}
FIDDLE
We may inverse the situation as follows:
HTML
<div id="captions">
Captions..
<div id="image"><img src="http://lorempixel.com/450/200/" /></div>
</div>
CSS
#captions{
background: #000;
color:#fff;
/* width:100%;*/
display:inline-block;
padding-bottom: 0px;
margin-bottom: 0px;
}
#image{
width: 100%;
padding-bottom: 0px;
margin-bottom: 0px;
}
#image img{
vertical-align: bottom;
}
This is a DEMO

Categories

Resources