Wednesday, December 18, 2013

Divs, mobile platform viewing, and sizing! (HTML, CSS, JavaScript)

So today I learn about how to make webpages look less horrible on mobile devices. Personally I hate hate hate mobile sites, because usually they change more than the way images scale and stuff.. they make an entirely new layout and it fucks everything up. But anyway, let us begin.

Apparently when making a website for that good-for-nothing whore Esha, I wasn't really understanding what I was doing when making div elements to hold photos and such of Esha's dishes. Specifically, the difference between making those photos the size of "cover" instead of "100%" or a specific pixel size.

We predefined the div height to 200px, and a div takes its width from the width of its parent element (Thanks Ian!) which, in this case, is max-width: 600px. Works out pretty perfectly for our photos... almost too perfectly...



Here's where stuff can get tricky. The body has a MAX width of 600, which is fine for the photos when the page is displayed in a bigger window. HOWEVER, on a mobile platform you probably don't have that 600px width unless you browse in landscape and the length is weird and shit. If these images were set to 100%, they would be resizing themselves to fit inside the div.

If the div goes down to 400px width, then in order for the picture to display 100%, the height of the picture must be scaled down to roughly 133px. If you remember, we made the height of the div 200px. That won't change. By default, there won't just be black-space for the other 66px of height.. it will be a repeat of the picture, like so:


For this reason, Cover is better because it just cuts the image off a bit and doesn't let it repeat. Looks slightly better.


HOORAY STORM OF SCREENSHOT'D PICTURES!

So, we'll use media queries (if, then statements) to fix this mess. But not after I watch American Horror Story with my bestie who is on her way over. EVAN PETERS IS A HOTTIE AMIRITE? I'd cover him, that's for sure.




4 comments:

  1. Potentially stupid question: With the cover method, it seems to be cutting off a pretty significant portion of the image. If that's the case, why wouldn't you just crop the image ahead of time, knowing that it's going to do that? What if you considered the entire image to already be perfect? On a plate of food, it isn't much of an issue, but it seems like a really annoying option for a picture of three friends and the Statue of Liberty. (Feel free to call me an idiot if I've missed something obvious.)

    ReplyDelete
    Replies
    1. Well, it would be hard to crop the image ahead of time because you never know what dimensions the reader will be looking at your web-page from.

      I guess one thing we could do is add a minimum-width that would ensure we see the entire photo and that the page doesn't scale down too much (then you'd just have to scroll or zoom to see the picture).

      I'll probably be learning more about alternatives and better solutions soon. Stay posted!

      Delete
  2. We are tied directly into the sate’s renewal database which allows us to process your request almost instantly. https://www.miuiupdates.com/2021/03/remove-bloatware-android.html

    ReplyDelete
  3. Cool stuff you have and you keep overhaul every one of us 交友平台

    ReplyDelete