DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • CSS Variables in Media Queries
  • Introduction To Template-Based Email Design With Spring Boot
  • Architecture and Code Design, Pt. 2: Polyglot Persistence Insights To Use Today and in the Upcoming Years
  • Design to Support New Query Parameters in GET Call Through Configurations Without Making Code Changes

Trending

  • GenAI-Infused ChatGPT: A Guide To Effective Prompt Engineering
  • Spring WebFlux Retries
  • Next.js vs. Gatsby: A Comprehensive Comparison
  • Automated Testing: The Missing Piece of Your CI/CD Puzzle
  1. DZone
  2. Data Engineering
  3. Databases
  4. Responsive Design with CSS Media Queries

Responsive Design with CSS Media Queries

Matt Raible user avatar by
Matt Raible
·
Apr. 12, 13 · Interview
Like (1)
Save
Tweet
Share
7.47K Views

Join the DZone community and get the full member experience.

Join For Free

in preparation for my upcoming talk on bootstrap and css3 , i figured it was high time i made this blog responsive. making my new theme mobile-friendly has been on my todo list ever since last year's redesign . i also took the opportunity to 1) remove the geolocation lookup and associated sunset logic for theme selection and 2) change the default theme to the "light" one. if you prefer dark, just click on the black rectangle in the top-right.

i started by refreshing my knowledge of media queries by reading css media queries & using available space . this led me to john hick's site , where i grabbed a couple of his rules. most notably, i started optimizing for iphone, smartphones and any screens less than 1000px wide. i also decided to widen things a bit for larger screens.

/* smartphones */
@media handheld and (max-width: 480px), screen and (max-device-width: 480px), screen and (max-width: 1000px) {

}

/* large desktop */
@media screen and (min-width: 1200px) {

}

when i started hacking away, i noticed a lot of the elements had "width" hard-coded in pixels, so i changed a lot of these to use "max-width" instead, as well as "width: 100%". this allowed me to only have a few elements that controlled the width and i was able to take advantage of larger screens with the following simple rules.

@media screen and (min-width: 1200px) {
    #site-container, #body-content, #header-inner {
        max-width: 1170px;
    }

    #body-content #left-column, .next-previous {
        max-width: 808px;
    }
}

for smartphones, i started by hiding the right column and menus with display: none. then i decided the navigation menu might be useful if i ever wanted to manage the site on my phone. i found create an absolute basic mobile css responsive navigation menu from the treehouse blog and went to work. 20 minutes later, i had the menu i was looking for and everything was looking pretty good in ios simulator.

raibledesigns.com on ios simulator

at this point, i discovered that rotating to landscape mode caused the content font to become quite a bit larger. so i added a rule for the iphone in landscape mode.

/* iphone landscape */
@media screen and (min-width: 321px) and (max-width: 480px) and (orientation: landscape) {
    #body-content #left-column .article .contents {
        font-size: 9px;
    }
}

i'm still not sure why this happens. i also noticed that rotating back to portrait causes some empty whitespace to show up on the right. the empty whitespace was a problem i spent most of my time solving. i ended up using web inspector with ios simulator to figure out which elements were bleeding past my desired width and then adjusted their width, or used overflow: hidden to hide them.

i enjoyed this mobile design experience, even with the many "why is there whitespace there!" moments. i especially liked it when i found i didn't need any rules for the ipad. i'm sure there's a few issues that still exist. for example, i haven't tested it on an android device. also, the facebook button's "color-scheme" is still hard-coded in my templates. i hope to fix this by patching roller to allow reading cookies on the server-side. if you notice anything that looks funny, please let me know.

in the meantime, i hope you enjoy squishing and stretching your modern browser to see how this new responsive design works.



Media queries CSS Database Media (communication) Design

Published at DZone with permission of Matt Raible, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • CSS Variables in Media Queries
  • Introduction To Template-Based Email Design With Spring Boot
  • Architecture and Code Design, Pt. 2: Polyglot Persistence Insights To Use Today and in the Upcoming Years
  • Design to Support New Query Parameters in GET Call Through Configurations Without Making Code Changes

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: