Vefforritun 1 kennd haustið 2025



If you’ve ever used Photoshop then you’ll know what happens when you select “New” from the “File” menu: you will be asked to enter fixed dimensions for the canvas you are about to work within. Before adding a single pixel, a fundamental design decision has been made that reinforces the consensual hallucination of an inflexible web.
Relinquishing control does not mean relinquishing quality. Quite the opposite. In acknowledging the many unknowns involved in designing for the web, designers can craft in a resilient flexible way that is true to the medium.

Byggir á, í mikilvægis röð:
“Responsive Web Design: Serves the same HTML code on the same URL regardless of the users’ device (for example, desktop, tablet, mobile, non-visual browser), but can render the display differently based on the screen size. Google recommends Responsive Web Design because it’s the easiest design pattern to implement and maintain.”
—Google – Mobile SEO Overview
“The web’s greatest strength, I believe, is often seen as a limitation, as a defect. It is the nature of the web to be flexible, and it should be our role as designers and developers to embrace this flexibility, and produce pages which, by being flexible, are accessible to all.”
—John Allsopp – A Dao of Web Design
“The primary design principle underlying the Web’s usefulness and growth is universality. […] And it should be accessible from any kind of hardware that can connect to the Internet: stationary or mobile, small screen or large.”
—Tim Berners-Lee — Long Live the Web
Byggir á:
max-width á umgjörð til að setja hámarksbreidd

Myndir frá 9 basic principles of responsive web design
target ÷ context = resultem1600px umgjörð og innan hennar 1200px efnissvæðipx (nákvæm stærð) notum við hlutfall í prósentum
1200 ÷ 1600 = 0,75 eða 75%Getum skilgreint með flexbox og margin æfingum:
margin-left og margin-right upp á hálft gutterpadding-left og padding-right á hvern dálk
box-sizing: border-box; er lykill til að láta gangamargin-left og margin-right til að færa efni til í dálkumEða notað CSS grid! Skoðum nánar í næsta fyrirlestri.
Dæmi um flexbox grind með margins
max-width: 100%; á img passar að mynd fylli alltaf út í foreldi sittobject-fit hjálpar tilpadding-topaspect-ratiomax-width – skilgreinum reglur upp að þeirri víddmin-width – skilgreinum reglur frá þeirri víddand-a saman en gerum sjaldan—reynum að halda einföldu/* almennt er section 100% breitt */
section {
width: 100%;
}
/* frá 800px breiðum viewport er
section 50% breitt */
@media (min-width: 800px) {
section {
width: 50%;
}
}
1000px til að vinna með?“ o.s.fr.clamp() er fall sem við getum notað með neðri mörkum, reiknuðu gildi, og efri mörkumfont-size: clamp(1rem, 16px + 1vw, 4rem);
Getum líka gert með aðeins flóknari aðferð sem kölluð er fluid typography.
html { font-size: 16px }
@media screen and (min-width: 320px) {
html {
font-size: calc(16px + 6 * ((100vw - 320px) / 680));
}
}
@media screen and (min-width: 1000px) {
html {
font-size: 22px;
}
}
<picture> elementið veitir okkur frekari stjórn yfir því hvernig myndir birtast<picture>
<source
srcset="/stor.jpg"
media="(min-width: 800px)"
>
<img src="/litil.jpg" alt="">
</picture>
<picture> og srcset attribute til að stjórna enn frekar<picture>
<!-- ef vafri styður webp, nota -->
<source
type="image/webp"
srcset="img.webp, img-2x.webp 2x, img-3x.webp 3x">
<!--
fyrir skjái með 2x eða 3x device pixel
ratio birtum við stærri myndir sem þá
birtast „greinilegri“
-->
<img
srcset="img-2x.jpg 2x, img-3x.jpg 3x"
alt="" width="600" height="600" src="img.jpg">
</picture>
<meta name="viewport">Getum leiðbeint vafra hvernig síða birtist:
width setur breidd viewports:
tala – föst breidddevice-width — viewport er jafnt logical resolution ekki physical resolutioninitial-scale, upphafs zoom á síðuminimum-scale, hversu lítil síða má verða — hve langt má zooma útmaximum-scale, hversu stór síða má verða — hve langt má zooma innuser-scalable, má zooma? viljum ekki banna<meta
name="viewport"
content="width=device-width,initial-scale=1"
>
Ef við skilgreinum ekki width=device-width í <meta name="viewport"> og notum media queries mun vefurinn okkar ekki birtast eins og við höldum í tækjum með hærri raunupplausn.