Content overflowing / overlapping flex items on smaller screens - html

I'm using flexbox and I set each section's height to 100vh.
Whenever, I resize the window, the text from the first section and the last section overflow to the other sections.
.banner, #showcase {
display: flex;
align-items: center;
justify-content: center;
}
.container, .banner {
width: 100%;
height: 100vh;
}
http://codepen.io/mrfishball/pen/oLgLxX

have you tried overflow:hidden; on the sections where the content is overlapping?

.banner, #showcase {
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
/**border: 10px blue solid;**/
overflow: hidden; /*or scroll*/
}
And you can control the font size for different device screen sizes. For example:
#media only screen and (max-width: 500px) {
.banner {
font-size: 9px;
}
}

you can just add width : 100% to .content

I've been struggling with the same issue over the past few days, and after hours of Google, trial and error, I have come up with a good workaround for one of your issues. I'm still struggling with the positioning a little so I'm not going to touch on that, but figuring out how to implement fluid typography REALLY helped me with the overflow problem.
I'm not going to try explain it all in detail, because it the resources I'm linking below do a much more thorough job, and there might be information I am unaware of/misunderstood.
The TL;DR of it is that instead of a bunch of media queries, you want the text to fluidly scale to your viewport size. Here are the basic steps, but first, a disclaimer:
Test this out on a sandboxed version of your site if possible. It might take you a while to get to the ideal typographic scaling, and
you will negatively affect your customer experience if every few
minutes the text size changes.
Set your base font size to 100% (either in body or html, depending on how your site is set up)
html {font-size:100%;}
Set your typographical hierarchy in rem (not em) sizes (rem works off the base font size, making the math simpler). For example:
p { font-size: 1.25rem; }
h1 { font-size: 4rem; }
h2 { font-size: 3.25rem; }
h3 { font-size: 3.0rem; }
h4 { font-size: 2.75rem; }
h5 { font-size: 2.25rem; }
h6 { font-size: 1.75rem; }
Add the following two media queries to enable the responsive behaviour of the text, and to settle the size above a specific threshold:
#media only screen and (min-width: 10em) {
html {
font-size: calc(0.875em + 0.25 * (100vw - 80em) / 40); /* 1 */
font-size: -webkit-calc(87.5% + 0.25 * (100vw - 8000%) / 40); /* 2 */
font-size: -ms-calc(0.875em + 0.25 * (100vw - 80em) / 40); /* 3 */
}
}
#media only screen and (min-width: 120em) {
html { font-size: 1.125em; }
}
And Voila! You should have fluid typography! You will have to go through your site carefully and make sure there aren't things overriding your css (bootstrap screwed me for hours before I finally clicked, thanks to the Google Developer sidebar), and that you don't have rogue font-size declarations messing up your pretty layout. If your site is clean and your typography well laid out though, you should be able to carry on just using <p>, <h1> and so on tags, all of which will be fully responsive.
Here are a few resources I found extremely helpful in figuring this out:
https://zellwk.com/blog/viewport-based-typography/
https://www.smashingmagazine.com/2016/05/fluid-typography/

You set this height: 100vh; and that's what's causing the problem. Set it to 100%.
.container, .banner {
width: 100%;
height: 100%;
/**border: 10px black solid;**/
}
I see other answers include adding more viewport height to child elements, but I think that's asking for more trouble. Plus, it doesn't entirely solve the overlapping issue. I usually avoid vh or vw unless it's necessary to achieve something that cannot be done with them; for example, parallax scrolling or side navigation with enhanced entrance and leaving animation.
To achieve a clear cut, bullet proof sections without any overlapping, use height: 100%;
Update: I am not able to comment since I don't have enough points, so I am adding it here. In response to this comment "#StevenKwok, I updated the answer. You can search more about responsiveness and screen sizes", this supports my point, asking for more trouble. If you stick with vh, then you will need to add media queries at certain breakpoints, including small laptop, tablet, and mobile devices.

Related

Screen size media query works on laptop but not on phone

In the web game that I have created, I have made a media query targeting screen sizes of less than 500px that worked just fine when I resized my browser on my laptop. See below for images. Page for browser size above 500px:
Page for browser size less than 500px:
However, on my tiny iPhone 5 screen (yes, I know, it's a relic), the media query does not activate, screwing up the website:
The width of my iPhone screen is definitely smaller than the screen of my laptop's browser when I shrink it down enough that the media query kicks in, hence my confusion. If anybody knows why my iPhone won't render the webpage according to the media query, I would greatly appreciate being clued in. Here is the media query if it helps:
#media only screen and (max-width: 750px) {
:root {
--sidebar-height: calc(var(--game-size) / 3);
--main-width: var(--game-size);
--main-height: calc(var(--game-size) + var(--sidebar-height));
}
main {
flex-direction: column-reverse;
}
hr {
display: none;
}
.vr {
display: inline-block;
}
#game {
margin: 0;
}
#sidebar {
border-bottom: 3px solid var(--center-color);
border-left: none;
width: var(--main-width);
height: var(--sidebar-height);
margin: 0;
}
#inner_sidebar {
margin: 2.5%;
display: flex;
align-items: center;
}
#stats {
display: inline-block;
min-width: 8ch;
}
#retry {
display: inline-block;
}
#victory {
bottom: calc(var(--main-height) + 5vh);
}
}
Thanks!
Checked your github link, you're missing this among your meta tags. Only then the browser will scale down or apply the media queries in smaller screens.
<meta name="viewport" content="width=device-width, initial-scale=1">
I looked at your CSS on git, and I suggest not using "vh" for making things responsive. the reason why things don't work on your iphone correctly is because your iphone has larger "vh" than "vw". I prefer using multiple media queries for different widths. and changing font-size in media queries will fix text overflow
btw vh = viewport height and vw = viewport width
I hope my reply helped you in any way :).

How to avoid horizontal scroll on website

I recently made a tribute page using html and CSS. The website looks fine on desktop but on mobile,a horizontal scroll bar appears and make the website look left aligned.I think its because the images exceed the parent container but I am unable to fix it.
Github pages: https://rahulviveknair.github.io/Coldplay-Tribute-Page/
Code hosted on github: https://github.com/RahulVivekNair/Coldplay-Tribute-Page
The code used to adjust image but does not seem to be working
#image {
max-width: 100%;
display: block;
height: auto;
margin: 0 auto;
}
I would suggest you to do the following:
remove margin and padding from the body, and set its width to 100%, in order not to rely on the default width applied by the browser:
body{padding:0; margin:0; width:100%;}
set a max-width if the disks cover:
#image-grid img {max-width: 100%;}
change the font-size of the title with media query:
#media screen and (max-width: 600px) {
h1 { font-size: 30px; }
}
The scrollbar only appears when your header "COLDPLAY" is getting too big/wide, which is due to its font-size. So you should use a media query for #title or h1 where you define a smaller font-size setting.
Try also wen do debugging to unable cache in DevTools(if you use Chrome).
Usually files are not updating and you don't see any result even if you change something.
Also check this page if you are beginner CSS Tricks
P.S. I also started with CodeCamp good luck on next assignments
Remove both #media for the h1 and replace them with:
h1 {
font-family: 'Montserrat', sans-serif;
font-size: calc(5vmin + 16px); /* (320,32)(1280,80) */
font-weight: 600;
text-align: center;
margin-bottom: -15px;
}
This calc() calculates the h1.font-size using linear equation y=mx+b (MathIsFun: linear equation) with points
point1 x1=320px y1=32px, fontsize 32px on a 320px display
point2 x2=1280px y2=80px, fontsize 80px on a 1280px display
and all h1.font-size for all display sizes inbetween/beyond (I tested this with your Codepen).
Did the same trick with the 'album' images by adding column-count and column-width
#image-grid {
column-count: 3;
column-width: calc(8.75vw + 252px); /* (320,280)(1920,420) */
...
}
Finally change CSS #image { max-width: 100% } to img { width: 100% } and all the images on the page resize responsively
See my Codepen
Note anything smaller than 320x320 can be considered a 'smartwatch'!
It's really easy, all you need to do is set the overflow-x value to hidden, if you only want to avoid a horizontal scrollbar and not a vertical one.
However, this will cut off things that go beyond the scrollbar, so you need to fix those widths as well.

using #media queries for media compatibility

I don't believe I'm grasping how to create a responsive website. this is my code:
body{
width: 100%;
font-size: 16px;
background-color: grey;
}
h1{
color:black;
}
p{
color:black;
}
#media only screen and(min-width:320px)and(max-width:420px){
h1{
color:red;
}
p{
color: white;
}
}
my goal with this small css edit was to see if I understood how the media query worked and to change the h1 and p element colors when a screen size is in-between mobile size.
however, regardless of what size the screen is, there is no changes the elements. I'm slightly confused because I've seen videos of people using this as an example.
You have the right order of things, normals rules first and then mobile rules afterwards.
Let's say you have two buttons on the screen for a desktop and a phone. Because a mobile phone obviously does not have the width to spare you may want to show the buttons above and below each other instead of side-by-side.
I have a phone with a horizontal screen width of 375px. If the buttons are rendered as 250px then they blatantly won't render side-by-side on my phone without clipping and therefore looking messy to visitors.
Take this code in to consideration:
input[type='button'] {display: inline-block; width: calc(50% - 8px);}
#media (max-width: 1024px)
{
input[type='button'] {width: calc(100% - 8px);}
}
The button input elements are set to use (roughly) 50% width (compensating a bit for border and margin). Since they are inherently display: inline; I'm using display: inline-block to keep them rendering on the same line (no line breaks for outright block rendering) though allow setting the width hence inline-block.
The media queries do not negate something like display unless it's explicitly defined, again so all the input buttons are still rendered as inline-block. But now on a mobile screen these buttons will use up enough space that they'll push each other to separate lines.

How to set a maximum width with flexbox and avoid jumps with media queries

I have 3 boxes with 3 products (Ragnar, Thor and Odin) created with flexbox. They work perfectly on a mobile version but when I resize the browser window to tablet and desktop versions, the boxes become suddenly bigger due to the media query. I'm working with max-width in pixels. I want to make it more responsive and I'm not sure how.
To sum up, the boxes should rescale and change their width smoothly until they reach to their maximum width and be narrower than the rest of the main elements.
Here's the link of the pen: https://codepen.io/aitormorgado/pen/MWayXPy
Here's the code for the section ID and the box class:
#models-section {
flex-direction: column;
align-items: center;
text-align: center;
font-size: 5.5rem;
}
.product {
margin: 3rem auto;
border: 1.5px solid black;
line-height: 1.8;
max-width: 260px;
}
And this is the media query:
#media only screen and (min-width: 768px) {
html,
body {
max-width: 70vw;
margin: 0 auto;
}
.product {
max-width: 400px;
font-size: 3.5rem;
}
}
I tried it out and found out your code needs only very few minor changes. Set your .product to the following widths:
.product {
margin : 3rem auto;
border : 1.5px solid black;
line-height: 1.8;
min-width : 260px;
width : 40%;
}
And remove the width in your media query. It may not be perfect. But from this point you should be able to optimise it on your own.
You've set your widths very fixed to 260px and 400px for wider screens. You let no room for transitions between the two values. A relative value with % should fix it.
However, your code has some other dependencies, which I'm not able to control. Good luck!

Logo Height not responsive

The "rh" logo on my site is responsive vertically, ie fits perfectly to a tall thin window, but does not resize to a wide short window. Could anyone help me make the logo responsive to both width and height?
here is the website... (takes a bit to load up)
http://rhwebdesign.co.uk/
Here is my CSS:
img {
height: auto;
max-width: 100%;
vertical-align: middle;
}
To be very specific and address your questions about the logo, consider setting the max-height relative to the window's height.
You have:
img {
height: auto;
max-width: 100%;
vertical-align: middle;
}
.hero-logo img {
max-width: 100%;
min-height: 100%;
padding: 20px;
}
In order to scale the logo, add in to the latter block:
max-height: 100vh;
This sets the images maximum height to 100% of the viewport height, which appears to be what you desire here. Note that there is some text beneath it, which is not displayed, since it is text wrapped in an H5. These two lines are 68px tall (40px padding plus 28px for the text). So, you can adjust the above to:
max-height: calc(100vh - 68px);
It looks like in landscape mode (480x320), there is a script not calculating the size of margin correctly.
<div class="container hero-content" style="margin-top: -97.5px;">
have a look in main.js for this function:
heroContent.css({
"margin-top" : topContentMargin+"px"
});
Which is this:
topContentMargin = (heroHeight - contentHeight) / 2,
heroHeight = windowHeight,
contentHeight = heroContent.height(),
I haven't really looked into why it is calulating it incorrectly. My guess is that heroContent is too high for landscape mode because the image becomes 441px high with the media query max-width:100%. So it tries to add a negative margin to compensate.
My advice would be to remove the jQuery calculation of the hero content sizing and apply sizes using css and media queries only.
Edit:
You need to be more specific with your css. Learn some more about css specifity. You should include your largest media queries at the top, so the smaller ones will take precedence at the bottom. Makes things easier. Also IMHO, I wouldn't use queries for anything larger than iPad. ie. 1024px. Although you should always test on newer devices if possible.
You will need to specify the height of the video for each specific device size. I can't tell now, but maybe jquery was determining the section heights, so now the css is determining the video height.
So at the bottom of your style sheet, try this.
div#bgVideo.skrollable.skrollable-between video#video_background {
min-height:940px !important;
}
#media (max-width: 480px) {
.hero-logo img {
max-width:55%; /*looks nice at 480 */
padding:20px;
}
div#bgVideo.skrollable.skrollable-between video#video_background {
min-height:320px !important;
}
}
#media (max-width: 320px) {
div#bgVideo.skrollable.skrollable-between video#video_background {
min-height:480px !important;
}
}
But Richard, to be honest, you should be troubleshooting and testing the design yourself. How will you ever learn if you don't try. Remember, firebug is your best friend :)