Media queries orientation: landscape

first, thank you for the recap.

i have a better, clear understanding when and how i should write my media queries

brain fart at my end

the ipad issue does not toggle, the hamburger can be seen but it doesn’t do anything when clicked

the url is www.forallthetime.com

not sure if cache is clear, need to follow up on that

yes… i did… i used the device word.

sorry!

how about for every time i use the “device” word, i owe you %0.00000000001 of my first million?

DEVICES NEVER AGAIN! : )

seriously, thank you for correcting me

i am not the brightest bulb in the chandelier, nor do i have the greatest memory!

but i will be a web developer

“My font-size clamp solved that issue without media queries. Or you can simply knock the font-size down a little bit in a media query at around 600px”

yes, please. good fit for me

and i do have the wrapping code.

“You need a smaller font for headings on smaller screen widths (I see your point and fully under stand and agree) but note body text should not be scaled smaller as body text is harder to read on a small device than it is on screen so I tend to make sure readable paragraphs are at least 1rem (16px) on smaller screens).” WELL SAID!

and most precious “You’ve made a good start” feels good! many thanks!

Paul, seriously, there is no way i could have done this without you

you have the patience of a saint

i am not going to take the code and run… i will try to figure it out and at least get the general concept

you are making me a better coder

if you ever want to learn to juggle, i would be more than happy to help you!

1 Like

It’s working on my ipad which is a really old one (ios 9.3.5) and if it works there it should work anywhere.

I’m guessing you have a cache issue as cache is hard to clear on some tablets. Also some tablets have a delay so you almost have to double tap to make things work (a quick first touch is often treated as a pseudo hover).

Hi Paul,

kindly see https://codepen.io/OBXJuggler/pen/zYKZzma

and www.forallthetime.com

i think you will be pleased!

i added prefect, well placed media queries at the proper break points

chrome dev tools were a HUGE help, thanks for that suggestion!

the navigation, logo and hamburger looks great on all media queries, i am well pleased… a little proud i made it this far

aesthetically, what are your thoughts on the logo? i do not want an image there right now. i would like to keep the text… change up the font-family? add a text color? text shadow? any advice is welcome!

long story short… WE MADE IT WORK

i am sincerely grateful to you!

you have made me a better coder!

i can take your advice and apply it to all future projects :grinning:

next up is the slide show, you have kindly provided code above

MANY THANKS!

T

PS,

how much of my first million do i owe you?

Yes its starting to look good now :slight_smile:

There’s a couple of little things you may want to rectify.:wink:

Firstly you have a horizontal scrollbar on small screen and that will be a small problem as the screen will wobble when anyone tries to scroll down with touch. It’s caused by the main-nav being right:-1px which puts it outside the viewport. Make it right:0; instead and it will be ok.

The second item that could be addressed is that you have placed padding on the h1 in the header and then in another rule for the anchor inside you use a negative top and margin of -1rem to offset the padding that was in place. You immediately create an unneeded dependency between 2 separate elements so rather than address 2 elements you should put the padding on the anchor and remove it from the parent. In that way you can just reduce the padding o n the anchor in the media query and know it doesn’t affect anything else.

Lastly you have a number of media queries at the same width so you can amalgamate those into one block rather than a separate block for each rule.

I’ve made those changes (quickly so double check) and forked the codepen to here:

I also note that you are using 2 h1s in the page and while that is allowed in html5 its generally better to have one main h1. I would suggest that you just use a div for the logo and leave the h1 for your main heading in the banner.

Those sort of changes are design issues and I’m not a graphic designer as such so leave those type of issues to the designers. I just concentrate on coding what’s required. At the end of the day its what looks best to you but always keep on eye on accessible colour contrasts as some colours just will not work well together.

1 Like

again, thanks for the tips!!

that latest pen worked fine!

i have successfully coded a slide show, the exact way i want it.

but it makes my navigation wonky :frowning:

i tried EVERYTHNG i could think of.

i suspect its an easy fix, but i can’t see it

seen on my site at https://forallthetime.com/

please help at your next earliest convenience : )

thanks

Run your css through the validator (as I mentioned before) to pick up any silly typos.

## W3C CSS Validator results for TextArea (CSS level 3 + SVG)

### Sorry! We found the following errors (8)

#### URI : TextArea

|168||Parse Error /* slide show code */ }|
| --- | --- | --- |
|296|.gallery|`space-around` is not a `flex-direction` value : space-around|
|452|#banner h1|Parse Error @media screen and (max-width: 600px) { .topnav a:not(:first-child), .dropdown .dropbtn { display: none; } .topnav a.icon { float: right; display: block; } }|
|477||Unknown error org.w3c.css.parser.analyzer.ParseException: Deprecated media feature “min-device-width”. For guidance, see the Deprecated Media Features section in the current Media Queries specification.|
|477||Unknown error org.w3c.css.parser.analyzer.ParseException: Deprecated media feature “max-device-width”. For guidance, see the Deprecated Media Features section in the current Media Queries specification.|
|477||`portriat` is not a `orientation` value|
|481||Parse Error|
|481||Parse Error|

The main error is here:

/* slide show code */
}  /* what's this stray bracket doing here */
.mySlides {display: none}
img {vertical-align: middle;}

The stray bracket actually goes here:

  @media screen and (max-width: 600px) {
    .slide h2 { 
    position: relative;
    top: 5rem;
    font-size: 1rem;
     text-align: center;  
    }
}/* the extra bracket should be here*/


/* ================================= 
  Media Queries
==================================== */

Stop using device-width (I’ve said that about ten times now) :slight_smile: This is invalid.

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation: portriat) {
  h1 {
      font-size: 1rem;
  }
}

It’s deprecated nonsense and no use to you (it’s broken anyway because of the typo in portrait). :slight_smile:

2 Likes

BINGO!

SUCCESS!

that’s a relief!

you wrote a ways back

“decide at what screen height the slideshow would look odd and at what width you think would be a minimum and you can combine both queries and set the slideshow to display:none.”

yes, i know better than to say landscape (there is no landscape) or say device

how can i display:none a slideshow on certain viewports dimensions, YET keep the same slideshow on different viewports dimensions?

i understand what height and width mean, but adding them together into a media query confuses me

why am i confused? i don’t remember using a media query like that… i honestly do not get this specific concept

see where i am coming from?

kindly give an example? that may help me learn

there is a lot to learn! i am learning it!

You already know how to do that.

e.g. If the slideshow looks a bit small at say 480px width then throw in a media query and set it to display:none.

@media screen and (max-width: 480px) {
  .slideshow-container,.dot{display:none} 
}

e.g. If the slideshow looks odd at a viewport with a small height then throw in a height media query and set it to display:none.

@media screen and (max-height: 600px) {
  .slideshow-container,.dot{display:none} 
}

However, I think that slideshow looks ok on the smallest phone so I don’t think you need to do either of those unless you want a minimal design on mobile (which is fine if that is what you want).

I notice that in your new code you have introduced a very bad practice that was in none of the examples I have given you and in one fell swoop defeats the point of responsive and semantic design :slight_smile:

The item in question is this.

<br><br><br><br>

Never, ever ever ever ever ever do that!

A break element <br> is used for making a break between lines of text such as in a poem or address where it is not the end of a paragraph as such. It is never a means of making space.

I can go months without using a break as they simply are only needed in certain circumstances. If you have text content then you have text in a paragraph and the closing p tag creates the line break. Divs create their own line break as do other block elements. You only need a break when you want to create a new line inside an inline fragment such as poem or address or perhaps in a form control (although there are still better ways of doing forms than using breaks).

In your page you simply had to add a bottom margin to the elements in question (.main and .slideshow-container) and then you keep complete control in the stylesheet. On smaller screens you now have big gaps between blocks and no amount of media queries will help because you have filled the html with breaks that you can’t target from the css. Use margins (and or padding) on existing elements to make space. Html does not make space on its own; it is a structural language. (In olden days a browser would ignore 2 breaks in a row anyway).

I also notice that you seem to have broken the small screen display by ,making the font-size event bigger than it was before.

Remove that erroneous media query where you set it to 3em.

I have made those changes here:

Lastly don’t be tempted to add inline styles even for testing as once in the html they are usually stuck there. Also avoid inline click handlers as that is a job to be done from the js file.

You have done both here:

<div style="text-align:center">
  <span class="dot" onclick="currentSlide(1)"></span>
  <span class="dot" onclick="currentSlide(2)"></span>
  <span class="dot" onclick="currentSlide(3)"></span>
  <span class="dot" onclick="currentSlide(4)"></span>
  <span class="dot" onclick="currentSlide(5)"></span>
  <span class="dot" onclick="currentSlide(6)"></span>
  <span class="dot" onclick="currentSlide(7)"></span>
  <span class="dot" onclick="currentSlide(8)"></span>
  <span class="dot" onclick="currentSlide(9)"></span>
  <span class="dot" onclick="currentSlide(10)"></span>
</div>

BTW that code should really be auto generated from the js based on the number of images present rather than being hard coded in the page. However that is a question for the JS forum.

2 Likes

ok. i am embarrassed. i should NOT be using <br>. understood.

i get its not good for responsive code

i thank you for pointing my error out. lesson learned.

i have been trying the validator on my own

what does “parse” or “parse error” mean?

i thought i fixed some, yet the error is still there

yes, i got the more serious errors corrected you kindly pointed out… thanks!

i feel my code is in a good place now.

not to sound like a broken record here… i sincerely appreciate your guidance and patience!

seriously, you may be the best person that has ever helped me with code concepts

you have what i need

i have learned from you

also, i feel i have a grasp on CSS.

you have been helping me with more complex or foreign (to me) CSS

i dont just want the code, i want to learn and understand the code… (or the general ideas)

where did you learn your CSS? kindly pass on a resource?

maybe a book? a website? a youtuber? a course?

again, i thank you!

It basically means the code is broken. The validator tries to parse the document as valid css but when it encounters something not in the specs it creates a parse error.

For example the first error shown is this.

Parse Error /* slide show code */ }

The parser find a stray bracket that does not belong to anything . It does not close anything and it does not open anything and indeed may be misinterpreted as a new element selector and not match anything either. In some cases one error can render all the following code invalid.

e.g. Say you had a stray typo (x in the example below):

x 
/* Give body a red background */
body {
  background: red;
}

That results in no background at all.

Why?

That’s because the browser sees the ‘x’ as an html selector and that results in a selector like this.

x body {
  background: red;
}

As there is no html element called ‘x’ in the document structure (and even if there was it would need to be a parent of the body element) the selector fails. If that was a media query with all your stylesheet in place then the whole lot fails. One error can disable a whole stylesheet or vast quantities of it in some cases. Or sometimes nothing happens because it recovers after a suitable closing bracket somewhere else that is closer.

Initially I learned by joining a number of web design forums and looking at all the html and css questions that were asked and if there was anything I didn’t understood I practiced until I knew the answer. In the end I knew more than ‘some’ of the experts that were answering the questions.

It’s mainly practice, practice and more practice but writing one of the first books on CSS did help :slight_smile: . Although these days there is so much more to learn that few people are expert over all aspects of css as grid and flexbox can take a while to master on their own and I’m pretty average at CSS grid (mainly because I don’t need it most of the time but the more I start to use it the better I will become).

Sitepoint has some good courses but they are not free. It’s worth the effort though because I find that if you pay for something you are generally going to try and get your money’s worth out of it and stick with it for longer.

2 Likes

Hi Paul

i put some thought and time into this before i ask

please see forallthetime.com

break point width 768px

i am looking to make the header background color dark green

works until 768px

after its white, almost white

boy i thought of everything i could!

tried all my ideas, no go

yes, i reviewed our previous posts but cannot find a solution to this problem

did not find any hints…

if they ARE there, i apologize

see https://codepen.io/OBXJuggler/pen/wvzVBJK

at a narrow browser… THAT is what i am after

not sure why its good on codepen but won’t behave elsewhere… i have been using chrome… could that be my problem?

the code we have talked about… light green / black text

dark green / white text

kindly help me out :slight_smile: :grinning:

please leave comments so i understand

again, i sincerely appreciate your time and guidance!

MANY THANKS!

Hi,

It’s in the media query here.

 /* use hasJS class to hide navigation on small screen */
  @media (max-width: 768.9px) {
    .hasJS .main-nav {
      position: absolute;
      left: -1px;
      right: -1px;
      top: 100%;
      transform: translateY(-100%);
      opacity: 0;
      transition: 0.5s ease;
      background: #eee;
      border: 1px solid #a2a2a2;
      box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0.75);
    }
    .hasJS .open .main-nav {
      opacity: 1;
      transform: translatey(0%);
    }
    .hasJS .header h1 {
      background: #f4f4f4;
    }
  }

Specifically this;

    .hasJS .header h1 {
      background: #f4f4f4;
    }

Just change that color to darkgreen and you should be good to go :slight_smile:

the background is on the h1 in that section and you were probably looking for the header. You will also need to change colours on the drop down but they are all in that section also :slight_smile:

1 Like

IT WORKED!

thanks so much!

just the way i want it

i feel good / proud i figured out the dropdown color without asking you

working on the media queries and break points now

again, thank you!

1 Like

follow up,

having issues writing media queries for the dropdown hamburger links

is it in that same block you provided?

somewhere else?

thank you!

Yes you would put your smaller screen nav styles in that section. You don’t have the js in your demo so you are getting a different view but you should be able to style things ok.

having trouble making smaller screen styles for the drop down nav

i reviewed your post, experimented with the code

tried everything i thought of

i kindly ask for the proper code, please leave comments so i can learn

thanks!

also, i really hope you can help me out here

responsive google calendars

i did research on google, codepen and even sitepoint, nothing helped

i hope you can save me some time and trouble here, most appreciated!

first, are responsive google calendars possible? realistic, easy?

ALL the code i looked at and tried were not at all useful

i think i read somewhere it simply is not possible (paraphrasing)

if proper, kindly pass on the code or point me to a site that helps

is it even worth my time perusing responsive google calendars?

is there an alternative? with events eg 2021 October 31st: Halloween

i sincerely hope you dont mind me asking these questions here :slight_smile:

again, i thank you!

You will need the js to toggle the hamburger menu and to add the hasJs class to the html element.

(function (d) {
  "use strict";

  var myToggle = d.getElementById("toggle");
  var toggleParent = d.getElementById("header");
  // use this hasJS class to make sure JS was enabled and then we can use it in css to hide things
  d.querySelector("html").classList.add("hasJS");

  // toggle the class called open which will add a call to the header so we can use css once again to hide and show the menu
  myToggle.addEventListener(
    "click",
    function () {
      toggleParent.classList.toggle("open");
    },
    false
  );

That routine allows for the clicking of the hamburger to show the dropdown menu. It also adds a class of .hasJS to the html element which lets us know that js has been enabled. If js is enabled then we can hide the menu and place it as a dropdown. If js is disabled the menu is displayed open by default otherwise there would be no navigation.

As I said above you just need ot add the styling you want in that media query. Here are a few basics added:

/* use hasJS class to hide navigation on small screen */
@media (max-width: 768.9px) {
  #toggle{display:none;}
  .hasJS #toggle {display:block;}
  .hasJS .main-nav {
    position: absolute;
    left: -1px;
    right: -1px;
    top: 100%;
    transform: translateY(-100%);
    opacity: 0;
    transition: 0.5s ease;
  }
  .hasJS .open .main-nav {
    opacity: 1;
    transform: translatey(0%);
  }
  .header h1 {
    background: darkGreen;
  }
  .main-nav a {
    padding: 0.5rem 1rem;
    border-top: 1px solid #000;
  }
  .main-nav {
    background: green;
    border: 1px solid #000;
    box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0.75);
  }
}

That will make the menu look like this when open:

Screen Shot 2021-02-01 at 12.14.50

…and when closed:

Screen Shot 2021-02-01 at 12.15.03

Sorry that’s not my area.

I assume if you are embedding the calendar via an iframe then you are limited to using the padding-top aspect ratio trick only,

1 Like

SUCCESS!

your code worked

i had some trouble, but did some problem solving and now its working well

not to sound like a broken record but THANK YOU!

there is no way i could make this work without your guidance

1 Like

Hi Paul,

the site looks good!

on mobile, EVENTS & PROGRAMS is a new page. notice the navigation does not collapse, EVENTS & PROGRAMS stays put and the hamburger is not shown

is this because its a new page?

also, when i open up “Links” and toggle the hamburger again “nearby places of interest” is highlighted

please help

need i do something special to the code if i want to add more pages? besides making .html .css for the page of course

again, thanks!

Hi,

You need to include the hamburger script in each page that needs it.

  (function (d) {
  "use strict";
        
  var myToggle = d.getElementById("toggle");
  var toggleParent = d.getElementById("header");
  // use this hasJS class to make sure JS was enabled and then we can use it in css to hide things
  d.querySelector("html").classList.add("hasJS");

  // toggle the class called open which will add a call to the header so we can use css once again to hide and show the menu
  myToggle.addEventListener(
    "click",
    function () {
      toggleParent.classList.toggle("open");
    },
    false
  );
})(document);

You seem to have the active class on the wrong pages in some cases. On the links page the html for the nearby places is highlighted.

<a href="nearby-places-of-interest.html" class="active">Nearby Places of Interest</a>

That active class should be on the links page anchor instead (but only when on the links page). You need to add the active class to the current item on each page so the html for each of those menus is different in that the active class is moved to the correct item.

Also I note that you change the position of some of the menu items on other pages which is not a good idea. If you click the Articles link then Nearby Places is next to it but usually that position would be occupied by Events.