Flexbox vertical centering/mobile browser issues - html

Context: I have a container using display: flex and I am centering one svg element vertically in the center of the page. The only other things on the page are A) a fixed header that gets taken out of the document flow and isn't taking up space and B) a footer with position: absolute that should also not be taking up space. The centering works correctly on every browser but mobile chrome/mobile ios. Vertical centering appearing correctly on firefox mobile.
Problem: The child element of the flex container is not being centered on IOS Safari and Chrome Mobile. It seems like the address bar is throwing off the alignment for some reason. Can anyone offer any insight or help me with a way to debug the issue? I cannot replicate the problem in chrome dev tools.
Any help appreciated. Thank you community.
.logo-flexcontainer {
align-items: center;
display: flex;
height: 100vh;
margin: 0 auto;
width: 90%;
#media (min-width: 1024px) {
width: 50%;
}
}
.logo-flexcontainer > div {
flex: 1 0 auto;
}
#mobile-navbar {
display: flex;
align-items: center;
position: fixed; /* Set the navbar to fixed position */
width: 100%; /* Full width */
height: 50px;
top: 0; /* Position the navbar at the top of the page */
transition: transform .1s ease, background-color .5s ease;
&.hidden {
transform: translate3d(0,-100%,0);
}
&.scroll-background {
background-color: rgba(0, 0, 0, 0.8)
}
#media (min-width: 1024px) {
display: none;
}
#page-title {
margin: 5px 0 0 5%;
h3 {
font-size: 6vw;
text-shadow: 1px 1px #000;
#media (min-width: 600px) {
font-size: 2rem;
}
a {
text-decoration: none;
}
}
}
#hamburger {
position: absolute;
width: 50px;
height: 50px;
top: 5px;
right: 10px;
cursor: pointer;
span {
display: block;
position: absolute;
height: 6px;
width: 100%;
background: #FFFFFF;
box-shadow: 1px 1px #000;
&:nth-child(1) {
top: 6px;
}
&:nth-child(2) {
top: 18px;
}
&:nth-child(3) {
top: 30px;
}
}
}
}
footer {
position: absolute;
text-align: center;
left: 0;
bottom: 0;
height: 100px;
width: 100%;
svg {
height: 90%;
#media (max-width: 550px) {
height: 80%;
}
}
}
<div class="logo-flexcontainer">
<div>
<svg id="logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 598.6 323.5">
<g>svg code goes here...</g>
</svg>
</div>
</div>
<footer>
social icons here, code not important
</footer>
Here is a live link to the project here: project link See if you can replicate the problem on your Android or iPhone device.
Two pictures of homepage on chrome mobile and firefox mobile.
The left is the incorrect orientation and the right is the expected result.

I've been reading a lot and I now realize this is a well documented issue. My initial instinct was correct, chrome mobile address bar adds 60px to the document flow. When you create an element with 100vh, it actually extends 60px past the bottom of the screen of the phone. To me it appears to be a bug but the chrome dev team considers it a feature. Calculating Viewport Height on Chrome Android with CSS
Here is Google's official statement on this: https://developers.google.com/web/updates/2016/12/url-bar-resizing
My apologies for posting this question in lieu of this new information.

Related

Text is flowing out of the container when zooming

My button's text leaks out of the container if I zoom it. When I zoom the button's text flows out of the container. What I want is for it to adjust its font size and stay in the container and don't leak out.
.wrapper a {
position: relative;
display: block;
width: 8.5vw;
height: 7vh;
font-size: 18px;
font-family: sans-serif;
text-decoration: none;
color: #05386b;
border: 2px solid #05386b;
letter-spacing: 2px;
text-align: center;
position: relative;
transition: all .35s;
}
.wrapper a span {
position: relative;
z-index: 2;
}
.wrapper a:after {
position: absolute;
content: "";
top: 0;
left: 0;
width: 0;
height: 100%;
background: #EDF5E1;
transition: all .35s;
}
.wrapper a:hover {
color: #8ee4af;
}
.wrapper a:hover:after {
width: 100%;
}
<div className="wrapper">
<Link to="/orders"><span>Returns <br/> <b>& Orders</b></span></Link>
</div>
You could take a look at the #media css rule. It can be used to create responsive webpages.
For example the following increases the font size by 2 pixels if the screen size is smaller than 786px.
#media only screen and (max-width: 786px) {
.wrapper a {
font-size: 20px;
}
}
To prevent the content from overflowing all together you might want to take a look at the overflow css property. It controls the way content overflows from the containing area. Might not be applicable to your case though as you are talking about making a button here.

How can I make this CSS card responsive?

Edit: here is a CodePen with CSS / HTML
I spend the weekend creating a CSS card for a website, only to realize that it's not responsive, at all. I'm not very well versed in CSS or responsive design, so I am hoping someone with more experience can help me out. So far, I've tried playing around with the #media tag, but I have not had any success. This is the relevant CSS:
#import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
background: #ffffff;
font-family: 'Muli', sans-serif;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
.courses-container {
}
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.2);
display: flex;
max-width: 100%;
margin: 20px;
overflow: hidden;
width: 1300px;
}
.course h6 {
opacity: 0.6;
margin: 0;
letter-spacing: 1px;
text-transform: uppercase;
}
.course h2 {
letter-spacing: 1px;
margin: 10px 0;
}
.course-preview {
background-color: #2a265f;
color: #fff;
padding: 30px;
max-width: 250px;
}
.course-preview a {
color: #fff;
display: inline-block;
font-size: 12px;
opacity: 0.6;
margin-top: 30px;
text-decoration: none;
}
.course-info {
padding: 30px;
position: relative;
width: 100%;
}
.right-container {
padding: 30px;
background-color: #fff;
width: 30%;
line-height: 200%;
}
.progress-container {
position: absolute;
top: 30px;
right: 30px;
text-align: right;
width: 150px;
}
.progress {
background-color: #ddd;
border-radius: 3px;
height: 5px;
width: 100%;
}
.progress::after {
border-radius: 3px;
background-color: #2a265f;
content: '';
position: absolute;
top: 0;
left: 0;
height: 5px;
width: 10%;
}
.progress-text {
font-size: 10px;
opacity: 0.6;
letter-spacing: 1px;
}
This is a simple suggestion, using CSS Grid. It's a two column card (as yours): the left column width-fixed (300px), the right column width-fluid. I've applied a little gap between them just to make my example clearer.
.card {
max-width: 1000px;
display: grid;
grid-template: "left right" / 300px 1fr;
background-color: #fed330;
border-radius: 10px;
height: 300px;
}
.card>* {
padding: 20px;
}
.left {
grid-area: left;
}
.right {
grid-area: right;
}
#media screen and (max-width: 700px) {
.card {
grid-template: "left" "right" / 100%;
}
}
<div class="card">
<div class="left">
Lorem ipsum....
</div>
<div class="right">
Lorem ipsum...
</div>
</div>
It could be a useful starting point.
#gaston
A good way to test and learn about CSS is to use the browser's "Inspect" feature, with which you can test the css behavior in real time.
Activating, Deactivating features, changing values, and adding new ones.
You see the result in real time.
Then just adjust your code according to your tests.
Just right-click on the area you want to inspect. and then Inspect.
You will see an area with HTML and another with CSS.
Click on the areas in HTML and see the corresponding css.
***** Then just test to find the desired result.
That's how I found the solution in your code:
In the ".course" class of your css you added the "width" property twice.
"max-width: 100%;"
"width: 1000px;"
However, the last property entered has priority over the previous ones.
"width: 1000px;" is defining that your card will ALWAYS have 1000px.
SOLUTION:
Just remove: "max-width: 100%;"
And Modify "width: 1000px;" for "max-width: 1000px;"
So your card will have a maximum of 1000px, the minimum will be defined according to the width of the window
It will look like this:
.course {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 10px 10px rgba (0, 0, 0, 0.2);
display: flex;
margin: 20px;
overflow: hidden;
max-width: 1000px;
}
The #media function will set the css when the screen is adjusted to a minimum or maximum width chosen by you.
What is defined within #media will have priority over other css. but only when the window meets the width you set.
You can use this to change the shape of your card completely to very small screens, placing the purple part on top of the card for example.
If you've solved your problem, mark the right answer to help others.
Good luck.

How to fix navbar shrinking height when resizing page

I'm writing an app that replicates the look/feel of a desktop OS, and my navbar in the bottom of the page shrinks in height when the page is resized in height. It shrinks in such a way that it becomes unusable at a point.
I've already tried some CSS properties such as using: position: fixed, position: relative, and position: absolute. position: absolute is the one that has been the best try out of all of them. If I use any others, the navbar would stick at the top no matter what you change in the style.
body {
/* these are for the navbar */
top: 100%;
margin: 0px;
padding: 0px;
/* normal styles */
font-family: "MS Sans Serif";
color: white;
background-color: #008080;
font-size: 12px;
/* without this, the page would go blank
overflow: hidden;
}
ul {
/* this is what works best */
position: absolute;
width: 100%;
top: 96.17%;
/* normal navbar styling.. */
list-style-type: none;
margin: 0px;
padding: 0px;
overflow: hidden;
background-color: #ffffff;
}
I expected the navbar to move up normally as needed, keeping its properties. Instead, the navbar moves up while the page is resized, but it becomes thinner and thinner until it is unusable.
Here is a sample gif: enter image description here
ul {
display: flex;
list-style: none;
align-items: center;
flex-flow: row;
background: red;
position: sticky;
max-width: 100vw;
width: 100%;
color: wheat;
height: 50px;
justify-content: space-around;
}
#media screen and (max-width: 768px) {
ul {
transition: .2s all linear;
height: 45px;
max-width: -webkit-fill-available;
width: 100%;
}
}
<ul>
<li>Home</li>
<li>About</li>
<li>Help</li>
<li>Contact</li>
</ul>

Why don't elements display inline-block again after a resize down and up in Chrome?

I'm trying to prove a wireframe can work responsively, whereby list items 1-4 display:block on mobile, and on desktop 1,3,5 display inline next to each other.
I've encountered a weird bug only in Chrome, whereby the elements 1,3,5 don't re-render inline after a resize down to the small breakpoint and up again.
Demo:
http://jsfiddle.net/n0ocqf2w/3/
Full Screen:
https://jsfiddle.net/n0ocqf2w/3/embedded/result/
stackoverflow is making me post the code with the jsfiddle link, so here are the styles we have in play:
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
ul {
margin: 50px 0 0 0;
padding: 0;
font-size: 0;
white-space: nowrap;
}
li {
display: block;
margin: 0;
padding: 10px 50px;
height: 40px;
background: red;
font-size: 12px;
position: relative;
z-index: 2;
display: block;
width: 100%;
}
li:nth-child(1) {
background: red;
}
li:nth-child(2) {
background: pink;
}
li:nth-child(3) {
background: blue;
}
li:nth-child(4) {
background: lightBlue;
}
li:nth-child(5) {
background: green;
position: fixed;
top: 0;
right: 0;
width: 50%;
}
#media screen and (min-width:400px) {
body {
background: black;
}
ul {
margin: 0;
}
li {
display: inline-block;
width: 20%;
vertical-align: top;
}
li:nth-child(2) {
background: pink;
position: fixed;
top: 35px;
left: 0;
width: 100%;
z-index: 1;
opacity: .5;
}
li:nth-child(4) {
background: lightBlue;
position: fixed;
top: 45px;
left: 20px;
width: 100%;
z-index: 1;
opacity: .5;
}
li:nth-child(5) {
background: green;
position: relative;
width: 20%;
}
}
Steps to replicate in Chrome:
Open at wide breakpoint, so body background is black. Observe items 1,3,5 rendering inline.
Resize browser down to < 400px, so body background is white. Observe items 1-4 switching to display:block.
Resize browser up again, so body background is black. Observe items 1,3,5 NOT lining up again.
After a bit of digging, I found this very old bug which hasn't been fixed in over 4 years:
https://bugs.webkit.org/show_bug.cgi?id=53166
Could anyone please confirm if this is fixable? I'm really hoping the open bug in the above link isn't present here, but the criteria of not applying the display property in a media query after a resize matches exactly :-(
Cheers
Hope this helps.
http://jsbin.com/bakujusaxu/1/edit?css,output
/*
SOLUTION HERE
The following elements are being treated as a "clearfix" type of thing, so when you re-size from "mobile" to "desktop" the fixed position elements are being treated as "block", as they happen to be intersected elements, it gives the stacked result...
*/
#media screen and (min-width:400px) {
li:nth-child(2),
li:nth-child(4) {
/*
The bug is a re-drawing bug. Not your fault, but the browser's.
The ideal solution, would be to set this to inline, but that doesn't work.
So you can set it to the following values:
none
flex
table
list-item
*/
display: flex;
}
}

Bootstrap Responsive Carousel doesn't resize properly

I'm using Bootstrap and I have a carousel under my navbar.
It works OK on normal computers, check this link.
However, I'm having trouble on smaller screens, e.g. iPhone. Just resize your browser screen to see what I mean.
I'm figuring maybe it isn't necessary the responsive CSS but something else I' doing wrong. Maybe their are better ways to get the carousel image with resized on every screen.
Also, I would like the carousel to have a 100% height of the screen, so the carousel spans the entire screen, and the rest of the content shows only when you scroll.
CSS I'm using:
/* CUSTOMIZE THE CAROUSEL
-------------------------------------------------- */
/* Carousel base class */
.carousel {
margin-top: -80px;
position: fixed;
width: 100%;
}
.carousel .container {
position:relative;
z-index: 9;
}
.carousel-control {
height: 80px;
margin-top: 0;
font-size: 120px;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
background-color: transparent;
border: 0;
z-index: 10;
}
.carousel .item {
min-height: 800px;
}
.carousel img {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: auto;
margin-top: -200px;
}
.carousel-caption {
background-color: transparent;
position: static;
max-width: 550px;
padding: 0 20px;
margin-top: 200px;
}
.carousel-caption2 {
background-color: transparent;
position: static;
max-width: 380px;
padding: 200px 20px;
}
.carousel-caption h1,
.carousel-caption .lead,
.carousel-caption2 h1,
.carousel-caption2 .lead {
margin: 0;
line-height: 1.25;
color: #fff;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.carousel-caption .btn,
.carousel-caption2 .btn {
margin-top: 10px;
}
#wrapper-container {
margin-bottom: -80px;
padding-bottom: 80px;
position: relative;
background: inherit;
top: 60%;
}
/* Featurettes
------------------------- */
.featurette-divider {
margin: 80px 0; /* Space out the Bootstrap <hr> more */
}
.featurette {
padding-top: 120px; /* Vertically center images part 1: add padding above and below text. */
overflow: hidden; /* Vertically center images part 2: clear their floats. */
}
.featurette-image {
margin-top: -120px; /* Vertically center images part 3: negative margin up the image the same amount of the padding to center it. */
}
/* Give some space on the sides of the floated elements so text doesn't run right into it. */
.featurette-image.pull-left {
margin-right: 40px;
}
.featurette-image.pull-right {
margin-left: 40px;
}
/* Thin out the marketing headings */
.featurette-heading {
font-size: 50px;
font-weight: 300;
line-height: 1;
letter-spacing: -1px;
}
/* RESPONSIVE CSS
-------------------------------------------------- */
#media (max-width: 979px) {
.container.navbar-wrapper {
margin-bottom: 0;
width: auto;
}
.navbar-inner {
border-radius: 0;
}
.carousel .item {
min-height: 500px;
}
.carousel img {
min-width: 100%;
height: auto;
}
.featurette {
height: auto;
padding: 0;
}
.featurette-image.pull-left,
.featurette-image.pull-right {
display: block;
float: none;
max-width: 40%;
margin: 0 auto 20px;
}
}
#media (max-width: 767px) {
.navbar-inner {
margin: -20px;
}
.carousel {
margin-left: -20px;
margin-right: -20px;
}
.carousel .container {
}
.carousel .item {
height: 300px;
}
.carousel img {
height: 300px;
}
.carousel-caption {
width: 65%;
padding: 0 70px;
margin-top: 100px;
}
.carousel-caption h1 {
font-size: 30px;
}
.carousel-caption .lead,
.carousel-caption .btn {
font-size: 18px;
}
.marketing .span4 + .span4 {
margin-top: 40px;
}
.featurette-heading {
font-size: 30px;
}
.featurette .lead {
font-size: 18px;
line-height: 1.5;
}
}
There's a lot you would need to do to clean it up... The following will get you started, but there would definitely be a bit more tweaking to do.
I didn't look at the CSS to fill the screen with an image as per your last request. I think you will have to look at adding a different carousel with other cropped images with a portrait aspect ratio if you want that, so you show the specific part of the image you want.
Firstly under #media (max-width: 767px), remove:
.navbar-inner {
margin: -20px;
}
It's causing your menu bar at the top to shift up out of sight.
From #media... .carousel, remove:
margin-left: -20px;
margin-right: -20px;
This is messy, and is there because of the padding added to body (see below).
Add the following to #media (max-width... .carousel:
position: relative;
margin-top: 0px;
Because you want the carousel to sit neatly under the navbar.
Remove the following from #media... body
padding-right: 20px;
padding-left: 20px;
This is causing problems for the carousel, and you can add this padding for specific divs like wrapper-container if you want.
From .carousel img, remove:
margin-top: -200px;
Next, you have to fix the fact that the text under the carousel is moved way down:
Add the following to #media... #wrapper-container
top: 0;
Remove the following from #media (max-width: 979px)
.carousel .item {
min-height: 500px;
}
and the following from #media (max-width: 767px)
.carousel img {
height: 300px;
}
because the carousel is nowhere near that height at smartphone sizes.
You will also have to play around with the positioning of the caption text in the #media CSS. You may want to decide to lose some caption text as the carousel shrinks.
This will get you started, and you can go from there...
For starters, get rid of the margin-top: -200px; on your .corousel img style.
With a small screen, your image height is less than 200px and this causes it to go off of the screen.