I am trying to figure out a solution for the misalignment of my paragraph text within a flexbox element

I am facing an issue with my flexbox where I cannot align the p elements inside the "newDog" div. My goal is to have them all left-aligned so that they can be neatly stacked underneath the dl contents.

See below for the code snippet:

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap');
body{
    background-color: rgb(255, 222, 176);
}
#newDog{
    display: flex;
    background-color: antiquewhite;
    flex-wrap: wrap;

}
#newDog img{
    float: left;
    margin: 10px 10px 10px 10px;
    clear: both
    
}
#newDog dl{
    font-family: 'Montserrat', sans-serif;
    position: relative;
    align-self: flex-start;
    margin-top: 5em;
}
#newDog p{
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    position: inherit;
    align-self: flex-start;
    vertical-align: baseline;

}
<body>
    <header>
        <img src="https://i.imgur.com/zk3.png" alt="Aussies R Us" title="Aussies R Us">
        <h1>&#9886; Our Aussies &#9887;</h1>
    </header>

    <nav>
        <a href="index.html">Home</a> &nbsp; &#9475; &nbsp;
        <a href="ouraussies.html">Our Aussies</a> &nbsp; &#9475; &nbsp;
        <a href="faq.html">FAQ</a> &nbsp; &#9475; &nbsp;
        <a href="contactus.html">Contact Us</a> &nbsp; &#9475; &nbsp;
    </nav>

    <main>
        <div id="newDog">
            <img src="https://i.imgur.com/R3l8.jpg" width="500" height="500" alt="Max" title="Max">
            <dl>
                <dd>Name: Max</dd>
                <dd>Availablility: Not Available</dd>
                <dd>Breed: Standard Australian Shepherd</dd>
                <dd>Gender: Male</dd>
                <dd>Height: 20-25 inches</dd>
                <dd>Weight: 50-60 lbs</dd>
                <dd>Age: 1-2 Years old</dd>
                <dd>Activity Level: Medium - High</dd>
            </dl>
                <p>
                    Meet Max! He is a great young Australian Shepherd, he is a very smart dog, and learns quickly. <br>
                    Max loves to be around people, even though he is not a very good lap dog, he never <br>
                    wants to be left out of the fun, and will stick around wherever there is people. Max <br>
                    loves other animals, small and big. He is very gentle when being introduced to other <br>
                    animals, and tends to watch after his smaller brothers.
                </p>
        </div>
        <br>
        <div id="newDog">
            <img src="https://i.imgur.com/o2Kp.jpg" width="500" height="500" alt="Odyn" title="Odyn">
                <dl>
                    <dd>Name: Odyn</dd>
                    <dd>Availablility: Not Available</dd>
                    <dd>Breed: Mini Australian Shepherd</dd>
                    <dd>Gender: Male</dd>
                    <dd>Height: 14-18 inches</dd>
                    <dd>Weight: 15-25 lbs</dd>
                    <dd>Age: 4-5 Months old</dd>
                    <dd>Activity Level: Low - Medium</dd>
                </dl>
                <p>
                    Meet Odyn! He is a young pup that is looking to find a good lap to lay on and sleep! <br>
                    Odyn loves to play with his brothers Max and Jack Jack, but he also loves a good nap. <br>
                    If you are looking for a pup to laydown and watch a show with, Odyn is the pup for you!
                </p>
        </div>
        <br>
        <div id="newDog">
            <img src="https://i.imgur.com/MWy.jpg" width="500" height="500" alt="Jack Jack" title="Jack Jack">
                <dl>
                    <dd>Name: Jack Jack</dd>
                    <dd>Availablility: Not Available</dd>
                    <dd>Breed: Yorkie</dd>
                    <dd>Gender: Male</dd>
                    <dd>Height: 7-9 inches</dd>
                    <dd>Weight: 14-18 lbs</dd>
                    <dd>Age: 3-4 Years old</dd>
                    <dd>Activity Level: Low - Medium</dd>
                </dl>
                <p>
                    Meet Jack Jack! He isn't exactly an Aussie pup, but he is a cute guy nonetheless. Jack <br>
                    loves to chill out and sit on someones lap even more than his brother Odyn. Don't let <br>
                    that fool you though, when Jack wants to play, he plays! Jack Jack, loves to wrestle <br>
                    with his cat friend Meep. Sometimes he wins, sometimes Meep wins, its a never ending battle!
                </p>
        </div>
    </main>

    <footer>&copy; 20 R Us</footer>
</body>

Answer №1

Consider enclosing your text content, DL, and P tag segments within a div container with a class of info for better padding control. Update the ID "newdog" to a class and utilize display: flex; instead of floating the image element. This will naturally position the dl above the p tag. It's also recommended to reset padding and margin in your CSS to avoid unexpected browser behavior. As a final recommendation, remove the BR tags from your P tag unless specific line breaks are desired, letting the viewport handle the spacing automatically.

Note about IDs... An ID attribute should be unique to a single element. For styling multiple elements similarly, prefer using classes. Hence, I transitioned the newdog ID to a class.

Additionally, incorporating @media queries in your CSS can enhance the responsiveness of your design on different screen sizes, ensuring optimal display of images and text content. To fully appreciate these changes, view this snippet in full-screen mode =)

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap');
* {
  padding: 0;
  margin: 0;
}

body {
  background-color: rgb(255, 222, 176);
}

.newDog {
  display: flex;
  background-color: antiquewhite;
}

.info {
  padding-left: 2rem;
}

.newDog dl {
  font-family: 'Montserrat', sans-serif;
  position: relative;
  margin: 5em 0 2em;
}

.newDog p {
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  position: inherit;
  vertical-align: baseline;
}
<body>
  <header>
    <img src="https://i.imgur.com/zb8Wvk3.png" alt="Aussies R Us" title="Aussies R Us">
    <h1>&#9886; Our Aussies &#9887;</h1>

  </header>

  <nav>
    <a href="index.html">Home</a> &nbsp; &#9475; &nbsp;
    <a href="ouraussies.html">Our Aussies</a> &nbsp; &#9475; &nbsp;
    <a href="faq.html">FAQ</a> &nbsp; &#9475; &nbsp;
    <a href="contactus.html">Contact Us</a> &nbsp; &#9475; &nbsp;
  </nav>

  <main>
    <div class="newDog">
      <img src="https://i.imgur.com/R3yolM8.jpg" width="500" height="500" alt="Max" title="Max">
      <div class="info">
        <dl>
          <dd>Name: Max</dd>
          <dd>Availability: Not Available</dd>
          <dd>Breed: Standard Australian Shepherd</dd>
          <dd>Gender: Male</dd>
          <dd>Height: 20-25 inches</dd>
          <dd>Weight: 50-60 lbs</dd>
          <dd>Age: 1-2 Years old</dd>
          <dd>Activity Level: Medium - High</dd>
        </dl>
        <p>
          Meet Max! He is an intelligent young Australian Shepherd who loves human companionship. Max enjoys interacting with other animals and is very caring towards his smaller counterparts.
        </p>
      </div>
    </div>
    <br>
    <div class="newDog">
      <img src="https://i.imgur.com/o2KAyxp.jpg" width="500" height="500" alt="Odyn" title="Odyn">
      <div class="info">
        <dl>
          <dd>Name: Odyn</dd>
          <dd>Availability: Not Available</dd>
          <dd>Breed: Mini Australian Shepherd</dd>
          <dd>Gender: Male</dd>
          <dd>Height: 14-18 inches</dd>
          <dd>Weight: 15-25 lbs</dd>
          <dd>Age: 4-5 Months old</dd>
          <dd>Activity Level: Low - Medium</dd>
        </dl>
        <p>
          Meet Odyn! This playful pup seeks comfort and relaxation. Whether it's playtime or naptime, Odyn is up for either one!
        </p>
      </div>
    </div>
    <br>
    <div class="newDog">
      <img src="https://i.imgur.com/MDBBTWy.jpg" width="500" height="500" alt="Jack Jack" title="Jack Jack">
      <div class="info">
      <dl>
        <dd>Name: Jack Jack</dd>
        <dd>Availability: Not Available</dd>
        <dd>Breed: Yorkie</dd>
        <dd>Gender: Male</dd>
        <dd>Height: 7-9 inches</dd>
        <dd>Weight: 14-18 lbs</dd>
        <dd>Age: 3-4 Years old</dd>
        <dd>Activity Level: Low - Medium</dd>
      </dl>
      <p>
        Meet Jack Jack! Although not an Aussie, Jack is an adorable companion who loves cuddling more than anything else. When it comes to playtime, he's always ready for some fun!
      </p>
      </div>
    </div>
  </main>

  <footer>&copy; 2021 Aussies R Us</footer>
</body>

Answer №2

Be sure to enclose all p tags within the dl tag in order to meet your specific needs

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Another option for "top-margin" in CSS?

I'm having some trouble fitting navigation tabs onto an <article> element, especially in Firefox and on different screen sizes. Does anyone have a solution that works across all browsers and maintains consistency when the screen is resized? The ...

What causes the CSS Sticky property to override neighboring elements as it moves?

My Goal: I am attempting to create a scrolling list on the page. Everything works fine until the last element, which seems to erase all the other elements. * { margin: 0; padding: 0; font-family: 'Ubuntu'; box-sizing: border-box; } bo ...

Is the PNG image displaying poorly in the IE10 browser?

My application features a PNG image with actual dimensions of 300px X 300px. I am using a 20% scale of this image as an input image button, which displays correctly in Mozilla and Chrome browsers. However, in IE, the image appears distorted. Please refer t ...

The distinct advantages of utilizing both HTML and PHP together in web development

What is the difference between using HTML code within PHP code and PHP code within HTML code? Does it impact performance? ...

CSS background image that will not be affected by padding-top

Is there a way to make a background image override the top padding on the first section of a website? I have set padding-top to separate the first title from the navbar, but now I want the background image to take precedence. Thank you! Using HTML: < ...

Tips for incorporating a CSS class or id into Html.PagedListPager

Currently utilizing a PagedListPager: @Html.PagedListPager((IPagedList)Model, page => Url.Action("InboxWithNoReplyListPaging", new { page = page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "G ...

`Turn nested JSON into a formatted list using jquery`

I am currently facing two challenges: I am having trouble with the HTML structure, as shown in the image below Current HTML structure: https://i.stack.imgur.com/GH46J.png Desired HTML structure: https://i.stack.imgur.com/Dq3Gn.png How can I create d ...

Issue with jQuery AJAX parsing The response is not in the

I've been struggling with a small jQuery script that is supposed to pull JSON from a website on my domain. No matter how long I work on it, I just can't seem to get it right. Whenever I set the "dataType" as json, I receive a status error of 0. H ...

What could be causing my custom CSS to not take effect on a progress bar within my JSP page?

Struggling to incorporate a progress bar into my JSP page to track order status, I'm facing issues with applying custom CSS. Despite using !important to override conflicting styles, it seems like other frameworks (such as Bootstrap) might be taking pr ...

Dynamic Navbar that Adapts to Your Scroll

I'm experiencing an issue with my navbar. I want it to stay at the top of the page when I scroll, but whenever I apply the "position: fixed;" property, the navbar disappears. Below is my HTML and CSS code: <nav> <div class="navbar"> <b ...

"Maintain element in a fixed position at the top of the page while scrolling

From the static screenshots, it's evident that an <audio> element is fixed at the top of the page upon scrolling. However, the preference is to have the element visible even before any scrolling occurs. The current solution involves using cumbe ...

Annoying Gap Found Between <header> and <nav>

I am encountering an issue with the spacing between the <header> and <nav> in my HTML5 code. Despite trying to adjust the padding, there remains approximately 5 pixels of empty space that I cannot seem to remove. If anyone could provide insigh ...

Determine whether the final element has been selected

I'm investigating how to check if the last td within a specific tr has been clicked. Here's an example of my HTML: <table> <tr> <td>Foo</td> <td>Bar</td> <td>Clicked</td> ...

Generate a consolidated dataframe by parsing through various HTML files

I have a collection of 23 HTML files that all contain data in the same tabular format. I am looking to combine this data into one large dataframe for further analysis. Below is the code snippet I am using: import glob import pandas as pd all_records = g ...

Looking for a way for the inner div to overlap the outer div while maintaining transparency on both layers

Seeking assistance with a div issue. I have an inner div that needs to extend beyond an outer div, which is not a problem. However, I am struggling to make the outer div clip where the inner div extends. The challenge is that both divs need to be transpar ...

What is the best way to add angular's ui-sref directive to a link element?

I am currently using AngularJS for one of my app and came across an interesting scenario in one of my views: <span>My URL: <a ui-sref="mystate({ arg1_name: 'arg1_val', arg2_name: 'arg2_val'})">XXX</a></span> Ev ...

How do I insert a variable into my email content using PHP?

Hey there, I have a form that captures Name, Email, Subject, Telephone Number, Message, and a checkbox. Unfortunately, I'm not very proficient in PHP. I've just started learning the basics and could use some guidance from you :) The Form < ...

Frustrating Problem with Favicon Displays in Various Web

I am experiencing an issue with my favicon setup. Initially, I had the following code in the root of my project: <link rel="icon" href="favicon.ico" /> When I first ran the project, the favicon displayed correctly. However, upon running it again to ...

Grails Error: Cannot find method signature for org.apache.catalina.core.ApplicationHttpRequest.getFile()

Every time I try to access the upload page of my Grails application, I encounter this error message: No signature of method: org.apache.catalina.core.ApplicationHttpRequest.getFile() is applicable for argument types: (java.lang.String) values: [file] ...

The initial selection in the First DropDown does not activate the function of the second DropDown

I am facing an issue with my MVC application that involves using AngularJS for two DropDowns. The first DropDown successfully populates with data from the DB. However, when a user selects an option from the first DropDown, the second one should update acco ...