skip to Main Content

I’m currently coding a reading website for my friend. It needs to work on mobile at just does that without the need for @media, except for 2 things. My summary and "read now" button.
website on pc When the screen becomes smaller I would like just the summary to be below the image but the "read now" button to be above the summary. In my html, the "read now" is below the summary so I’m not sure how to do that. Also, the summary is a part of a longer div that has the display: flex; to put them next to the image so I’m not sure how to put just the summary down. I still want it to look as it does right now on larger screens. Does anyone have any advice? Here’s my code

.flex {
    display: flex;
    gap: 2em;
}

.cover {
    max-width: 15em;
    max-height: 26em;
    border-radius: 0.5em;
}

.info {
    margin-top: 1.5em;
    max-width: 40vw;
}

.info h2 {
    font-size: 1.1em;
    margin-right: 0.5em;
    color: var(--primaryColour);
}

.title {
    display: flex;
    margin-bottom: 1.5lh;
}

.genre {
    display: flex;
    margin-bottom: 1.5lh;
}

.summary h2 {
    margin-bottom: 0.2lh;
}

.read {
    margin: 2em 3.5em;
}

.read a {
    padding: 1em;
    background-color: var(--secondaryColour);
    text-transform: uppercase;
    text-decoration: none;
    color: var(--darkColour);
    border-radius: 1em;
}

.read a:hover {
    text-decoration: underline;
}

/* Added by editor to reproduce styling in screenshot */
img.cover { border: 1px solid black; height: 418px; width: 240px; }
.read a { background-color: orange; }
   
<div class="flex">
    <img src="img/cover large.png" alt="Bored No More!" class="cover">

    <section class="info">
        <div class="title">
            <h2>Title:</h2>
            <p>Bored No More!</p>
        </div>

        <div class="genre">
            <h2>Genre:</h2>
            <p>Comedy/Fantasy/Slice of life</p>
        </div>

        <div class="summary">
            <h2>Summary</h2>
            <p>
                Not everyone can be a social person, Mango wasn't one. In fact, Mango was the type of person
                to
                sit
                in their room all day long and design and animate characters and upload them on the
                internet.
                This
                led to Mango being quite bored every day, and their only social interactions were when
                ordering
                a
                coffee, at their local coffee shop “A Cupfull of Charm”.
            </p>
            <p>
                One of Mango's most popular characters is Goober, a weird little marshmallow. The small
                Goober
                had
                become a fan-favourite amongst the large fanbase Mango had built. But suddenly, on a
                completely
                ordinary day, Mango had gone out to drink to finally be social. They were not that
                successful,
                but
                when Mango returned home they discovered something truly puzzling. Before them stood their
                animated
                character Goober.
            </p>
            <p>
                With this weird mystery upcoming, Mango had to try and figure out what was going on, or just
                entirely ignore this odd phenomenon…
            </p>
        </div>
    </section>
</div>

<section class="read">
    <a href="cha1.html">read now</a>
</section>

I thought of making the "read now" have position: absolute; but my attempt didn’t work. Other than did I didn’t try much before deciding I do not know the correct way to code this.

2

Answers


  1. Try adding flex-wrap: wrap to .flex, then using min-width and min-height on .cover and .info to force flex to wrap.

    Login or Signup to reply.
  2. So the order for mobile has to be: image > read now > summary?

    To obtain this first change the html to have all the elements inside the div class="flex", like this:

        <div class="flex">
        <img src="img/cover large.png" alt="Bored No More!" class="cover">
    
        <section class="info">
            <div class="title">
                <h2>Title:</h2>
                <p>Bored No More!</p>
            </div>
    
            <div class="genre">
                <h2>Genre:</h2>
                <p>Comedy/Fantasy/Slice of life</p>
            </div>
    
            <div class="summary">
                <h2>Summary</h2>
                <p>
                    Not everyone can be a social person, Mango wasn't one. In fact, Mango was the type of person
                    to
                    sit
                    in their room all day long and design and animate characters and upload them on the
                    internet.
                    This
                    led to Mango being quite bored every day, and their only social interactions were when
                    ordering
                    a
                    coffee, at their local coffee shop “A Cupfull of Charm”.
                </p>
                <p>
                    One of Mango's most popular characters is Goober, a weird little marshmallow. The small
                    Goober
                    had
                    become a fan-favourite amongst the large fanbase Mango had built. But suddenly, on a
                    completely
                    ordinary day, Mango had gone out to drink to finally be social. They were not that
                    successful,
                    but
                    when Mango returned home they discovered something truly puzzling. Before them stood their
                    animated
                    character Goober.
                </p>
                <p>
                    With this weird mystery upcoming, Mango had to try and figure out what was going on, or just
                    entirely ignore this odd phenomenon…
                </p>
            </div>
        </section>
    <section class="read">
        <a href="cha1.html">read now</a>
    </section>
    </div>
    

    Then place inside a media query the flex declaration "order" for each child element of the div father, and set the desired order of the elements for mobile (to better understand see media query at the end of the CSS code).
    N.B. Don’t forget to add some extra css to .flex to obtain the natural wrapping of the elements.

    .flex {
        display: flex;
        gap: 2em;
        /* add this to haveelements in row */
          flex-direction: row;
            /* add this to naturally wrap elements */
          flex-wrap: wrap;
    }
    
    .cover {
        max-width: 15em;
        max-height: 26em;
        border-radius: 0.5em;
    }
    
    .info {
        margin-top: 1.5em;
        max-width: 40vw;
    }
    
    .info h2 {
        font-size: 1.1em;
        margin-right: 0.5em;
        color: var(--primaryColour);
    }
    
    .title {
        display: flex;
        margin-bottom: 1.5lh;
    }
    
    .genre {
        display: flex;
        margin-bottom: 1.5lh;
    }
    
    .summary h2 {
        margin-bottom: 0.2lh;
    }
    
    .read {
        margin: 2em 3.5em;
    }
    
    .read a {
        padding: 1em;
        background-color: var(--secondaryColour);
        text-transform: uppercase;
        text-decoration: none;
        color: var(--darkColour);
        border-radius: 1em;
    }
    
    .read a:hover {
        text-decoration: underline;
    }
    
    /* Added by editor to reproduce styling in screenshot */
    img.cover { border: 1px solid black; height: 418px; width: 240px; }
    .read a { background-color: orange; }
    
    /* CSS Media Query - Works on screens that are 600px or less */
    @media screen and (max-width: 600px) {
      .cover{order: 1;}
      .read{order: 2}
      .info {order: 3}
    }
    

    Now, you have some other text before Summary, is not clear what you want to obtain at this point, but you can change the order inside this section in the same way, or set to display none to hie the unwanted elements on media query.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search