Ich code aus Übungszwecken ein OnePageLayout mit Flexbox. Komischerweise tritt wieder das bekannte Problem mit justify-content: center; & align-items: center; auf.
Ich möchte in <section id="seite_1> einen Container mit 50% Breite definieren. Der dem untergeordnete Container <div class="content_box_seite_1"> igonriert jedoch folgende Angaben ;
Code
.content_box_seite_1 {
width: 50%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
Wenn ich justify-content: center; & align-items: center; <section id="seite_1> zuweise, dann funktioniert es. Warum ist das so ?
HTML
<!DOCTYPE html>
<html lang="de">
<head>
<title>OnePageLayout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style_alt.css" media="all" type="text/css">
</head>
<body>
<nav>
<div class="title">OnePageLayout</div>
<div class="nav_links">
<ul>
<li><a href="#header">startseite</a></li>
<li><a href="#seite_1">über mich</a></li>
<li><a href="#seite_1">links</a></li>
</ul>
</div>
</nav>
<header id="header">
<h1 class="header_title">OnePageLayout</h1>
<h2 class="header_subtitle">Lorem ipsum dolor sit amet</h2>
</header>
<section id="seite_1">
<div class="content_box_seite_1">
<figure><img src="images/platzhalter.jpg" alt="platzhalter" class="responsive"></figure>
<article>
<h3>Lorem ipsum dolor sit amet</h3>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</article>
</div>
</section>
</body>
</html>
Alles anzeigen
Code
@import url('https://fonts.googleapis.com/css2?family=Cairo&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Amatic+SC&display=swap');
html, body, #header, #seite_1, #seite_2, #seite_3 {
height:auto;
min-height: 100vh;
}
html {
scroll-behavior: smooth;
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
font-family: 'Cairo', sans-serif;
background-color: #fff;
color: #777;
}
nav {
position: fixed;
display: flex;
justify-content: space-between;
align-items: center;
padding: 30px;
width: 100%;
background-color: #fff;
box-shadow: 0 2px 2px -2px rgba(0,0,0,.2);
}
.title {
font-size: 30px;
font-family: 'Amatic SC', cursive;
background-color: #fff;
color: #777;
}
.nav_links ul {
display: flex;
}
.nav_links li {
list-style: none;
}
.nav_links a {
font-family: 'Cairo', sans-serif;
text-decoration: none;
background-color: #fff;
color: #777;
padding: 5px;
}
.nav_links a:hover {
background-color: #ccc;
border-radius: 3px;
}
#header {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-image: url(images/background.jpg);
background-size: cover;
}
.header_title {
font-size: 75px;
font-family: 'Amatic SC', cursive;
font-weight: 700;
text-align: center;
color: #fff;
padding: 5px;
border-radius: 4px;
}
.header_subtitle {
font-size: 35px;
font-family: 'Amatic SC', cursive;
font-weight: 500;
text-align: center;
color: #fff;
padding: 5px;
border-radius: 4px;
}
.content_box_seite_1 {
width: 50%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.responsive {
width: 100%;
height: auto;
}
/*responsive Elemente*/
@media only screen and (max-width: 800px) {
nav {
flex-direction: column;
}
.nav_links {
margin: 10px;
}
.header_title {
font-size: 30px;
}
.header_subtitle {
font-size: 15px;
}
}
/*responsive Elemente*/
Alles anzeigen