body is not covering full page - html

What can I do to make the body cover the whole page? In my CSS for body and html height and width 100%.
With the mobile version, the body is reduced in this way
With the pc version, everything is fine with the width, but the height is not on the whole page
html {
overflow: auto;
height: 100%;
width: 100%;
}
body {
background-color: #1c1c1c;
font-family: 'Press Start 2P', cursive;
}
Here is my full html and css
and if you can tell me what else can be corrected, I will be very grateful

many of your elements have fixed width in px, which doesn't change in the media query. E.g. you have:
.container {
width: 890px;
...
}
.menu__list {
...
width: 700px;
}
You need to change them in your media query
#media screen and (max-width: 450px) { ... }
Personallly I'd keep only the container width in px for desktop and other things in percents, then in mobile versions I'd keepp them all in percents like
.container {
width: 100%
}
Or sometimes
.container {
width: 100%
max-width: 320px;
}

Basing on the first code you posted.
Modify your container class css (Desktop) since its inheriting from wrapper.
.container {
margin: 0 auto;
}
Your current css ( remove width & padding )
.container {
width: 890px;
margin: 0 auto;
padding: 0 20px;
}
Mobile is fine, its just inheriting the screen size of the emulator.

Related

Body not taking whole device width on mobile device

When the page is displayed on PC or tablet width it works perfectly. When on phone the body leaves empty space on the right. It isn't margin, or padding. I have tried width: 100% and width: 100vw.
Although the #media part doesn't help too much. I'm using flexbox to position everything, the viewport is activated and I have tried using position absolute / fixed on the body, but nothing works.
#media (max-width: 576px) {
body {
width: 100%;
}
main {
width: 100%;
}
header {
justify-content: center;
flex-wrap: wrap;
padding: 1rem;
}
nav {
margin-right: 0px;
}
a {
margin: 0.5rem;
}
}

HTML/CSS Fit Div to Contents unless screen is small

How do I setup HTML/CSS to have my DIV follow the screen size for width, but stop expanding once it fits the contents (it should scroll left/right when the div cannot fully contain the contents).
Pseudo-Code:
HTML:
<div class="image-container">
<img width="1000">
</div>
CSS:
.image-container {
/* ??? */
display: inline-block; /* ??? */
overflow: auto;
}
EDIT: Per Evadore's answer, I was able to come up with the following CSS.
.image-container {
display: inline-block;
overflow: auto;
}
/* optimize these px dimensions, 900 worked for my application */
#media (max-width: 900px) {
.image-container {
max-width: 710px;
}
}
/* redundant, I plan to tweak this range later */
#media (min-width: 901px) and (max-width: 1575px) {
.image-container {
max-width: 710px;
}
}
#media (min-width: 1576px) {
.image-container {
max-width: 1385px;
}
}
The following reference also helped: w3schools
Use CSS Media queries to setup for various screen sizes.
view source code of this page to see how media queries were used.
for this set the parent div width to fit-content and max-width to 100%. now the parent div will remain between the width of the content and the with of the screen if the screen size is not enough. And lastly for scrolling inside the parent div on the small screen devices put overflow:scroll.
Here is the Codepen demo
.parent {
background-color: green;
width: fit-content;
max-width: 100%;
overflow: scroll;
}
.child {
padding: 30px;
width: 700px;
background-color: red;
color: #fff;
}
<div class="parent">
<div class="child">
test string
</div>
</div>
ps: I've added bg colors just for reference purposes, to show whether the parent component is expanding or not.

Unspecified media query

I have used a media query to hide an element when the screen size decreases. I set max-width to 780px.
`#media only screen and (max-width: 780px) {
/* the container for #left and #right elements */
.container {
width: 300px;
height: 400px;
overflow: auto;
}
/* the element to be hidden */
#left {
display: none;
}
/* this element should then take up the whole width of the container */
#right {
width: 300px;
height: 400px;
border-radius: 2%;
}
}`
It behaves as per the media query only at about 770px and below.
I have also included bootstrap classes col-sm-12 col-md-6 for #right.
Between 780px and 770px, #left gets hidden but the #right does not occupy the full space of .container. Instead, #right takes up the first half space of .container, where #left should be and the original space of #right is unoccupied.
What is this unwanted gap and how do I eliminate it?
There are two things min-width and max-width and it functions as
if you use (min-width:768) it means that the design will be applied to the screen width greater than 768px, i-e: from 768px - infinity.
if you use (max-width:768) it means that the design will be applied to the screen width less than 768px, i-e: from 0 - 767px.
Coming back to your question.
.container {
width: 300px;
height: 400px;
overflow: auto;
}
Here you are specifying the width of container as 300px, change it as
.container {
max-width: 100%;
width: 100%;
height: 400px;
overflow: auto;
}
Similarly,
#right {
width: 100%;
height: 400px;
border-radius: 2%;
}
Please let me know If it helps.
Try changing the width to 100% and it should work.
#right {
width: 100%;
height: 400px;
border-radius: 2%;
}

Responsive elements - stretching and then stacking

I'm fairly new to responsive web design, so don't beat me up too badly.
I have a currently fixed-width gallery page that is 1000px wide. The 1000px outer div has 30px padding and 30px between each pair of images. So I've got 910px of space available for each pair. The page might look like this:
(30px spacing)(500px img)(30px spacing)(410px image)(30px spacing)
(30px spacing)(480px img)(30px spacing)(430px image)(30px spacing)
(30px spacing)(450px img)(30px spacing)(440px image)(30px spacing)
...etc.
I'd like to convert it to a responsive page so that the images scale down as the browser window shrinks and ultimately stack on top of each other once the browser window drops below 640px.
The only way I know to make this 640px change is inside a stylesheet. Is this the only way I can do this? Am I going to have to define styles within the stylesheet for every image?
For example, for a 480px wide image:
img.img480 {
width: 48%;
float: left;
}
#media screen and (max-width: 640px) {
img.img480 {
width: 100%;
max-width: 480px;
float: none;
}
}
Here is an example of the effect you're asking for with responsive design.
A couple things to note:
margins are bad, use padding and wrappers instead
floats are bad, use inline-block instead
(Demo)
html, body {
margin: 0;
}
.wrapper {
padding: 0 15px;
font-size: 0;
}
.img-wrp {
width: 50%;
padding: 0 15px;
display: inline-block;
box-sizing: border-box;
}
.img-wrp img {
width: 100%;
}
#media screen and (max-width: 640px) {
.img-wrp {
width: 100%;
}
}
<div class="wrapper">
<i class="img-wrp"><img src="//lorempixel.com/640/480" /></i>
<i class="img-wrp"><img src="//lorempixel.com/640/480" /></i>
</div>

Bootstrap div won't adapt to height based on content

Note: Yes I did make a research first trying to find a solution and tried to implement a number of options to fix the problem, nothing I could find worked though!
UPDATE
Because media queries are not an optimal solution for my problem, as I have to take into account multiple cases of width/height combinations in a responsive layout, I used some javascript at the end in order to calculate the difference in height of the banner div and the content div in order to readjust height accordingly. Here is the code I used
function resizeContainers()
{
var bannerContainer = $('#banner');
var contentContainer = $('#homeFormContainer');
var bannerContainerHeight = bannerContainer.height();
var bannerContainerBottom = $(window).height() - bannerContainerHeight;
var contentContainerBottom = $(window).height() - contentContainer.height();
var containersDiff = bannerContainerBottom - contentContainerBottom;
if (containersDiff > -200) {
var newBannerContainerHeight = bannerContainerHeight+contentContainerBottom+20;
bannerContainer.css('height', newBannerContainerHeight);
}
}
$(document).ready(function () {
// check and resize after page loads
resizeContainers();
// check and resize containers on window resize
$(window).resize(function() {
resizeContainers();
});
});
I am struggling with a div in bootstrap that won't adapt to the height of it's inner content. As far as I can tell, CSS looks OK (but it probably is not, so I could use some help).
You can see the fiddle here
http://jsfiddle.net/spairus/fbmssraw/6/
The basic HTML structure looks like this
<div id="banner" class="banner">
<div class="banner-image"></div>
<div class="banner-caption" style="display: table;">
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
(content here)
</div>
</div>
</div>
</div>
</div>
And the CSS
html,
body {
height: 100%;
}
img {
display: block;
max-width: 100%;
height: auto;
}
.banner {
width: 100%;
height:100%;
min-height: 100%;
position: relative;
color: #fff;
}
.banner-image {
vertical-align: middle;
min-height: 100%;
width: 100%;
}
.banner:after {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.55);
content: "";
}
.banner-caption {
position: absolute;
top: 22%;
width: 100%;
z-index: 2;
}
.subfooter {
background-color: #fafafa;
border-top: 1px solid #f3f3f3;
border-bottom: 1px solid #f3f3f3;
padding: 40px 0;
}
/* Backgrounds
----------------------------------------------------------------------------- */
.default-bg {
background-color: #222222;
color: #ffffff;
}
.space {
padding: 20px 0;
}
I need the .banner and .banner-caption to expand along with the content.
If you're going to have the following code:
html,
body {
height: 100%;
}
and then on your main container:
.banner {
width: 100%;
height:100%;
min-height: 100%;
position: relative;
color: #fff;
}
the container is not going to be responsive to the content inside it, because what you've said in the CSS is basically "hey container (banner), I want you to be 100% of the screen size of whatever device you show up on" .
Instead you need to change the css to said "hey container I want you to have a min-width or be responsive to whatever content you have inside you", so you could do the following:
The best solution I have for this problem (which I face quite often) is as follows.
#media only screen and (min-width : 992px) {
.banner {
width: 100%;
height:120%; // adjust this to whatever size you think your content will stretch to there is no golden rule saying it has to be 100% only.
min-height: 100%;
position: relative;
color: #fff;
}
}
Edit
Why does the above solution work? Notice how I have added a media query that says min width of 992px, now it's safe to say that the dimension of devices above 992px are predictable, and thus it's safe to use a height:120%; it's only when you go below 992px or 768px that the screen resolution (height & width) become unpredictable to counter this you add absolutely no styling to the height of the container.
How effective is this technique? Well, it is pretty effective, but on some screens (the screens above 992px) there might arise a problem of excessive white spacing or slight overlapping of content.
Now to counter this problem you can use multiple media queries : eg.
#media only screen and (min-width : 768px) {
height : 125 %;
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
height : 120 %
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
height : 100 %
}
but IMHO, this is not needed unless you need pin point accuracy (multiple media queries are a pain!). Worst case scenario, use two media queries.
Anyway, here's the technique in action. Try to reduce the screen size and voila! Still looks pretty, and nowhere have a added height:400% for smaller screens: it adapts by itself.