Understanding how child elements inherit parent css properties - html

I have a lack of understanding how the css settings of a parent restrict its children.
Simple example:
I have a container with three buttons.
play button
fast forward button
fast backwards button
My goal is the following:
create a grid 1x3 (row x column)
aling buttons inside of the grid
With this I went to work and ended up here:
.adaptations {
margin-bottom: 20px;
}
.video-button-container {
height: 100px;
width: auto;
display: grid;
grid-template-columns: 33% 33% 33%;
}
.video-button {
height: 100%;
}
.video-button img {
height: 70%;
}
<div class="adaptations video-button-container">
<button type="button" class="video-button">
<img src="https://e7.pngegg.com/pngimages/552/785/png-clipart-smile-mouth-love-white.png">
</button>
<button type="button" class="video-button middle-button">
<img src="https://e7.pngegg.com/pngimages/552/785/png-clipart-smile-mouth-love-white.png">
</button>
<button type="button" class="video-button">
<img src="https://e7.pngegg.com/pngimages/552/785/png-clipart-smile-mouth-love-white.png">
</button>
</div>
Here's my problem: I managed to implement the said goal with fixed sizes (width, height). However, it is not desireable since screen sizes differ, hence, make it responsive and here lies my problem.
What I learned is that if I set my parent-div to height: 100px; the child elements will adjust themselves inside that div. Therefore I said height: 100%. Which sounds like (as far as I understand this): "You can use all the height that is available to you, therefore max. 100px)
Can you enlighten me on what I am missing?

I hope this is what you are trying to achieve.
.adaptations {
margin-bottom: 20px;
}
.video-button-container {
height: 100px;
width: auto;
display: grid;
grid-template-columns: 33% 33% 33%;
}
.video-button {
height: inherit; /* Use 'inherit' here instead of '100%' */
}
.video-button img {
height: 70%;
}
<div class="adaptations video-button-container">
<button type="button" class="video-button">
<img src="https://e7.pngegg.com/pngimages/552/785/png-clipart-smile-mouth-love-white.png">
</button>
<button type="button" class="video-button middle-button">
<img src="https://e7.pngegg.com/pngimages/552/785/png-clipart-smile-mouth-love-white.png">
</button>
<button type="button" class="video-button">
<img src="https://e7.pngegg.com/pngimages/552/785/png-clipart-smile-mouth-love-white.png">
</button>
</div>

Related

how can i make my button clickable area bigger

i wanna know why my button clickable area is bugged, i can only click a small area, and it works terrible.
<button class="btn btn-primary btn-dark boton-carrito" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight"><img src="../multimedia/shopping-cart.png" alt="" class="foto_carrito"></button>
.boton-carrito {
width: 50px;
height: 50px;
margin-left: 15px;
display: block;
}
.foto_carrito {
width: 36px;
height: 36px;
margin-left: -8px;
}
Im using bootstrap too.
Perhaps if you make the area of your button bigger using padding (options: p-1, p-2, p-3, p-4, p-5) instead of using "boton-carrito"?
class="p-2"
if you're using React JS:
className="p-2"
Good luck!
try to using min-height and min-width
it will change the minimum size of your button component.
.boton-carrito {
display: block;
min-width: 50px;
min-height: 50px;
margin-left: 15px;
}
.foto_carrito {
min-width: 36px;
min-height: 36px;
margin-left: -8px;
}
<button
class="btn btn-primary btn-dark boton-carrito"
type="button"
data-bs-toggle="offcanvas"
data-bs-target="#offcanvasRight"
aria-controls="offcanvasRight">
<img
src="../multimedia/shopping-cart.png"
alt=""
class="foto_carrito" />
</button>
Here was the docs link for min-width and min-height for more information.
Thank you

How to set a normal height for uk-body in uk-modal?

I'm trying to make a functional modal window using uiKit. This is a modal:
This is its body:
Here is a code I wrote for this modal:
<div id="adjust-export-modal" uk-modal>
<div class="uk-modal-dialog" style="width: 100%; height: 100%;">
<div style="width: 100%; height: 100%;">
<button
class="uk-modal-close-default"
type="button"
uk-close
#close
></button>
<div class="uk-modal-header">
<h2 class="uk-modal-title">Adjust exported report</h2>
</div>
<div class="uk-modal-body" style="/*width: 100%; height: 100%;*/ padding: 0">
<app-report-grid
[companyId]="companyId"
></app-report-grid>
</div>
</div>
</div>
</div>
<app-report-grid> is not functional at the screenshots, but when it is, it takes all the blue space of uk-modal-body and takes away all the bottom margin.
What should I do to make uk-modal-body stay inside the modal edges? Or there is a different possible option: what should I do to make uk-modal-body expand exact modal and make it scrollable, without taking away the bottom margin?
Try by adding a specific height and width to uk-modal-dialog
.uk-modal{
display:block;
}
.uk-modal-dialog {
width: 60vw;
min-width: 600px;
height: 500px;
}
This will make your inside modal context understand that 100% is 100% of its actual size, because sometimes when everthing is set to 100% it just render default values.
Also add display:block to modal if it's not that way.
If that doesn't work, try by setting size to .uk-modal-body and then set .uk-modal-dialog's height to height: fit-content. This will auto-adjust dialog height to its content size.
.uk-modal-dialog{
height: 500px;
max-height: 500px;
width: 600px;
max-width: 600px;
}
.uk-modal-dialog {
width: fit-content;
height: fit-content;
}

How do I remove the extra space on the right side of this bootstrap 4 modal?

Here is the fiddle: https://jsfiddle.net/apo5u0mt/
Here is the code:
HTML
<div class="modal" id="galleryModal">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl">
<div class="modal-content">
<div class="gallery">
<div class="gallery-item">
<img src="https://preview.ibb.co/kPE1D6/clouds.jpg">
</div>
<div class="gallery-item">
<img src="https://preview.ibb.co/mwsA6R/img7.jpg">
</div>
<div class="gallery-item">
<img src="https://preview.ibb.co/kZGsLm/img8.jpg">
</div>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#galleryModal">
Modal
</button>
CSS
.gallery {
overflow-y: auto !important;
}
.gallery-item {
margin: 5px;
float: left;
}
.gallery-item img {
height: 150px;
width: 200px;
object-fit: cover;
}
.btn {
margin: 5px;
}
There is some extra space on the right side of the modal. I do not want that space. I want the modal to fit the contents, which are images. I have been staring at this for entirely too long, and would appreciate any help.
Bootstrap is doing this:
.modal-dialog {
max-width: 500px;
}
The .modal-dialog element is a block element, and thus wants to be 100% width by default, but Bootstrap's styling is keeping it to 500px wide.
You're explicitly setting your images to be 200px wide each, which (ignoring margins for the moment) only adds up to 400px.
Two possible fixes are:
1. Override Bootstrap's modal styling here to constrain the modal to a narrower width:
/*
The value below is empirically tested,
allows for your given margins & floating. I originally expected it to be
420px = (200px width + 5px left margin + 5px right margin) * 2
but 422px was necessary to avoid wrapping when tested in jsfiddle
*/
.modal-dialog {
max-width: 422px;
}
https://jsfiddle.net/nftj9s7y/1/
If images being exactly 200px wide is what matters, then that's your solution. However, that seems like a brittle solution to me - it'll break if you decide to change image widths, and might not work at smaller screen sizes.
The more flexible solution would be:
2. Use flexbox to have images expand to fill the modal
.gallery {
display: flex;
flex-wrap: wrap;
padding: 5px;
}
/* now that the parent element is display: flex, we don't need floats anymore */
.gallery-item {
padding: 5px;
width: 50%;
}
.gallery-item img {
height: 150px;
object-fit: cover;
width: 100%; /* allow image to fill width of containing element */
}
https://jsfiddle.net/vzs98n6b/2/
And as a final note, .gallery { overflow-y: auto } won't have any effect unless you specify a height or max-height on that element.

How to center align 3+ divs dynamically in rows of 3?

I'm trying to center dynamically generated divs (containing other divs and dynamic content), and have them align horizontally with up to 3 in a row, currently they're in line, but are not centered in parent div(ie. there is leftover space to the right). I've used alot of methods on other posts to no avail. Any help would be fantastic! :)
HTML: (PHP will generate any number of these)
<div id="div$j" class="divs">
<div class="image_ratio">
<img src="photos/Asset 1-100.jpg" onerror="this.src='Social_Icons/Rectangle 157#2x.png'">
</div>
<h3><?php echo $name; ?></h3>
<form type="text" name="form$j" id="form$j" action="AJAX.php" method="post">
<div class="aligner">
<button type="button" class="button_div")">X</button>
<button type="button" class="button_div">Y</button>
<button type="button" class="button_div">Z</button>
</div><br>
<input type="hidden"/>
<input type="hidden"/>
</form>
</div>
and all of these divs are wrapped together in:
<div class="BAJAX">.....</div>
CSS:
.BAJAX {
grid-area: pieces;
border: solid;
}
.image_ratio {
position: relative;
width: 25vmin;
height: 35vmin;
}
.image_ratio img {
margin: 0 auto;
width: 100%;
height: 100%;
object-fit: cover;
}
.divs {
width: 25vmin;
z-index: 98;
display: inline-block;
padding: 2.5%;
float: left;
margin: 0 auto;
border: solid;
}
Your best bet is to use flexbox. Your container (parent) will have display: flex and justify-content: space-between (so items can fill the space evenly). Then on each individual item (child) you will be setting flex-basis: 33% (or less as you will want items to have some margin/padding to delimit one from the other).
More info on this: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Demo: https://codepen.io/Manu92/pen/PvvdMp
Instead of <div class="aligner"> use <div class="row">.
https://getbootstrap.com/docs/3.4/css
Also you can add it inside tag <h3>.

How to fit IMG in parent DIV where its height is not set?

I have this situation: I want to make a IMG height to be fit with its parent DIV where no height is set. This is the sample code:
.box_NewsList {
width: 100%;
background: #ffa;
overflow: hidden;
display: inline-block;
}
.box_NewsList>img {
height: 100%;
display: inline-block;
}
.box_NewsPreview {
padding: 15px;
width: auto;
}
.box_NewsPreview>.tit_News {
font-size: 1.5rem;
line-height: 1.5rem;
position: relative;
margin: -15px 0 15px;
padding: 15px 0 0;
background: transparent url(../imgs/main_menu_hover.png) no-repeat top left;
}
<div class="box_NewsList">
<img class="pull-left" src="mypicture.jpg">
<div class="box_NewsPreview">
<h1 class="tit_News">MyTitle</h1>
<div class="txt_Abstract">
<p>Long text abstract here</p>
</div>
<button class="btn btn-default btn-rounded pull-right">READ</button>
</div>
<div class="clear"></div>
</div>
How can I make the img height to fit the height of div with box_NewsPreview class?
.box_NewsPreview>.txt_Abstract p{color:#7e7e7e;font-family:Roboto, sans-serif;font-size:1rem;font-weight:300;text-align:justify;}
If I add a height value in box_NewsList like height:300px; it works fine.
If I set height:auto, height:initial, height:inherit or I don't add any height value in that class then I get the IMG in its full size instead of resizing in its parent height.
I think the easiest way to acheive what you want is to use a little jQuery. I dont think it is possible with pure CSS
I have made an example where i set position: relative; on .box_NewsList and position: absolute; on .box_NewsList>img
and the this little script to loop through the images and give padding to the text:
$('.box_NewsList').each(function() {
var imageWidth = $(this).find('img').width();
$(this).find('.box_NewsPreview').css('padding-left', imageWidth + 15);
});
Here is a fiddle
try
<div class="box_NewsList">
<div class="box_NewsPreview">
<img class="pull-left" src="mypicture.jpg" stretch="fill">
<h1 class="tit_News">MyTitle</h1>
<div class="txt_Abstract"><p>Long text abstract here</p></div>
<button class="btn btn-default btn-rounded pull-right">READ</button>
</div>
<div class="clear"></div>
</div>
It looks like <img> was inside news_list not news_preview.
I added stretch to the img, so no matter what it will always stretch to the size of the div :)