使用flex box时,我在对齐多个div项时遇到问题.主要用于div id=‘flow’.我希望内容标题和内容本身垂直对齐,同时以行/下方的形式显示它应该是这样的.try 使用对齐资源中心,甚至try 以多种方式对其进行包装,但由于它们是单独的实体,因此它们确实只在水平方向上垂直对齐

<!DOCTYPE HTML>
<html lang="en-us">
<head>
    <meta charset="utf-8" />
    <title>Pacific Trails Resort :: Activities </title>
    <link rel="stylesheet" href="pacific.css">
    <style type="text/css">
        #wrapper {
            display: grid;
            background-color: #FFFFFF;
            margin-left: auto;
            margin-right: auto;
            min-width: 960px;
            max-width: 2048px;
            box-shadow: 3px 3px 3px #333333;
        }

        body {
            background-color: #90c7e3;
            background: linear-gradient(white ,#90c7e3);
            background-repeat: no-repeat;
        }

        header {
            background-color: #002171;
            color: #FFFFFF;
            background-image: url(sunset.jpg);
            background-position: right;
            background-repeat: no-repeat;
            text-align: center;
        }

        header ul {
            margin: 0;
            padding: 0;
        }

        h1 {
            padding-top: .5em;
            padding-bottom: .5em;
            margin: 0;
        }


        h2 {
            color: #1976D2;
            text-shadow: 1px 1px #CCCCCC;
        }

        h3{
            color: #00003;
        }
        nav {
            background-color: #ffffff;
            font-weight: bold;
            padding: 0;
            padding-left: 0;
            text-align: center;
            margin: 0;
        }

        nav ul{
        list-style: none;
        margin: 0;
        padding: 0;

        }

        nav li{
        list-style: none;
        border-bottom: 1px solid #00008b;
        }

        nav a {
            list-style-type: none;
            text-decoration: none;
            padding: 8px;
            color: #002171;
        }

        ul{
            list-style-image: url(marker.gif);
        }

        dt{
            color: #002171;
        }

        main{
            padding-top: 1px;
            padding-right: 20px;
            padding-bottom: 20px;
            padding-left: 20px;
            display: block;
        }

        .contact{
            font-size: 90%;
        }

        footer{
            font-size: 75%;
            font-style:italic;
            padding: 2em;
            text-align: center;
        }

        #homehero{
            height: 300px;
            background-image: url(coast.jpg);
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }

        #yurthero{
            height: 300px;
            background-image: url(yurt.jpg);
            background-size: 100% 100%;
            background-repeat: no-repeat;

        }

        #trailhero{
            height: 300px;
            background-image: url(trail.jpg);
            background-size: 100% 100%;
            background-repeat: no-repeat;

        }

        .Resort{
            color: #1976D2;
            font-weight:bold;
        }

        @media (min-width: 600px){

            nav ul{
                flex-direction: row;
                flex:none;
                justify-content: space-around;
                border: none;
            }

            nav li{
                border-bottom: none;
                display: inline;
                text-align: center;
            }

            nav a {
                margin-right: 2em;
                margin-left; 2em;
                text-decoration: none;
                padding: 10px;
            }

            #flow{
                display: flex;
                flex-direction: row;
                flex: 1;
                justify: center;
                align-items: center;
            }
        }
    </style>
</head>
<body>
    <div id="wrapper">
        <header>
            <h1>Pacific Trails Resort</h1>
        </header>
        <nav>
            <a href="index.html">Home</a>
            <a href="yurts.html">Yurts</a>
            <a href="activities.html">Activities</a>
            <a href="index.html">Reservations</a>
        </nav>
        <div id="trailhero">

        </div>
        <main>
            <h2>Activities at Pacific Trails</h2>

            <div id="flow">
                <h3>Hiking</h3>
                <p>Pacific Trails Resort has 5 miles of hiking trails and is adjacent to a state park. Go alone or join one of our guided hikes </p>
                <h3>Kayaking</h3>
                <p>Ocean kayaks are available for guest use</p>
                <h3>Bird Watching</h3>
                <p>While anytime is a good time for bird watching at Pacific Trails, we offer guided birdwatching trips at sunrise several times a week.</p>
          </div>
        </main>
        <footer>
            <small>
                <i>Copy right &copy; 2022 Pacific Trails Resort</i><br />
                <a href="mailto:davilaco@asu.edu"> davilaco@asu.edu</a>
            </small>
        </footer>
    </div>
</body>
</html>

what is should look like

谢谢

推荐答案

我对您的代码进行了一些更改,将每个内容包装在div中并赋予其类card.我还更正了您的#flow样式,您使用的是justify而不是justify-content.

<main>
   <div class='title'>
     <h2>Activities at Pacific Trails</h2>
   </div>
   <div id="flow">
     <div class='card'>
       <h3>Hiking</h3>
       <p>Pacific Trails Resort has 5 miles of hiking trails and is adjacent to a state park. Go alone or join one of our guided hikes </p>
     </div>
     <div class='card'>
       <h3>Kayaking</h3>
       <p>Ocean kayaks are available for guest use</p>
     </div>
     <div class='card'>
       <h3>Bird Watching</h3>
       <p>While anytime is a good time for bird watching at Pacific Trails, we offer guided birdwatching trips at sunrise several times a week. </p>
     </div>
  </main>

Css:以下内容:

.title {
   align-items: center;
   justify-content: center;
   text-align: center;
 }
 #flow{
   display: flex;
   flex: 1;
   justify-content: center;
   align-items: center;
 }
 .card{
   text-align: center;
   width: 500px;
 }

Here's how it looks like

Html相关问答推荐

为什么使用Google字体的SVG徽标内的文本不能在网页上正确呈现?

当在双引号|Angular .html文件中使用时,Pretier会将单引号字符替换为&;Quot;

由于列中的图像,它们不会随FlexBox中的窗口大小进行调整

禁用与行分开的边框折叠span

让多对图像在各自的div中叠加

Bootstrap nav没有崩溃

如何更改Django中的默认按钮?

如何在悬停时使矩形按钮上的边框变圆

如何居中此按钮,即使它已经在计算机分辨率中居中

带圆角帽的 CSS 部分边框

使单行路径的 svg 填充父级的 100% 宽度

网页爬虫:使用时光机器进行数据采集

在选项标签中如何添加Django模板的条件

水平填充容器内的空间

主要元素内滚动时,固定导航栏会消失

为什么我的 div 元素没有形成一个圆形时钟?

两个span,一个在div居中,好像没有另一个,另一个在右边

使用 CSS 样式化进度条

我如何使用 HTML 和 CSS 在我的下拉菜单中获得这种类型的样式

所有幻灯片上的 Quarto RevealJS 标题