Is there any way to make object-fit work with min-height?
See this jsfiddle for example.
If I set a fixed height, it works, but if I set a min-height, it doesn't work.
HTML:
<div class="container">
<div class="b_feat_img">
<img src="http://i.imgur.com/iEJWyXN.jpg">
</div>
</div>
CSS:
.container {
width:120px;
}
.b_feat_img {
border: 1px solid green;
background: red;
float: left;
height: auto;
min-height:130px;
margin-bottom: 10px;
overflow: hidden;
width: 100%;
}
.b_feat_img img {
object-fit: cover;
height: 100%;
width: 100%;
}
The min-height needs to set on the img element, not the container.
In additional, you can also set vertical-align:top or display:block on the img to get rid of the unwanted whitespace below it.
.container {
width:120px;
}
.b_feat_img {
border: 1px solid green;
background: red;
float: left;
height: auto;
margin-bottom: 10px;
overflow: hidden;
width: 100%;
}
.b_feat_img img {
object-fit: cover;
min-height: 130px;
width: 100%;
vertical-align: top;
}
<div class="container">
<div class="b_feat_img">
<img src="http://i.imgur.com/iEJWyXN.jpg">
</div>
</div>
You can use position: absolute to the img in css.
So it will be like:
HTML:
<div class="container">
<div class="b_feat_img">
<img src="http://i.imgur.com/iEJWyXN.jpg">
</div>
</div>
CSS:
.container {
width:120px;
}
.b_feat_img {
position: relative;
border: 1px solid green;
background: red;
float: left;
width: 100%;
min-height:130px;
margin-bottom: 10px;
overflow: hidden;
}
.b_feat_img img {
position: absolute;
height: 100%;
width: auto;
}
fiddle:
https://jsfiddle.net/b93txe6t/1/
Hope that helps.
Related
How can I change image size of second div in CSS changing only square? with the same class but different div?
<div class="square"> <img class="square__img" src="square.png"> </div>
<div class="square square--small"> <img class="square__image" src="square.png"> </div>
Try this
.square {
width: 300px; /*standard image size*/
}
.square.square--small {
width: 150px; /*small image size*/
}
.square.square--small .square__image { /*apply change only to small img*/
width: 100%;
height: auto;
}
hello you can use this css selector:
.square img
{
width:100px;
height:100px
}
.square.square--small img{
width:50px;
height:50px
}
Make image to not overlap the div by setting its max-width to 100%, max-height to 100%
and height to auto like this:
max-width: 100%;
max-height: 100%;
height: auto;
then style your division elements like this for example:
.square {
width: 300px;
height: 300px;
margin: 30px;
}
.square.square--small {
width: 200px;
height: 300px;
}
Again, width and height are only for demonstration, modify as you like.
img of working code
<div class="square">
<img class="square__img" src="square.png" alt="img1">
</div>
<div class="square square--small">
<img alt="img2" class="square__image" src="square.png">
</div>
.square {
border: 1px solid red;
height: 200px;
width: 200px;
margin-bottom: 20px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
float: left;
margin-right: 20px;
}
.square img {
width: 100px;
border: 1px solid green;
display: inline-block;
height: 100px;
}
.square--small {
border: 1px solid black;
}
.square--small img {
border: 1px solid red;
height: 150px;
width: 150px;
}
Can't get img inside "head-logo" div to center both vertically amd horizontaly.
i tryed CSS solutions like:
1)
.head-logo img {
margin-left: auto;
margin-right: auto;
display: block;
}
2)
.head-logo img {
vertical-align: middle;
}
3)
.head-logo img {
display: -webkit-flex;
display: -ms-flex;
display: flex;
justify-content: center;
-ms-align-items: center;
align-items: center;
}
etc
<div class="head-container">
<div class="head-logo">
<img src="img\logo.svg" height="70" width="70">
</div>
<div class="head-menu">
</div>
</div>
div {
border: dotted 1px;
}
.head-container {
width: 80%;
height: 100px;
margin: auto;
padding: 5px;
background-color: aqua;
}
.head-logo {
vertical-align: middle;
width: auto;
height: 100px;
background-color: red;
float: left;
}
.head-logo img {
}
Current result is img is stuck to upper left corner of parent div, and I need it centered from all sides.
Probably I'm missing something, quite new to css, looking forward for your help.
div {
border: dotted 1px;
}
.head-container {
width: 80%;
height: 100px;
margin: auto;
padding: 5px;
background-color: aqua;
}
.head-logo {
vertical-align: middle;
width: auto;
height: 100px;
background-color: red;
float: left;
}
.head-logo img {
}
<div class="head-container">
<div class="head-logo">
<img src="https://via.placeholder.com/150x200/O%20https://placeholder.com/" height="70" width="70">
</div>
<div class="head-menu">
</div>
</div>
There is few ways of doing it. My preferred one is this
div {
border: dotted 1px;
}
.head-container {
width: 80%;
height: 100px;
margin: auto;
padding: 5px;
background-color: aqua;
}
.head-logo {
width: 100px;
height: 100px;
background-color: red;
float: left;
overflow: hidden;
position: relative;
}
.head-logo img {
position: absolute;
width: 100%;
height: auto;
top: -50%;
right: -50%;
bottom: -50%;
left: -50%;
margin: auto;
}
<div class="head-container">
<div class="head-logo">
<img src="https://placeholder.com/wp-content/uploads/2018/10/placeholder.com-logo1.png" height="70" width="70">
</div>
<div class="head-menu">
</div>
</div>
Benefits of this solution is that it will always stay at center of parent container it works well in older versions of browsers u can set img width to fixed like "100px" if u want to logo stay at same size or set it to scale to parent container
overflow: hidden; in parent container make sure that bigger picture will not spill out off container
div{
height: 300px;
width: 300px;
padding: 10%;
background: red;
box-sizing: border-box;
}
div img{
height: 100%;
width: 100%;
}
<div>
<img src="https://media.gettyimages.com/photos/trent-boult-of-new-zealand-bowls-during-day-two-of-the-second-test-picture-id1087035928" alt="">
</div>
You could try object-fit - like:
.head-logo img {
object-fit: contain;
height: 100%;
}
Object-fit demo (including image polyfill for ie) https://codepen.io/jakob-e/pen/Pxwzpw
/* object fit polyfill */
// is object fit supported
if (document.body.style.objectFit === undefined) {
// loop through all images
[].slice
.call(document.querySelectorAll('img'))
.map(function (img) {
// image has background-size cover or contain
if (['cover', 'contain']
.indexOf(getComputedStyle(img).backgroundSize) !== -1) {
// use src as background image
img.style.backgroundImage = "url(" + img.src + ")";
// replace src with transparent gif
img.src = 'data:;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
}
});
}
/* add this */
.head-logo img {
height: 100%;
object-fit: contain;
background-size: contain; /* used by polyfill */
background-repeat: no-repeat; /* used by polyfill */
}
div {
border: dotted 1px;
}
.head-container {
width: 80%;
height: 100px;
margin: auto;
padding: 5px;
background-color: aqua;
}
.head-logo {
vertical-align: middle;
width: auto;
height: 100px;
background-color: red;
float: left;
}
<div class="head-container">
<div class="head-logo">
<img src="https://i.pinimg.com/originals/33/b8/69/33b869f90619e81763dbf1fccc896d8d.jpg" height="70" width="70">
</div>
<div class="head-menu">
</div>
</div>
Try this: (ignore long image link :p)
div {
border: dotted 1px;
}
.head-container {
width: 80%;
height: 100px;
margin: auto;
padding: 5px;
background-color: aqua;
}
.head-logo {
width: 150px;
height: 100px;
background-color: red;
float: left;
display: flex;
justify-content: center;
}
.head-logo img {
display: block;
margin: auto;
vertical-align: middle;
}
<div class="head-container">
<div class="head-logo">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMTEhUTExMWFhUWGBgaGBgYFxcXGhcaFRgWFxYYGhcYHSggGBolHRcYITEhJSkrLi4uFx8zODMtNygtLisBCgoKDg0OGxAQGy0lICUtLS0tLS8vLS0tLS0tLy0tLS8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLf/AABEIAKgBLAMBIgACEQEDEQH/xAAcAAACAgMBAQAAAAAAAAAAAAAEBQMGAAIHAQj/xAA7EAABAwMDAgUCAwcEAgIDAAABAgMRAAQhBRIxQVEGEyJhcYGRMkKhBxQjscHR8FJi4fEVM2NyCBZD/8QAGQEAAwEBAQAAAAAAAAAAAAAAAgMEAQUA/8QAKhEAAgICAgEFAAEEAwEAAAAAAQIAEQMhEjEEEyJBUWHwMkJxkYGx0RT/2gAMAwEAAhEDEQA/AK4gCiEtiKSs3ChzR9u/NcUgzmydy3FSNLgVC9cxivFLkV6oStUx+6pa/fkmK3WsTWjduFGiCgRZM2t1lRptaigi0ECsauKE76mVC79cCkodVuoi9u5wakZWkJowKEIpJbe+20arUhFVq6fyYo6yttwyaFkFWYvjDE3wJo0O4pbb6ad+TTK4YKE0pq6E2oE67mnemBBGaqt3c596I0/UVpHtT0x2JT46i9iW13YOKjeCVCqvd6r1qS01OaW2MiLyMVNRmu2E1hZisRdCKGfu6XsxXO4Q4zIpVdGKJTqA4NKdSuZ4pmNDc3ueLuBQ7t2e9Jnbog1qLqqvRPcP0jHSdRI4rYakTzShl8VOVisOIfU8VqWOzfMUa0/mDSKwuKeWyN0VK44mLYVNr8SKSs2hKqsqraRQjLMKoUeCDIxZlOYqO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ygIMx3rKyosrkkTm53OiI10bUg2SRwecfejtU1FDowAZ/SsrK0ZWOpTj8rIQFO4Oy6iOBVe8R6eHxAMc+1ZWU1shqdHNnPpHQle/8CC2ESSEgDPXndPseI961YB9TZEiUz79yfevaylLkY3c4mPIxsSC0sIDi4MFwr+iwEkH9aLtdP9AIACwuSY5wBHxisrKMuY0MQajpy1SIVtEgfQH2FBN2aQkgZCp7cn+lZWUiz3J3YhtQFOmAmSBj27VE8xnAxXtZRWT3BBJn/9k=" height="70" width="120">
</div>
<div class="head-menu">
</div>
</div>
another newbie question here. Learning CSS. I am trying to do something that I thought would be very simple, but have not managed to find the way to do it, or a suitable answer to the question.
I have a simple project with a header, some content and a footer. The content has a div with a white border and an image inside it. I would like the div to be as wide as the image and no wider. I have provisionally set the width to 430px, but I would like to know the code to set the width to whatever the width of the image is.
Code
html
html,
body {
margin: 0px;
padding: 0px;
height: 100vh;
}
#header {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#footer {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#container {
height: 80%;
width: 100vw;
background-color: red;
}
#imagewrap {
position: relative;
border: 1px solid white;
width: 430px;
display: block;
margin: 0 auto;
top: 50%;
transform: translateY(-50%);
}
<div id="header"> </div>
<div id="container">
<div id="imagewrap">
<img src="Images/01Folder/Image.jpg" height="100%" id="front" />
</div>
</div>
<div id="footer"> </div>
Add display: inline-block; to your .imagewrap without setting it's width.
.imagewrap {
display: inline-block;
}
If you want a div with an image to be centered, add another div around them with:
.wrapper {
display: flex;
justify-content: center;
align-items: center;
}
But do you really need that div around an image? The border might be added to an image itself without additional div.
If you want a border on the image, add it there
html,
body {
margin: 0px;
padding: 0px;
height: 100vh;
}
#header {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#footer {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#container {
height: 80%;
width: 100vw;
background-color: red;
}
#imagewrap {
position: relative;
/*border: 1px solid white;
width: 430px;
display: inline-block;
line-height: 0;
margin: 0 auto;*/
top: 50%;
transform: translateY(-50%);
text-align: center; /*center image horizontally*/
}
#imagewrap img {
border: 1px solid white;
}
<div id="header"> </div>
<div id="container">
<div id="imagewrap">
<img src="https://unsplash.it/100/100" height="100%" id="front" />
</div>
</div>
<div id="footer"> </div>
Check out this fidde:
https://jsfiddle.net/56myv9g2/1/
#imagewrap img{
display:block;
}
#imagewrap{
position: relative;
border: 1px solid white;
display: inline-block;
margin: 0 auto;
top: 50%;
transform: translateY(-50%);
}
#container {
height: 80%;
width: 100vw;
text-align:center;
background-color: red;
}
Also, you could just give the border to the image tag all along without the div
If you set display: inline-block, then you need to add text-align: center to container
html,
body {
margin: 0px;
padding: 0px;
height: 100vh;
}
#header {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#footer {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#container {
text-align: center;
height: 80%;
width: 100vw;
background-color: red;
}
#imagewrap{
position: relative;
border: 1px solid white;
width: 430px;
display: inline-block;
top: 50%;
transform: translateY(-50%);
}
<div id="header"> </div>
<div id="container">
<div id="imagewrap">
<img src="Images/01Folder/Image.jpg" height="100%" id="front" />
</div>
</div>
<div id="footer"> </div>
I am trying to wrap my right div around my left, in an inverse moon shape? Here's what it looks like right now.
What I want to do is have the red block wrap around the rounder corners of the black block. Here is the current HTML/CSS code, I apologize if the CSS code is a little "messy" as i have been experimented different codes.
HTML
<div class="container full-width">
<div class="row proj">
<div class="col-md-8 full-width">
<div class="content">
</div>
</div>
<div class="col-md-4 full-width">
<div class="options">
</div>
</div>
</div>
</div>
CSS
.content {
margin-top: 75px;
position: relative;
width: 70vw;
max-width: 100%;
height: 90vh;
max-height: 100%;
overflow: hidden;
background-color: black;
border-radius: 0 50vw 50vw 0;
}
.options {
margin-top: 75px;
position: relative;
width: 30vw;
max-width: 100%;
height: 90vh;
max-height: 100%;
overflow: hidden;
background-color: red;
}
.container .full-width{
padding-left: 0;
padding-right: 0;
overflow-x: hidden;
}
UPDATE
Answer Found, thanks for the help, so had to tweak the code a bit from your posted code, it looks like this now.
.content {
margin-top: 75px;
width: 30vw;
height: 90vh;
overflow: hidden;
background-color: black;
border-radius: 0 50vw 50vw 0;
float:left;
position:relative;
z-index:2;
}
.options {
margin-top: 75px;
margin-left:3%;
position:relative;
float:right;
width: 30vw;
height: 90vh;
max-height: 100%;
overflow: hidden;
background-color: red;
}
.container .full-width{
position: absolute;
padding-left: 0;
padding-right: 0;
}
and the final result looks like this, will tweak the positioning some more but the result is what i wanted, thanks again.
UPDATE 2
Ok, had to make another edit, for some reason I had to float them both left. OTherwise if i kept the red div float right and tried to expand its width, it would expand to the left, any idea why? current code:
.content {
margin-top: 75px;
width: 44vw;
height: 90vh;
overflow: hidden;
background-color: black;
border-radius: 0 50vw 50vw 0;
float:left;
position:relative;
z-index:2;
}
.options {
margin-top: 75px;
margin-left:20%;
position:relative;
float:left;
width: 50vw;
height: 90vh;
max-height: 100%;
overflow: hidden;
background-color: red;
}
.container .full-width{
position: absolute;
padding-left: 0;
padding-right: 0;
}
Use position:relative; for content and position:absolute; for options
.content {
width: 30vw;
height: 90vh;
overflow: hidden;
background-color: black;
border-radius: 0 50vw 50vw 0;
float:left;
position:relative;
z-index:2;
}
.options {
margin-left:3%;
position:absolute;
float:right;
width: 30vw;
height: 90vh;
max-height: 100%;
overflow: hidden;
background-color: red;
}
<div class="container full-width">
<div class="row proj">
<div class="col-md-8 full-width">
<div class="content">
</div>
</div>
<div class="col-md-4 full-width">
<div class="options">
</div>
</div>
</div>
I have a div with class container. I have 3 more divs inside .container. What I want is to display internal divs float: left so that 2 divs tags are visible inside .container and the third one is invisible and is placed on the right side of first 2 div tags which are visible. I am trying the following code but it makes all tags visible all the time.
jsfiddle
<div class="container">
<div class="div"></div>
<div class="div"></div>
<div class="div"></div>
</div>
css
.container {
position: relative;
width: 405px;
height: 500px;
background: red;
margin: 0 auto;
overflow: hidden;
}
.div {
width: 200px;
height: 200px;
background: blue;
float: left;
border: 1px solid red;
}
I want above to look like this
You can do as such in other way,
HTML
<div class="container">
<div class="innerContainer">
<div class="div"></div>
<div class="div"></div>
<div class="div"></div>
</div>
</div>
CSS
.container {
position: relative;
width: 405px;
height: 500px;
background: red;
margin: 0 auto;
overflow: hidden;
}
.innerContainer {
position: relative;
width: 605px;
height: 500px;
overflow: hidden;
}
.div {
width: 200px;
height: 200px;
background: blue;
float: left;
border: 1px solid red;
}
Check over here http://jsfiddle.net/nftp6/8/
Use:
display: inline-block;
white-space: nowrap;
For that effect
Fiddle:
http://jsfiddle.net/Hive7/nftp6/5/
Use display:inline-block instead of float and set white-space:nowrap to the container:
.container {
position: relative;
width: 405px;
height: 500px;
background: red;
margin: 0 auto;
overflow: hidden;
white-space: nowrap;
}
.div {
width: 200px;
height: 200px;
background: blue;
display: inline-block;
border: 1px solid red;
}
Demo fiddle
Now you'll most likely face some white-space issues, read this answer for multiple ways to handle that