I'm trying to make a div height the same width as a col-md-3 in bootstrap so that as the page adjusts it keeps its "squareness". Outside of bootstrap I use vw, but that's not the case here and height 100%; doesn't work. Any ideas?? Needs to be simple and dynamic.
Bootstrap make same height as width. Width of the colum is added to padding so that you can get a squared box
.col-md-3{width:25%; padding:25%;}
https://jsfiddle.net/SHABU89/gee3mzsy/
It has been answered before from what I see.
div {
background:orange;
width:?%;
padding-top:?%;
}
width = padding=top
See here css height same as width
Related
How to maximize div width in browser screen in reactjs.
As you can see there's a small margin in left and right of the div container even I set the width to 100vw. And I use container fluid. How can I maximize the width of div container to fill the width of the browser screen
Make sure the margin of the body of the page is set to 0.
body {
margin: 0;
}
Also worth mentioning that Bootstrap's container and container-fluid have a small amount of horizontal margin on either side. You might want to override this.
user have ability to set height of some div in "px". And if he do that, than some div have height like this:
height: 245px;
but if this is done, then height stays the same which is not good for responsive design. Because i want that that div needs to adjusts to the conditions of responsive design.
So my question is what could I do in css to make div responsive ?
that later the height of div adjusts to the conditions of responsive design.
therefore, the height of div does not need to be fixed.
I have also tried this:
height: 100vw;
max-height: 245px;
but this also not works, as div stays at height of 245px.
Thank you
Convert the PXto %, so it will be responsive.
use the formula:
size-in-pixel/Screen-Size*100 = it gives the percentage
in your code in place of the size in pixel enter the value in percentage
I have an image something like below.
<img src="file.jpg" />
Below is the css code
img {
max-width: 100%;
height: auto;
}
Can anyone explain me on how does this css code make the images responsive, I mean scale it perfectly. I want to know the working behind this css code.
When your parent width is smaller than width of image, image width will take 100% of parent width.
If parent width is bigger than image width, image width will stay original.
Same with max-height. Also min-width/min-height will ensure that width/height will not be smaller than specified.
height: auto; will preserve aspect ratio for image. If you set both max-height and max-width or set height to specific size than image will be stretched
When you apply max-width:100%; to any element then that perticular element could have maximum 100% width of its parent, thus it can give you gaurantee that child will never go out of parent's bounds.
Thus if parent has suffitient width then child is shown in it's original size, otherwise it's width is matched to the parent. Thus it make our layout responsive.
Here is example : http://jsfiddle.net/xxn2hfuL/
I'm trying to make a menu for a mobile landing site.
The problem I'm having is that the items inside the divs are being set to height bigger than the containing div, which is screwing up the vertical align. I've tried many different things in order to manually set a height, but nothing is working. I've also tried setting margins and padding to 0. Nothing has worked.
Code:
<div id="menu">
<div><span><h4><a class="menuItem" href="find-us.html">Find us</a></h4></span></div>
<div><span>Promos</span></div>
<div><span>Events</span></div>
<div><span>Gallery</span></div>
</div>
http://jsfiddle.net/milkman15/r6VDe/1/
You can set a min height on the div and remove the css for the span inside
http://jsfiddle.net/mx28a/1/
#menu div{
font-size:2.5em;
width:93%;
height:14%;
margin-top:7%;
display:inline-block;
background:rgba(000,000,000,0.6);
text-transform:uppercase;
min-height: 60px;
}
I added the min-height as the last item. Since the divs are set using percents, when the height of the screen becomes smaller your div's height also becomes smaller. Your font are simply too large for the divs so it bleeds out when you reduce the height of the window. By setting a min-height, you can stop this from happening
I have a header/footer <div> that is 100% width. If I make the widows small enough so that horizontal scrollbar appears, and then scroll to the right most of the page, I can see the footer breaks at some point and leave an empty white space as if its width is fixed.
http://jsfiddle.net/enxRw/
Am I missing any CSS property? Do I need an extra wrapper <div>? Do I need JavaScript to check window width and adjust accordingly?
Edit:
The width:1024px for main <div> is on purpose because its content is 2 X 500px images side by side and I don't want them to wrap when windows is resized down.
Instead of having the width set on the .main div, set it on the body:
body {
min-width: 1024px;
}
Here's your fiddle: http://jsfiddle.net/enxRw/1/
Yes you can go with a wrapper div. Or you can specify a min-width on the body element.
Percentage widths are calculated as a percentage of the parent node. In this instance that is the body node.
Since you have not set a width on the body node it is calculated to be the width of the viewport. (You can check that out by looking at the body node in an inspector)