SlideShare a Scribd company logo
1 of 29
CSS - position



foto: miuenski
Boxar
        foto: lightmash
Boxar

        När webbläsare med hjälp av
        CSS ritar upp ett html-
        dokument gör den det i en
        form av boxar.
        Dessa boxar ligger under och
        ”i varandra” i en hierarki

        Det finns två huvudsakliga
        boxar:
         • Block-boxar
         • Inline-boxar (”text”)
        Denna demo handlar om hur
        man placerar block-boxar
Placering   Foto: koshyk
Placering




Man kan placera
element med CSS
Fyra egenskaper för placering
  top     Positivt värde på top flyttar neråt



  right   Positivt värde på right flyttar åt vänster




 bottom    Positivt värde på bottom flyttar uppåt



  left     Positivt värde på left flyttar åt höger
Till exempel så här

A                          top

B                         right

C                         bottom

D                          left

E
Position




       foto: Julie Berlin
Fyra värden för position

         Static

        Relative

       Absolute

         Fixed
         (inherited)
foto: steve-h   Normalt flöde
position: static; = normalt flöde

 A
                        Static
 B

               Boxarna kommer i den
 C
               ordning de finns i html-
 D             koden.
 E
position: relative; = normalt flöde

  A
                        Relative
  B

  C

  D
                Boxen flyttas i förhållande
   E            till sig själv
Boxar ur flödet vid…

A
                  Absolute
B

C                   Fixed
D

E
position: absolute; ur flödet

A
                   Absolute
B

C

D

E
Viktigt begrepp: positionerad




    Positionerad
    I förhållande till…?
I förhållande till webbläsarfönstret

   A         I ”normalfallet”, dvs. om vi säger att B ska ha:
                position: absolute;
             placeras den i förhållande till webbläsarfönstret.
   B         Här med värden för left och top.

   C

   D

   E
”Syskon, barn, föräldrar & förfäder”


                               body




           Div id=”ett”                         Div id=”tva”



           P                                                   P
   h1                     P              P
           class=”uno”                                         class=”due”




  Barn     Syskon             Förälder       Förfader
”Syskon, barn, föräldrar & förfäder”

  body

  div id=”ett”      Body är förälder till div id=”ett”

    h1
                    div id=”ett” förälder till h1 och båda p.
    p class=”uno”
                    div id=”ett” och body är förfäder
    p

  div id=”tva”      Body förälder till div id=”tva”

    p               div id=”tva” förälder till båda p.
    p class=”due”   div id=”tva” och body är förfäder
”Normalfallet” absolut placering

body

div id=”ett”

  h1
 p class=”uno”
  p

div id=”tva”

  p
  p class=”due”
”Närmast positionerade förfader”
                   body

                     div id=”ett”
body
                            Om id=”ett” är positionerad,
 div id=”ett”               (dvs relative, absolute eller fixed)
                            och dessutom närmsta förfader,
  h1                        placeras class=”uno” i förhållande
 p class=”uno”              till den, inte webbläsaren.
  p

 div id=”tva”

   p
   p class=”due”
                     div id=”tva”
”Med kod:”
                    body
                    div id=”ett”
body
                    .uno {
div id=”ett”          position:absolute;
                      bottom: 10px
  h1                  right: 10px;
  p class=”uno”     }
  p                 #ett {
                      position:relative;
div id=”tva”        }
  p
  p class=”due”
                    div id=”tva”

                                           p class=”uno”
”Ett absolut placerat




                            Regel
 element positioneras i
 förhållande till närmast
 positionerade förfader”


Foto: Aunt Owwee
Fixed




                            Fixed
Foto: Darwin Bell
position:fixed;

          är samma som
         position:absolute;
        med en stor skillnad:

       Den är alltid positionerad
 i förhållande till webbläsarfönstret!
(Den ligger kvar på samma plats, även
       om man rullar innehållet.)
Det innebär!
En sak kvar


          Z-index
Foto: mag3737
När man placerar
relative, absolute eller fixed
kan de olika elementen komma att täcka varandra.
Vilken som kommer överst beror på något som kallas
stacking context.

Man kontrollerar det med egenskapen z-index.
Exempel: z-index: 1;

Den fungerar mycket enkelt:
Högst z-index hamnar överst.
Z-index: 27




              Foto: Horia Varlan
Det var teorin.

Nu är det bara att
   praktisera!

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Css position

  • 2. Boxar foto: lightmash
  • 3. Boxar När webbläsare med hjälp av CSS ritar upp ett html- dokument gör den det i en form av boxar. Dessa boxar ligger under och ”i varandra” i en hierarki Det finns två huvudsakliga boxar: • Block-boxar • Inline-boxar (”text”) Denna demo handlar om hur man placerar block-boxar
  • 4. Placering Foto: koshyk
  • 6. Fyra egenskaper för placering top Positivt värde på top flyttar neråt right Positivt värde på right flyttar åt vänster bottom Positivt värde på bottom flyttar uppåt left Positivt värde på left flyttar åt höger
  • 7. Till exempel så här A top B right C bottom D left E
  • 8. Position foto: Julie Berlin
  • 9. Fyra värden för position Static Relative Absolute Fixed (inherited)
  • 10. foto: steve-h Normalt flöde
  • 11. position: static; = normalt flöde A Static B Boxarna kommer i den C ordning de finns i html- D koden. E
  • 12. position: relative; = normalt flöde A Relative B C D Boxen flyttas i förhållande E till sig själv
  • 13. Boxar ur flödet vid… A Absolute B C Fixed D E
  • 14. position: absolute; ur flödet A Absolute B C D E
  • 15. Viktigt begrepp: positionerad Positionerad I förhållande till…?
  • 16. I förhållande till webbläsarfönstret A I ”normalfallet”, dvs. om vi säger att B ska ha: position: absolute; placeras den i förhållande till webbläsarfönstret. B Här med värden för left och top. C D E
  • 17. ”Syskon, barn, föräldrar & förfäder” body Div id=”ett” Div id=”tva” P P h1 P P class=”uno” class=”due” Barn Syskon Förälder Förfader
  • 18. ”Syskon, barn, föräldrar & förfäder” body div id=”ett” Body är förälder till div id=”ett” h1 div id=”ett” förälder till h1 och båda p. p class=”uno” div id=”ett” och body är förfäder p div id=”tva” Body förälder till div id=”tva” p div id=”tva” förälder till båda p. p class=”due” div id=”tva” och body är förfäder
  • 19. ”Normalfallet” absolut placering body div id=”ett” h1 p class=”uno” p div id=”tva” p p class=”due”
  • 20. ”Närmast positionerade förfader” body div id=”ett” body Om id=”ett” är positionerad, div id=”ett” (dvs relative, absolute eller fixed) och dessutom närmsta förfader, h1 placeras class=”uno” i förhållande p class=”uno” till den, inte webbläsaren. p div id=”tva” p p class=”due” div id=”tva”
  • 21. ”Med kod:” body div id=”ett” body .uno { div id=”ett” position:absolute; bottom: 10px h1 right: 10px; p class=”uno” } p #ett { position:relative; div id=”tva” } p p class=”due” div id=”tva” p class=”uno”
  • 22. ”Ett absolut placerat Regel element positioneras i förhållande till närmast positionerade förfader” Foto: Aunt Owwee
  • 23. Fixed Fixed Foto: Darwin Bell
  • 24. position:fixed; är samma som position:absolute; med en stor skillnad: Den är alltid positionerad i förhållande till webbläsarfönstret! (Den ligger kvar på samma plats, även om man rullar innehållet.)
  • 26. En sak kvar Z-index Foto: mag3737
  • 27. När man placerar relative, absolute eller fixed kan de olika elementen komma att täcka varandra. Vilken som kommer överst beror på något som kallas stacking context. Man kontrollerar det med egenskapen z-index. Exempel: z-index: 1; Den fungerar mycket enkelt: Högst z-index hamnar överst.
  • 28. Z-index: 27 Foto: Horia Varlan
  • 29. Det var teorin. Nu är det bara att praktisera!