How to fix a tear between divs? - html

I'm working on a small practice text adventure game project. Lately I have noticed a strange tear that appears between the main story div, and the footer [menu div]. It appears randomly when you scroll the story text all the way down - sometimes it's there, sometimes it's not. The problem occurs both on mobile, and on PC.
The tear is visible here, right below "Newest line" text:
Div tear
Here an image without the tear, with the text not fully scrolled down:
No Div tear
CSS for the two divs:
main
{
font-family: '8bit', Times, serif;
font-size: x-large;
background-color: rgb(255, 255, 255);
height: 32vh;
padding: 2em;
overflow: auto;
display: flex;
flex-direction: column-reverse;
}
footer
{
font-family: '8bit', Times, serif;
display: flex;
flex-direction: row;
justify-content: space-between;
background-color: rgb(255, 255, 255);
height: 30vh;
padding: 1em;
}
I have tried several weird hacks, like CSS transform for both of those - it seemed to help with the tearing, but generated other weird artifacts with the box-shadow and such.
The full code is available here:
https://github.com/Akawgan/textRPG
Any ideas what might be causing that, or how to fix it?

I think you have run into the good old "fractional pixel values on a screen with discrete pixels" problem.
The main div has a height of 32vh, which equates to 509.11px on my screen, and probably to similar values on different screens.
There's a lot going on between CSS pixel values and the actual size on screen, so without complicating it I'm going to put it this way: some screen sizes can't handle this exact value. Your div is going to be rounded up or down to some integer value, often times "correctly", sometimes "incorrectly".
There's not much you can do to actually fix this issue, short of choosing another height value.
You might be able to work around it by placing the footer 1px on top of the main element:
footer {
position: relative;
margin-top: -1px;
}
This is a somewhat dirty trick that just superposes both elements in order to cover any gap caused by fractional pixels.

I found a way to 'reliably' experience the problem, by gradually changing the width of the viewport. The phenomenon changed, sometimes the background of the container showed through (I changed it to red so it was obvious), sometimes it seemed to be the greeny background that showed through, sometimes it seemed to be neither but instead a couple of gray lines (of different shades).
It is difficult to prove a negative, but if I removed the reverse of the flex column then I never managed to see the phenomenon.
This has to be speculation but it looks likely that putting your text into the order you want it rather than getting CSS to reverse it may remove the problem.

Related

How to hide padding devoted to scrollbars that don't appear?

I've got a frustrating issue here involving a nav element that always displays an area to contain a scrollbar, even when the scrollbar is not needed. Here's what it looks like when all the content is displaying:
Here's what it looks like when you reduce the height of the window so scrolling is necessary to see all the content:
And here's what it SHOULD look like:
Here's the CSS for this element (as written in React and including some variables I'm leaving in -- I'm assuming those shouldn't matter):
box-sizing: border-box;
background-color: ${Color.White};
border-radius: 8px;
height: calc(100vh - ${heightCorrection});
padding: 0 16px;
text-align: left;
overflow: scroll;
width: ${width};
display: flex;
flex-flow: column nowrap;
> header,
footer {
padding-left: 16px;
}
I created that third screenshot by changing overflow: scroll to overflow: hidden, but that prevents me from being able to scroll when I need to, and I still need that to happen.
I should mention that a frustrating thing about this issue is that most users haven't been able to replicate it. I don't have any particularly unusual setup; I'm running the latest version of Chrome on MacOS. But others with very similar configurations aren't seeing that empty scrollbar area. This issue stumped one of the best front-end developers I know (who can't replicate it), so I thought I'd try here and see if anyone has any ideas.
Well, I didn't get any traction on this, but in case anyone lands on it, the answer is simply to change overflow: scroll to overflow: auto.

I have a div that I need to stay in a certain position when the screen gets smaller

I'm currently having a problem with a div on my site. I'm trying to get it to stay in a fixed position even on smaller resolutions but no matter what I have tried so far the div moves to the right every time the window gets smaller.
Here are pictures of the issue:
Correct position:
Incorrect position:
Also, here is the CSS for the div:
#fep-notification-bar{
color: #f3ed42;
border-width: 0px;
text-align: left;
background-color: #282828;
margin-left: 1338px;
font-weight: normal;
}
The site is wastelandgamers.com
If anyone knows how to resolve this issue I would really appreciate it!
EDIT:
Sorry, I wasn't clear enough and I realize now that the way I clipped the pictures makes it seem like the header is expanding but that's not the case. The new message text is what won't won't stay in place. whenever I make the screen smaller the text moves to the right instead of staying in place above the search bar. Unfortunately you can't really test it unless you are logged in and get a message.
I'm not sure what your HTML looks like but from the screenshots I would wrap all the elements up in a span or div and then position that.
Try to use float:right maybe then edit certain classes or ids using #media in the css.
I have figured out a solution for now. I have changed the code to:
#fep-notification-bar{
color: #f3ed42;
border-width: 0px;
background-color: transparent;
margin-left: 24.7%;
font-weight: normal;
position: absolute;
}
It has not completely solved my problem but it is at least a band-aid. This way the text still moves slightly, however, it now moves to the left and only a small amount so it does not fall off the page no matter how small it is.

Words cut off at the end of lines - only in Safari

I am creating a short and relatively simple website for a summer project about the book Red October (located at http://dragonmath.net/summer_project_2016/summary/). The website is not complete (it is missing content, pictures, and is not yet fully responsive), but before I finish any more, I would like to fix a bug. The website appears fine in all browsers except Safari. When Safari is over 1242px wide, some of the words at the ends of the line cut off.
Originally I believed that it might be the font that was the problem, but a little bit of testing showed that the words were cut off with many fonts, all the fonts I tried. Another interesting point is that some words extend past where the cut off words are cut off. This makes me believe that it doesn't likely have to do with the width of the element, but I am not sure.
I also noticed that the website seems to be wider in Safari, The (min-width) in the #media tag was able to be smaller in Chrome, but had to be wider in Safari. I don't know if this contributes to the words being cut off only in Safari, but I thought it might help explain the problem more completely.
I found several other articles with seemingly similar problems, but none of the suggested fixes helped my problem.
This question and this article both deal with overflow, or text-overflow neither of which fixed my problem. The css in my website still has overflow: visible in it.
The website from this question is no longer at the link provided, but I would imagine that the change to the answer was adding width: 100%;. I tried that, but it didn't have any effect on the text being cut off. This MacRumors article seems to provide a similar answer to the question (changing to height: 100%; in this case). This article also mentions the fact that the text wasn't cut off in Safari (opposite of what I am finding).
I have tried Googling every possible way to put my problem that I can think of, but nothing has turned up. I have also searched Stack Overflow extensively for any reason that this could be happening. While it is hard to create a short piece of code that recreates the problem (because the problem only happens in Safari) below is all the html and css that should be causing the problem. The full code for my webpage can be found at http://dragonmath.net/summer_project_2016/summary/
.mainSection {
display: block;
height: auto;
width: 100%;
}
.sectionContentContainer {
display: inline-block;
margin-top: 40px;
margin-left: 40px;
width: 560px;
overflow: visible;
}
.sectionParagraph {
font-weight: 400px;
font-size: 20px;
width: 100%;
margin-top: 40px;
word-spacing: 10px;
}
<section class="mainSection">
<div class="sectionContentContainer">
<p class="sectionParagraph">The content goes here, but sometimes when the content stretches onto multiple lines, it cuts off random words in Safari.</p>
</div>
</section>
As far as I know, that is all the css that could impact the text. Just for background, the text has an image next to it and the image and the text are surrounded by <main> tags. The main is set to have min-height: calc(100% - 160px;
height: auto;
width: 100%;
Here are some images of what happens:
Any help would be great (and if any clarification is needed, ask in the comments).

HTML body not filling complete width on mobile devices [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
If I open my (GWT) page in a normal browser, everything works fine. The body takes the whole width and the content is nicely centered. But if I try this on a mobile phone, the body does not take the whole width and therefore the content is not centered.
I couldn't find out why it is being displayed like this. Also, adding 100% width to body and html tag does not solve the issue .
Is there a way to get this working nicely on a mobile device?
The page can be reached under: http://www.vegantastic.de/
this was driving me crazy and i just solved it by adding position:fixed to the body
Why is body not full width, even though its set to 100% / vw?
In a strange way it is full width, but the viewport is scaled down automatically by the browser, so it fits in the overflowing content.
To check, if this is the case, type this in the console (1): window.visualViewport.scale
1) edit Sep. 2019: visualViewport: only available on Chrome - sry for late notice
If it returns something like 0.8, then the body size is correct, but the viewport is scaled down.
You can also double tap to toggle between scale 1 and "fit-content-scale" (needs touch simulation like in chrome dev-tools).
How to not overflow body?
See here https://stackoverflow.com/a/14271049/3313410 "Creating a site wrapper div inside the body"
or check, if a certain element has a min-width, that "overrides" its width
or check, if something is rotated, or margins out https://stackoverflow.com/a/45534745/3313410
It might be because of a very long word on your webpage. After using the correct viewport meta tag:
<meta name="viewport" content="initial-scale=1.0, width=device-width">
I tried this out, by placing this text inside a paragraph element, inside some empty HTML document:
<p>Here I have a text, and I am going to use a very long, and not-imaginary word (oh it's real) inside. Without some word-breaking CSS, the result will break the screen on smaller devices: Pseudopseudohypoparathyroidism</p>
What happened when I decreased the screen size without the mobile phone simulator:
And what happened when I decreased the screen size with the mobile phone simulator:
Quite the difference. My tip: use the following CSS attribute:
p {
word-break: break-word;
}
I can see that the problem behind this question was solved, but I just experienced the same issue and the answer here could not applied in my case because of the scroll disabling stated in the comment, and any other style modifications on the body seemed to affect the result.
After experimentation I found out this was caused by an element inside my page which was rotated and its height became an obstacle on mobile, since it was closer the right end of the body.
So I would like to add this answer if someone, like myself, find this question via google:
This problem can be caused by many factors, you may want to investigate if one of your component's width is not becoming a problem on mobile view. There is probably a div too long on your page, or a rotated one which margin got out of the body.
Just add this to your body tag and your problem should be solved:
body {
position: absolute;
}
In my case, body (and html) element returns to normal after removing the properties from display: flex; group. After my investigation, I discovered that every element with an automatically calculated width must be in an element that has height and width and wraps all children going all the way to the body. After adding some overflow:auto; position:relative; to the parent elements, the body scales correctly with display flex nested in display flex.
#import '../../variables.scss';
:host {
overflow: auto; // added this line
}
.top-bar {
display: flex;
flex-direction: row;
padding: 10px;
box-shadow: $shadow;
position: relative;
.search-item {
flex: 1;
margin: 0 1em;
display: flex;
flex-direction: row;
position: relative;
input {
margin: 0;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-right-width: 0px;
flex: 1;
width: 1px;
}
button {
margin: 0;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
border: 1px solid #ccc;
border-left-width: 0px;
box-shadow: inset $shadow;
}
}
button.icon-only {
border: none;
background-color: transparent;
}
}
menu looks like this:
before:
after:
I had the same problem. In my case there was a grid element that had many columns and grid-gap set to 50px. It caused html to expand. I think it's a good practice to reduce grid-column-gap on small screens.

main page multilingual css alignment issues

We have some minor formating issues with the main page of our site Batoku when we switch to an alternative language (change to italian to test).
1) 'Swap' text is not centered between the arrows upon changing languages.
(#wrap-main #main-home #items a#swap )
a#swap {
color: #449AC2;
font-size: 26px;
font-weight: bold;
left: 467px;
max-width: 135px;
position: absolute;
top: 194px;
word-wrap: break-word;
}
2)The footer is not centered and doesn't look good it is inconsistent in terms of items per line when a language changes and if you like this page at the bottom for the first time, there is no space to write a comment and like.
3)Potentially if there is a very large text for any of the languages the header will look completely all over the place.. to test under <li id="add-item"> modify the span to say <span>I will destroy your header!!! </span> (please use firebug)
Thanks
1) About the swap, there is a fixed left position, that means that it will always stay there. It's better to be wrapped via some div with width: 100%; text-align: center; or something like that in other to center the text, and not the element itself.
2) About the footer. There is fixed width to the ul. You should remove it, add 'text-align:center' to it, remove the float from li elements and make them display: inline;
3) For the header you should blame the designer. :) They are not coders but at least they should ask their self "What if there are more links?" or "What will happens once the language is changed?", they should think a little outside of the frame.
There is nothing here to prevent the site from braking. You can make it absolute, but once it's to large it will start to go over the text field. And that will not be ok too. You can use some kind of javascript to check if the elements it's breaking and apply some kind of class to the navigation in order to decrease the font-size or change the position of the elements.