需要帮助对齐列表和图像(HTML CSS)

问题描述 投票:0回答:1

我正在尝试对齐在列表旁边的 div 语句中定义的图像。

    body { background-color: #3799DF;
    color:#1B78BB;
        font-family: Arial;
        margin: 0; }

    * { box-sizing: border-box; }

    header { background-color: #3799DF;
    background-image: url(FullLogoBanner.png);
    background-position: left;
    background-repeat: no-repeat;
    font-size: 105%;
    max-height: 250px;  }

    header a { text-decoration: none; }

    header a:link { color: #40407A }

    header a:visited { color: #40407A }

    header a:hover { color: #FFF }

    h1 { padding-top: 80px; 
    padding-left: 6em; }

    nav { font-weight: bold;
    text-align: center; 
    position: relative; 
    padding-bottom: 1.5em; }
    nav a { text-decoration: none; 
    display: block;
    border-width: 2px;
    border-style: groove;
    border-color: #1B78BB;
    padding: 0.7em;
    background-color: #8ADFFF;
    margin-left: 0.5em;
    margin-right: 0.5em; }

    nav a:link { color: #000000; }

    nav a:visited { color: #40407A; }

    nav a:hover { color: #3799DF; border: 2px groove #333333; }

    nav ul { list-style-type: none; 
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    margin: 0; }

    nav ul ul { position: absolute;
        background-color: #FFF;
        padding: 0;
        text-align: center;
        display: none; }

    nav ul ul li { display: block;
        border-width: 2px;
        border-style: groove;
        border-color: #8ADFFF;
        padding: 0.5em;
        background-color: #FFF; 
        width: 8em; }

    nav li:hover ul { display: block; }

    main { padding-left: 2em;
    padding-right: 2em;
    display: block; }

    section {padding-left: .5em;
    padding-right: .5em; }

    footer { font-size: .70em; 
    font-style: italic; 
    text-align: center;
    color: #000000;
    padding: 1em;
    background-color: #8ADFFF; }

    .name { font-weight: bold; }

    .home { height: 40vh;
    padding-top: 2em; 
    padding-left: 10%; }

    .content { height: 40vh;
    padding-top: 2em; 
    padding-left: 10%; }

    #mobile { display: inline; }

    #desktop { display: none; }

    #wrapper { background-color: #F5F5F5;
    padding: 2em; }

    #homeimg { background-image: url(petstore_dog.jpg);
    background-repeat: no-repeat;
    height: 300px;
    background-size: contain;
    display: none; }

    .header {  text-decoration: underline; }
    #column { display: flex;
    flex-direction: column; 
    align-items: center; }

    #center { text-align: center; 
    padding-left: 1.5em;
    margin: auto; }

    #left { text-align: left;
    padding: 1em; 
    margin: auto; }

    table { width: 100%;
    margin: auto;
    border: 1px solid #3799DF;
    border-collapse: collapse;
    margin-bottom: 1em; }

    td, th { padding: 1px;
    border: 1px solid #3799DF;
    text-align: center; }

    tr:nth-of-type(odd) { background-color: #89CFF0; }

    caption { margin: 1em; 
    font-weight: bold;
    font-size: 120%; }

    form { display: flex;
    flex-direction: column;
    padding-left: 1em;
    width: 80%; }

    input { margin-bottom: .5em; }

    @media (min-width: 645px) {
        
        header { background-color: #3799DF;
        background: url(LogoDesign2.png) no-repeat left,
        url(Pawprints.png) repeat-x bottom,
        url(Pawprints.png) repeat-x;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        font-size: 150%;
        max-height: 355px; }

        .home { height: 50vh; }
        .content { height: 50vh; }

        nav ul { display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center; } 
        
        section { padding-left: 2em;
        padding-right: 2em; }
    
        #homeimg { display: block; }
    
        #flow { display: flex;
        flex-direction: row; }

        form { display: grid;
        grid-gap: 1em;
        grid-template-columns: 12em 1fr;
        width: 60%; }
        input[type="submit"] { grid-column: 2 / 3;
                width: 9em; } 
        label { float: right; }
    

        #mobile { display: none; }
    
        #desktop { display: inline; } 
    
        table { width: 80%;  } 
    

    @media (min-width: 1045px) {
        header { background: url(LogoDesign1.png) no-repeat left,
        url(LogoDesign1.png) no-repeat right,
        url(Pawprints.png) repeat-x,
        url(Pawprints.png) repeat-x bottom; 
        font-size: 160%; }

        .home { height: 50vh; }
        .content { height: 50vh; }
        #wrapper {margin: auto;
        width: 75%; } 
        footer { margin: auto;
        width: 75%; }
        table { width: 65%; } }

这是我的CSS ^

`<div id="wrapper">
<main>


    <h2>Your Local Pet Shop</h2>
    <p><span class="name">Furry Baby</span> is the best place to go for all your pet shopping needs
in the Hyde Park area. We provide options for all your favorite furry friends including: Dogs, Cats, and Birds.
<br>Our services have allowed pet owners to thrive with their best friends since 1989. Come to <span class="name">Furry Baby</span>
and let your animal companion live their best life!</p>

    <p>We cater towards cat, dog, and bird owners!<br> Currently we sell:</p>
    <ul>
       <li>Leashes</li>
       <li>Collars</li>
       <li>Toys</li>
       <li>Treats</li>
       <li>Cages</li>
       <li>And more!</li>
    </ul>

    <div id="homeimg">
    </div>
    
    <span class="name">Furry Baby</span><br>
    123 Hyde Park North<br>
    Tampa, Florida, 33606<br><br>
    <a id="mobile" href="tel:888-555-5555">888-555-5555</a>
    <span id="desktop">888-555-5555</span>


</main>`

这是我主页的一部分^

我尝试使用 Flexbox 行容器来对齐它们,但它不起作用,我尝试将它们分别设置为向左和向右浮动。理想情况下,我希望图片位于左侧,列表位于右侧,但无论我尝试什么,列表最终都会脱离页面/未对齐,或者如果我将其浮动,图像就不会显示。

html css image html-lists
1个回答
0
投票

您可以将内容包装在

.wrapper
类中,然后对其应用 Flexbox,并将两个部分分组到 div 中。像这样的东西:

body { background-color: #3799DF;
    color:#1B78BB;
        font-family: Arial;
        margin: 0; color: white; }

.wrapper {
  display: flex;
  gap: 1rem;
}
<div id="wrapper">
<main>
<div>
  <div class="wrapper">
    <div id="homeimg">
      <img src="https://images.pexels.com/photos/36717/amazing-animal-beautiful-beautifull.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
    </div>
    
    <div>
    <h2>Your Local Pet Shop</h2>
    <p><span class="name">Furry Baby</span> is the best place to go for all your pet shopping needs
in the Hyde Park area. We provide options for all your favorite furry friends including: Dogs, Cats, and Birds.
<br>Our services have allowed pet owners to thrive with their best friends since 1989. Come to <span class="name">Furry Baby</span>
and let your animal companion live their best life!</p>

    <p>We cater towards cat, dog, and bird owners!<br> Currently we sell:</p>
    <ul>
       <li>Leashes</li>
       <li>Collars</li>
       <li>Toys</li>
       <li>Treats</li>
       <li>Cages</li>
       <li>And more!</li>
    </ul>
    
    <span class="name">Furry Baby</span><br>
    123 Hyde Park North<br>
    Tampa, Florida, 33606<br><br>
    <a id="mobile" href="tel:888-555-5555">888-555-5555</a>
    <span id="desktop">888-555-5555</span>
  </div>

    
  </div>
</main>

© www.soinside.com 2019 - 2024. All rights reserved.