Mismatched photo caption positioning beneath image (html, CSS)

Question from a beginner: I'm attempting to position a photo on the right side of a webpage, with text wrapping around it on the left, and the photographer credit directly under the photo.

The issue is that the credit is appearing on the left side above the text header rather than below the photo on the right.

This is my HTML code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'/>
    <link rel='stylesheet' href='test.css'/>
  </head>
  <body>
    <picture>
      <img class='pic' src='images\str_pic1.JPG' alt="Person in blue shirt" />
      <figcaption class='pic'>Photo Credit: Photographer</figcaption>
    </picture>
    <div>
      <h2>Title</h2>
      <p>Text body here, lorem ipsum etc.</p>
    </div>
  </body>
</html>

This is my CSS code:

.page {
  font-size: 100%;
  background-color: #777;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.pic {
  width: 35%;
  float: right;
  margin-left: 20px;
}

I attempted enclosing the pic and credit in a div container and using the following in the CSS:

.pic-box {
  display: flex;
  flex-direction: column;
}

Unfortunately, this solution did not work as expected.

This is my first time asking a question here, feedback on how I can improve is appreciated!

Answer №1

It appears that I have made the necessary changes you were looking for. I switched out your <picture> and figcaption elements with div elements, as they are more versatile. The wrapping div, originally <picture>, now has the class of picwrap, while the former figcaption div is now styled with the class piccap, ensuring it differs from the picture class, which is pic.

In addition, I introduced the following CSS adjustments:

.picwrap {
  float: right;
  text-align: center;
}

.pic {
  max-width: 35vw;
}

Below is a functional demonstration incorporating an image I inserted along with additional text to showcase the wrapping effect.

.page {
  font-size: 100%;
  background-color: #777;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.picwrap {
  float: right;
  text-align: center;
}

.pic {
  max-width: 35vw;
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'/>
    <link rel='stylesheet' href='test.css'/>
  </head>
  <body>
    <div class="picwrap">
      <img class='pic' src='https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2F3.bp.blogspot.com%2F-h0-QmJgoc0A%2FUynUaTP3h1I%2FAAAAAAAACOI%2FrmJPmSiM388%2Fs1600%2Fjavanes2.jpg&f=1&nofb=1&ipt=2d9c6496df9f3008cb82378322a186661b08e10918f56fd1458cf7d8db784cfe&ipo=images' alt="Person in blue shirt" />
      <div class='piccap'>Photo Credit: Photographer</div>
   </div>
    <div>
      <h2>Title</h2>
      <p>Text text text etc. this is the text body   Text text text etc. this is the text bodyText text text etc. this is the text...
    </div>
  </body>
</html>

Answer №2

Here are the changes you requested for your .pic: I believe this will achieve the look you desire!

.pic {
    width: 40%;
    float: center;
    margin-left: 25px;
  }

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

The PHP code is experiencing issues on the enquiry/callback form, but it is functioning correctly on the contact form

I'm having trouble understanding why I am only getting the telephone number and missing the name and email fields when submitting a form. I have tried making changes, but I can't get all three fields to work properly. <aside clas ...

What is the reason behind the failure of a distinct milestone (such as w-70) to show progress in Bootstrap, unlike w-25, w-50, w-75, and w-100, and what steps can be

As I navigate through Bootstrap using <div>, I aimed to reach a milestone of 70%. However, when I tried setting w-70, the progress bar only displayed around 5%. It seems that this issue persists with values like w-45, w-50, w-75, and w-100 only. Her ...

What are some creative ways to customize the appearance of a PHP email form body?

I need assistance in creating a PHP form that will generate an email with visually appealing formatting. Currently, when I receive the submitted form via email, it lacks aesthetic presentation. After implementing the following code snippet, this is how th ...

Automatically adjusting the top margin of the main content section depending on the variable height of a fixed header

Visit our mobile site here (mobile view) Currently, I have set the margin-top of .main-content based on sticky-animation, which keeps the header fixed at the top on mobile. However, there is a div with a close button (X) that alters its height dynamically ...

Restrict the Number of Columns in GridView

I am currently working with a gridview that displays product information. I'm trying to find a way to limit the description field so that only the first few lines are shown if it is too long, and also resize the image to fit into the image column whil ...

How to organize the cpuinfo output in BASH

I'm currently working on a script that collects information from our servers and outputs the results to an HTML file. Everything is going smoothly up to a certain point. I've run into an issue when trying to grab the cpuinfo. While it does extrac ...

I am seeking assistance in troubleshooting this javascript code. Can someone please help me identify the issue?

function validateCredentials() { var username = document.forms["myForm"]["name"].value; var admin = "admin"; var user = "user"; var master = "master"; if (username == "&qu ...

Aligning images and input fields vertically with relative measurements

I'm looking for a way to vertically position two images, one on the left and one on the right, so that they are centered between labels and input fields within a containing div. Is it achievable using only relative lengths? Check out this jsfiddle fo ...

Is there a flaw in how Firefox handles text-overflow and inline-block?

It seems that according to the text-overflow specification, the ellipsis effect only applies to inline elements: This property defines how content within an inline element is displayed when it overflows its container's boundaries in the inline dire ...

I would like to create a border for the radial gradient and apply it to the div as well

Below is the CSS code I have written. div { height: 150px; margin: 5em 2em; background: radial-gradient(circle at top center, transparent, transparent 70px, black 70px, black); border-radius: 8p## Heading ##x; position: relative; } .circle { ...

Switch up the placement of the boxes by moving them in different directions, such as

I've been attempting to recreate the button movement demonstrated in this link , but I'm having trouble achieving it. Using CSS animation, I can make the buttons move in a straight line, here's what I have so far: <div id="box" style=&ap ...

The data variable in Vue.js does not show up in the view even when it is populated through an AJAX request

I am facing an issue with my code, where the 'tarefas' variable is not appearing in my v-for loop. I have verified that the response from the server is correct and the data is being received. Interestingly, when I add new data in the input field, ...

Centering div elements in ASP.NET using C# and Javascript

I am looking to create a functionality on my website where, upon clicking a button, a DIV appears in the center of the browser, overlaying all other content. I have already created the DIV and managed its visibility toggle, but I'm struggling with the ...

Creating a collapsing drop down menu with CSS

I utilized a code snippet that I found on the following website: Modifications were made to the code as shown below: <div class="col-md-12"> ... </div> However, after rearranging the form tag, the drop-down menu collapse ...

Thumbnail Carousel Caption in Bootstrap 3

Is it possible to create a Bootstrap 3 carousel where the image changes when the mouse cursor hovers over the thumbnail under the carousel? Currently, I have a setup with the carousel and thumbnails below it. Typically in Bootstrap, the image changes autom ...

Is it possible to embed PHP code within an XML document?

I have been working on creating an automatic "sitemap.xml" file. I followed the guidelines provided by Google and managed to put together the following: <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/s ...

`Arrange Buttons Horizontally in Bootstrap`

I've been struggling to align my two bootstrap buttons next to each other horizontally, instead of on top of one another vertically. Despite researching and trying various suggestions, I still can't seem to get it to work... Below is the code I ...

Three responsive images neatly arranged within separate div containers

Looking to have these 3 divs align horizontally with responsive images. Having trouble maintaining the layout when setting max-width. Any suggestions? .fl { display: flex; flex-wrap: no-wrap; height: 35%; flex-direction: row; } .pic { width: ...

Is there an issue with the padding not functioning correctly on smaller and medium-sized devices when using Bootstrap

On my desktop, I added '50px' padding to the body of my page and it's working properly. However, on smaller and medium screens, it's not functioning correctly. I tried using Bootstrap @media CSS functionality, but it still doesn't ...

Include money symbols within input fields with padding and vertical alignment

I am looking to create an input field that includes either € or $ currency symbols. The challenge is ensuring perfect vertical centering inside the input, especially when using padding. Is there a foolproof method to achieve this? https://i.stack.imgur ...