skip to Main Content

Im trying to align my image that is defined in a div statement next to a list.

    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%; } }

Here is my 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>`

Here is part of my home page ^

I’ve tried using a flexbox row container to align them and it does not work, I’ve tried setting them both to float left and right, respectively. Ideally, I would want the picture on the left and the list on the right but no matter what I try either the list ends up off the page/unaligned or the image just doesn’t show up if I put it to float.

2

Answers


  1. You can wrap your content in a .wrapper class, and apply flexbox to it, and group your two sections into divs. Something like this:

    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>
    Login or Signup to reply.
  2. so I would start with making sure that I understand css flexbox properly. By this I mean reading those articles:

    https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox

    https://css-tricks.com/snippets/css/a-guide-to-flexbox/

    And later on I would try to implement flexbox in similar fashion to the snippet below. You are on the right track, just keep on going 🙂

    .flex {
      display: flex;
    }
    
    .flex-row {
      flex-direction: row;
    }
    
    .justify-between {
      justify-content: space-between;
    }
    
    .w-full {
      width: 100%;
    }
    
    .bg-red {
      background-color: red;
    }
    
    .bg-blue {
      background-color: blue;
    }
    
    .bg-yellow {
      background-color: yellow;
    }
    <div class="flex flex-row justify-between w-full bg-yellow">
      <ul class="bg-red">
        <li>Leashes</li>
        <li>Collars</li>
        <li>Toys</li>
        <li>Treats</li>
        <li>Cages</li>
        <li>And more!</li>
      </ul>
    
      <div id="homeimg" class="bg-blue">
        There will be some img I guess.
      </div>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search