iPhone tries to squish everything onto one page - html

I've been working on a website, and all was going well until I had someone try to test it on their iPhone. All the content seems to be squished onto the screen on iPhone. This happened in Safari, Chrome, and Duck Duck Go. I am unable to recreate the problem in any of the iPhone simulators I've tried on the internet, but have seen the problem on both iPhones I've tested it on.
Here is what it looks like on the iPhone:iPhone image
Here is what it looks like on my android: Android image
The layout uses flexbox extensively, which my research leads me to believe is the problem. I have tried adding this css to the bottom of my css file to prevent flexboxes from shrinking, but it has not solved the problem:
* {
flex-shrink: 0;
}
Let me know if you need more source code, but since the problem is throughout the entire page I would have to post all of it.
Edit: Here is the pastebin of the css https://pastebin.com/c0VjkGDc
Edit 2: Here is an example of the HTML from one of the cards that seems to be squished on iPhone (ignore the php):
<div class='container'>
<div class='results-container'>
<div class='result-card'>
<div class='card-date'>
<div class='month'>{$date_month}</div>
<div class='day'>{$date_day}</div>
<div class='year'>{$date_year}</div>
</div>
<div class='card-info'>
<div class='card-title'>{$aud_position}</div>
<div class='card-subtitle'>{$aud_name}</div>
<div class='card-location'><i class="fas fa-map-marker-alt"></i> {$aud_location}</div>
<div class='card-pay'><span class='pay-span'>{$aud_pay}</span></div>
<div class='card-icons'>
<i class='icon-red fas fa-clock'></i> App deadline passed
</div>
</div>
<div class='card-actions'>
<div class='card-fave'><i class="fas fa-heart"></i></div>
</div>
</div>
</div>
</div>
And here is relevant CSS for that:
.container {
display: flex;
}
.results-container {
width: 100vw;
display: flex;
flex-direction: column;
}
.result-card {
flex: 1;
display: flex;
margin-top: 5px;
background-color: white;
padding: 15px;
}
.card-date {
flex: 0 0 5em;
display: flex;
flex-direction: column;
border-right: 1px solid #ddd;
align-items: center;
justify-content: center;
border-radius: 5px;
}
.day {
font-size: 2em;
}
.card-info {
padding-left: 15px;
flex: 1;
display: flex;
flex-direction: column;
line-height: 1.5em;
}
.card-title {
font-weight: bold;
font-size: 1.1em;
}
.card-pay {
margin: 10px 0;
}
.pay-span {
background-color: #f0f0f0;
border-radius: 5px;
padding: 10px;
border: 1px solid #ddd;
}
* {
flex-shrink: 0;
}

As mentioned in the comment of the question above, the original HTML and CSS contain quite a lot of errors. To validate and fix the errors, the following online resources can be used:
W3 HTML Validator: https://validator.w3.org/nu/
W3 CSS Validator: https://jigsaw.w3.org/css-validator/
On the other hand, if you apply the Bootstrap responsive framework in your website, it can save you quite a lot of efforts to handle different screen sizes.

Related

How do I get flex elements not to grow on click?

Hobbyist who really sucks at css.
I have the following three divs:
The problem is, when I click on the middle one, the box grows, and so do the other two boxes:
How do I make boxes start off and stay the same size even after click. The reason the box is growing is do to adding the "arrow-icon"
Code looks like this:
HTML
<section class='modes-flex__options'>
<div class='options'>
<h2 class='options__title'>Options</h2>
<div class='options__item-container'id='1v1' onClick="selectedGameOption(this.id)">
<h3 class='options__item'>Player vs AI (1 v 1) </h3>
<div class='arrow-icon__div'>
<i></i>
</div>
</div>
<div class='options__item-container' id='1v1-tourny' onClick="selectedGameOption(this.id)">
<h3 class='options__item'>Player vs AI (Tournament)</h3>
<div class='arrow-icon__div'>
<i></i>
</div>
</div>
<div class='options__item-container' id='ai-v-ai-tourny' onClick="selectedGameOption(this.id)">
<h3 class='options__item' >AI vs AI (Tournament)</h3>
<div class='arrow-icon__div'>
<i></i>
</div>
</div>
</div>
</section>
CSS
.modes-flex{
display: flex;
margin-top: 3rem;
&__options{
flex:1;
display: flex;
justify-content: end;
}
&__description{
flex:1;
display: flex;
flex-direction: column;
}
}
.options{
margin-right: 5rem;
&__title{
font-size: 1.2rem;
padding-bottom:2rem;
}
&__item{
flex: 1;
padding-right: 5rem;
}
}
.description{
&__title{
font-size: 1.2rem;
padding-bottom:2rem;
}
}
.options__item-container {
padding: 1.5rem 1rem 1.5rem 1rem;
margin-bottom: 2rem;
box-shadow: 0 0 10px lightgrey;
border: 1px solid lightgrey;
display: flex;
align-items: center;
&:hover{
cursor: pointer;
}
}
.arrow-icon__div{
text-align: right;
}
.active-option{
background-color: $dark-navy;
color: white;
}
Tried to set min and max width and was still growing , just want them to stay even width after adding the icon.
You said it: The reason the box is growing is do to adding the "arrow-icon".
In my experience, in these situations, I always added to the default size of the boxes so that when another element (i.e. arrow-icon) is added, it doesn't change the size. (Because there is enough space in the box for arrow-icon to be added). With doing so, all the boxes remain the same through any actions.

How can I align an element right below another one but with some spacing to the side? [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 9 months ago.
Improve this question
How can I align an element right below another one but with some spacing to the side?
Use grid for that:
.container {
padding: 10px;
border: solid 1px;
width: 100%;
height: 300px;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 10px;
align-content: flex-start;
}
.item {
padding: 20px;
border: solid 1px;
text-align: center;
}
.item2 {
grid-column: 3 / 4;
}
.item4 {
grid-column: 3 / 4;
}
<div class="container">
<div class="item">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="item item4">4</div>
</div>
There are many potential solutions to this, including the more modern CSS Grid Layout. I have chosen to implement this using Flexbox. First I create a simple layout, separating the numbered boxes, which I will call tiles, into two columns. I set those columns within a row wrapper. I then apply flexbox properties to the row and columns so that the columns and the tiles within them arrange themselves properly according to the viewport size. Many of the other properties may need to be adjusted for your particular implementation, but all you have given is a picture which is not enough to describe what you want. Next time when asking a question, please show code, address what you already attempted, and fully explain the parameters of what you're trying to do. Details like if the tiles are of fixed size or need to be able to shrink with the viewport are helpful. My solution is below, I will do my best to answer any questions you may have.
*,
:before,
:after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
font-family: sans-serif;
font-size: 100%;
}
.row {
border: 2px solid #000;
margin: 1rem 10rem;
padding: 1.5rem;
min-width: 51.5rem;
overflow: hidden;
display: flex;
justify-content: space-between;
}
.col {
display: flex;
justify-content: space-between;
gap: 1.5rem;
}
.col--left {
margin: 0 1.5rem 1.5rem 0;
}
.col--right {
flex-wrap: wrap;
width: 31.5rem; /* double tile width + gap width */
}
.tile {
border: 2px solid #000;
height: 6.25rem;
width: 15rem;
font-size: 1.75rem;
text-align: center;
line-height: 6.25rem;
}
<div class="row">
<div class="col col--left">
<div class="tile">1</div>
</div>
<div class="col col--right">
<div class="tile">2</div>
<div class="tile">3</div>
<div class="tile">4</div>
</div>
</div>
You can view the above example on my CodePen.

Is Angular adding margin/padding to my component?

I'm facing a little problem.. I'm trying to build some kind of "Matrix" to build a snake game in angular, and for some reason, there is a margin / padding I can not remove. Here is my code:
<!-- snake.component.html -->
<div id="ng-snake-main">
<div *ngFor="let row of matrix" class="row">
<ng-container *ngFor="let box of row.boxes>
<snake-box [box]="box"></snake-box>
</ng-container>
</div>
</div>
<!-- box.component.html -->
<div class="box"></div>
Both using the same style file:
// styles.scss
.row {
margin: 0px;
padding: 0px;
}
.box {
display: inline-block;
background-color: blue;
width: 30px;
height: 30px;
border: 1px solid black;
}
so, why is there a space between rows??? I think that it doesn't make sense, but I'm sure I'm missing something. I'll left some screenshots:
In this screenshot you can check that the "snake-box" component is adding some kind of margin.
In this other screenshot you can see that the div actually doesn't have margin/padding.
Is angular adding margin to my component? If yes, how can I remove it?
The answer to you problem is CSS FLEX.
It would work with these styles:
// styles.scss
.row {
display: flex;
flex-direction: row;
}
.box {
background-color: blue;
width: 30px;
height: 30px;
border: 1px solid black;
}
If you want more information about flexbox, here is an interesting link https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Make a container with an image to the left and a title paragraph to the right in HTML/CSS

I'm trying to replicate a container image-text style for my landing page, but after hours of research I couldn't find any useful example for my problems which seems pretty basic.
Something like this
Is there a name for this type of container/header to look for them? I would love if someone could write a simple example to replicate it, because all of my solutions are not very elegant mainly because I am new to pure CSS (I'm being asked to not use any CSS libraries) I want my landing page to have multiple rows of this containers as this web page (without the animations of course) Overflow Webpage
So far I have tried something like this
HTML
<div class="header_2">
<article>
<h1>Multiples Odontólogos en todo Santiago</h1>
<p>If your knees aren't green by the end of the day, you ought to seriously re-examine your life.</p>
Únete >
</article>
<span class="helper"></span>
<img src="<%= assetPath('Land1.svg') %>" alt="Odontólogos por todo Santiago">
</div>
CSS
.header_2 {
padding: 10vh 15vw;
background: #def2f1;
text-align: center;
color: #17252a;
}
.header_2 img {
max-height: 30%;
max-width: 30%;
vertical-align: middle;
}
.header_2 article{
text-align: left;
padding-right: 50vw;
}
.header_2 h1 {
font-family: 'Kanit';
color: #17252a;
font-size: 1.7vw;
}
.header_2 p {
font-family: 'Montserrat';
color: #17252a;
font-size: 1vw;
}
.header_2 a {
font-family: 'Montserrat';
color: #3aafa9;
font-size: 1vw;
}
With these results:
My Actual Webpage
I can't set the image and text in the same line and my div is huge. Which is the most elegant and simple solution fr this type of style?
There are a few ways to do this.
Using flex:
Add this code to '.header_2' and adjust your padding-right on .header_2 article:
display: flex;
flex-direction: row;
align-items: center;
Using inline-block:
Add this code to '.header_2 article' and adjust the padding-right you have on this class:
display: inline-block;
width: 40%;
vertical-align: middle;
Using float:
With this option it won't be aligned vertically so depends on what you want.
Add this code to '.header_2 article' and adjust the padding-right you have on this class:
float: left;
|HTML|
<div class="header_2">
<div class="container">
<div class="box-6">
<img src="<%= assetPath('Land1.svg') %>" alt="Odontólogos por todo Santiago">
</div>
<article class="box-6">
<h1>Multiples Odontólogos en todo Santiago</h1>
<p>If your knees aren't green by the end of the day, you ought to seriously re-examine your life.</p>
Únete >
</article>
</div>
|CSS|
.header_2 {
padding: 10vh 15vw;
background: #def2f1;
color: #17252a;
margin:0;
}
.container{
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}
.box-6{
flex: 0 0 50%;
max-width: 50%;
}

Flex auto margins and previous / next button spacing

I have this situation with Previous/Next Project buttons where I could either have both previous and next project buttons showing, or just one depending on what page the user is on. (First project does not have prev button, last project does not have next button). Same code for all situations.
I used flexbox and justify-content: space-between; to space them normally, and then margin-left: 10px; on the prev button for mobile and it was perfect.
For 1 button case however I added margin-left/right to shove them to the left/right side of page. This overrides margin: auto.
So you see my problem now is with the 2 button situation on mobile. When these buttons collide obviously it looks terrible, I need margin in between but I have margin: auto already on them.
I have added my current state and all 3 situations below:
.project-controls {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.project-controls a {
width: 100%;
max-width: 200px;
padding: 10px 5px;
border: 1px solid #2c2c2c;
font-weight: 600;
text-align: center;
text-decoration: none;
text-transform: uppercase;
color: #2c2c2c;
transition: all 0.3s ease;
}
.project-controls .prev-proj {
margin-right: auto;
}
.project-controls .next-proj {
margin-left: auto;
}
<h1>Two buttons</h1>
<section class="project-controls">
<a class="prev-proj" href="#">Previous Project</a>
<a class="next-proj" href="#">Next Project</a>
</section>
<h1>One button prev</h1>
<section class="project-controls">
<a class="prev-proj" href="#">Previous Project</a>
</section>
<h1>One button next</h1>
<section class="project-controls">
<a class="next-proj" href="#">Next Project</a>
</section>
How can I keep my existing structure and still get that space in between on mobile? My best guess is having some sort of invisible spacer div that I could display with a media query, but just wondering if anyone has a quicker/cleaner solution I'm not thinking of?
Thanks
No need for margin auto on both. You can set a fixed margin-right for the previous element. You also don't need to use justify-content.
.project-controls {
display: flex;
flex-direction: row;
/* no need this too
justify-content: space-between;
*/
}
.project-controls a {
width: 100%;
max-width: 200px;
padding: 10px 5px;
border: 1px solid #2c2c2c;
font-weight: 600;
text-align: center;
text-decoration: none;
text-transform: uppercase;
color: #2c2c2c;
transition: all 0.3s ease;
}
.project-controls .prev-proj {
margin-right: 20px; /* Changed this */
}
.project-controls .next-proj {
margin-left: auto;
}
<h1>Two buttons</h1>
<section class="project-controls">
<a class="prev-proj" href="#">Previous Project</a>
<a class="next-proj" href="#">Next Project</a>
</section>
<h1>One button prev</h1>
<section class="project-controls">
<a class="prev-proj" href="#">Previous Project</a>
</section>
<h1>One button next</h1>
<section class="project-controls">
<a class="next-proj" href="#">Next Project</a>
</section>
I also use previous and next buttons on my web pages.
I also use flexbox and justify-content: space-between or an auto margin, depending on the site (I've switched it up just for variety; ultimately they both have the same effect).
I encountered the same problem as you with having only one button on the first and last pages.
My solution was to add a hidden button on the first and last pages. This keeps the layout behavior consistent on all pages, without a lot of extra CSS (just one or two lines for the .hidden class).
Then on smaller screens, to avoid the "collision" issue altogether, a media query kicks in with flex-direction: column.
.hidden {
visibility: hidden;
width: 0;
}
nav {
display: flex;
justify-content: space-between;
border: 1px dashed blue;
}
#media ( max-width: 500px ) {
nav { flex-direction: column; align-items: center; }
}
<h3>first page</h3>
<nav>
next
</nav>
<h3>middle page</h3>
<nav>
previous
next
</nav>
<h3>last page</h3>
<nav>
previous
</nav>
jsFiddle demo