table-cell adapt to image - html

I have this problem. I need that the yellow div adapts to the contained image; its width is dynamic, so I can't use a fixed width.
I can't find a solution anywhere, and I've tried with margin: 0; display:block; but nothing.
Here is the code:
HTML
<div class="columna" style="max-width: 100%;">
<div class="s_container seleccion_simple_default">
<div id="text_opcion">
<div class="ti-ab-d" style="display: table-cell;">
<label for="test" ><p>Prueba</p></label>
</div>
</div>
<div class="ssm_opcion img_opcion">
<img src="images/opciones/mcdonalds.png">
</div>
</div>
</div>
CSS
.s_container{
margin: auto;
width: 100%;
height: 100%;
border-spacing: 0px;
overflow: hidden;
border: none;
position: inherit;
display: table;
}
.ssm_opcion{
width: 1px;
max-width: 100%;
overflow: hidden;
display: table-cell;
vertical-align: middle;
background:yellow;
}
.img_opcion{
display:;
width: auto;
max-width: 100%;
}
.ssm_opcion img{
width: auto;
max-width: 100%;
height: auto;
vertical-align: middle;
}
#text_opcion{
width: 100%;
height:100%;
min-width: 50px;
text-align: left;
display: table;
float: left;
background:green;
}
.ti-ab-d{
vertical-align: bottom;
text-align: right;
}
.s_container {
margin: auto;
width: 100%;
height: 100%;
border-spacing: 0px;
overflow: hidden;
border: none;
position: inherit;
display: table;
}
.ssm_opcion {
width: 1px;
max-width: 100%;
overflow: hidden;
display: table-cell;
vertical-align: middle;
background: yellow;
}
.img_opcion {
display: ;
width: auto;
max-width: 100%;
}
.ssm_opcion img {
width: auto;
max-width: 100%;
height: auto;
vertical-align: middle;
}
#text_opcion {
width: 100%;
height: 100%;
min-width: 50px;
text-align: left;
display: table;
float: left;
background: green;
}
.ti-ab-d {
vertical-align: bottom;
text-align: right;
}
<div class="columna" style="max-width: 100%;">
<div class="s_container seleccion_simple_default">
<div id="text_opcion">
<div class="ti-ab-d" style="display: table-cell;">
<label for="test">
<p>Prueba</p>
</div>
</div>
<div class="ssm_opcion img_opcion">
<img src="images/opciones/mcdonalds.png">
</div>
</div>
</div>

You have some conflicting CSS in the snippets you provide, I've modified the code to remove the .img_opcion CSS you had in there. Image autosizes to the container nicely.
https://jsfiddle.net/Lvv7Lxrs/1/
EDIT: the width declaration is just to prove the container snaps to size, as the default "broken image" browser stand-in is a bit small.

If you add a div and in the div you put a paragraph inside the div, if you give to div such rules css a background-color: #color, the div fits automatically to the paragraph, you don't must you do not have mandatory put a width-height fixed.

Related

img positioning inside div container

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="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iwEkH9aLtdP9AIACwuSY5wBHxisrKMuY0MQajpy1SIVtEgfQH2FBN2aQkgZCp7cn+lZWUiz3J3YhtQFOmAmSBj27VE8xnAxXtZRWT3BBJn/9k=" height="70" width="120">
</div>
<div class="head-menu">
</div>
</div>

Centering multiple images horizontally and vertically using display: table

So using the display: table; technique I have centered a single image. The behaviour exhibited by this single image in the example is perfect for me; only I would like to also allow for multiple portrait images to be centered side by side in the container and centered in exactly the same manner.
.slider-container {
left: 75px;
right: 75px;
position: fixed;
top: 75px;
height: calc(100vh - 150px);
}
.slider-container .table {
display: table;
height: inherit;
width: 100%
}
.slider-container .table .col {
display: table-cell;
width: 100%;
height: inherit;
vertical-align: middle;
text-align: center
}
.slider-container .table .col img {
max-height: 100%;
max-width: 100%;
}
<div class="slider-container">
<div class="table">
<div class="col">
<img src="https://www.top-windows-tutorials.com/images/2013/04/2014-03-Windows-Xp-Bliss-wallpaper.jpg">
</div>
</div>
</div>
Jsfiddle here if you prefer.
This is close to what I am aiming for but would like to be able to control the size of the spacing between each image so that it is always a fixed amount – at the minute the table cells are wider than the images within them and this is cause the gap to be greater that it should be, depending on screen size:
.slider-container {
left: 75px;
right: 75px;
position: fixed;
top: 75px;
height: calc(100vh - 150px);
}
.slider-container .table {
display: table;
height: inherit;
width: 100%
}
.slider-container .table .row {
display: table-row;
width: 100%;
height: inherit;
vertical-align: middle;
text-align: center;
}
.slider-container .table .row .cell {
display: table-cell;
width: 33%;
height: inherit;
vertical-align: middle;
font-size: 0;
padding-right: 15px;
padding-left: 15px;
}
.slider-container .table .row .cell img {
max-height: 100%;
max-width: 100%;
}
.left-cell {
text-align: right;
}
.middle-cell {
text-align: center;
}
.right-cell {
text-align: left;
}
<div class="slider-container">
<div class="table">
<div class="row">
<div class="cell left-cell"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
<div class="cell middle-cell"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
<div class="cell right-cell"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
</div>
</div>
</div>
Jsfiddle here
As you can see the spacing changes between the images – I would like to set it as a controllable amount. The table cell size is currently larger than the image itself which I want to prevent.
Thanks,
.slider-container {
left: 75px;
right: 75px;
position: fixed;
top: 75px;
height: calc(100vh - 150px);
}
.slider-container .table {
display: table;
height: inherit;
width: 100%
}
.slider-container .table .col {
display: table-row;
width: 100%;
height: inherit;
vertical-align: middle;
text-align: center;
}
.slider-container .table .col img {
max-height: 100%;
max-width: 100%;
}
.third {
display: table-cell;
width: 33%;
height: inherit;
vertical-align: middle;
text-align: center;
}
<div class="slider-container">
<div class="table">
<div class="col">
<div class="third"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
<div class="third"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
<div class="third"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
</div>
</div>
</div>
I would suggest to simplify the structure a bit as shown below: Just have the table and a cell with three images inside it (no row necessary), and center the contents of that cell as you did. To avoid any space between the images, I added font-size: 0 for the cell:
.slider-container {
left: 75px;
right: 75px;
position: fixed;
top: 75px;
height: calc(100vh - 150px);
}
.slider-container .table {
display: table;
height: inherit;
width: 100%
}
.slider-container .table .col {
display: table-cell;
width: 100%;
height: inherit;
vertical-align: middle;
text-align: center;
font-size: 0;
}
.slider-container .table .col img {
max-height: 100%;
max-width: 100%;
}
<div class="slider-container">
<div class="table">
<div class="col">
<img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png">
<img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png">
<img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png">
</div>
</div>
</div>
You can use relative units (%) together with the transform property:
body {margin: 0}
.slider-container {
position: fixed;
left: 50%; /* moved right by 50% */
top: 50%; /* moved down by 50% */
transform: translate(-50%,-50%); /* moved left and up by 50% of its w/h to achieve the perfect center */
}
.slider-container .table {
display: table;
height: inherit;
width: 100%;
}
.slider-container .table .col {
display: table-cell;
width: 100%;
height: inherit;
vertical-align: middle;
text-align: center;
}
.third {
display: table-cell;
width: 33.33%; /* modified for accuracy */
height: inherit;
vertical-align: middle;
text-align: center;
}
.third > img { /* modified */
display: block; /* removes bottom margin/whitespace */
max-width: 100%;
max-height: 100vh; /* modified, vertical responsiveness */
}
<div class="slider-container">
<div class="table">
<div class="col">
<div class="third"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
<div class="third"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
<div class="third"><img src="https://cosmic-s3.imgix.net/f1ed4d70-f2db-11e7-bf63-ff4a4a43daf9-Screen%20Shot%202018-01-06%20at%2012.19.20.png"></div>
</div>
</div>
</div>

Margin auto doesn't apply to whole inside content

Here is a content inside: <div class="traki"> </div>
I add following css:
.traki {margin-left: auto !important;
margin-right: auto !important;}
}
And goal is to set inside content center. but it doesn't apply, demo: http://buhehe.de/kalender-2018/
You cannot do an "auto" margin to vertically center an element.
There is a workaround though, you could try this:
.container {
display: table;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
}
.helper {
#position: absolute;
#top: 50%;
display: table-cell;
vertical-align: middle;
}
.content {
#position: relative;
#top: -50%;
margin: 0 auto;
width: 200px;
border: 1px solid orange;
}
<div class="container">
<div class="helper">
<div class="content">
<p>stuff</p>
</div>
</div>
</div

CSS: Make object-fit work with min-height

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.

HTML - center fixed element and provide width of the parent

I want to center a fixed div inside its parent. The width of the fixed div should have the width of its parent. But it does not work, what is wrong?
js fiddle
HTML
<div class="container">
<div class="wrap">
<div class="center" >
centered
</div>
</div>
</div>
CSS
.container {
position: relative;
width: 300px;
height: 400px;
border:solid;
margin-right: auto;
margin-left: auto;
padding-left: 15px;
padding-right: 15px;
}
.wrap {
height: 800px;
width: 100%;
position: relative;
text-align: center;
}
.center{
background: red;
position: fixed;
bottom: 100px;
width: inherit;
}
change .wrap's width:
.wrap {
height: 800px;
width: inherit;
position: relative;
text-align: center;
}