Which parent container to use for a figure with float:left AND some explanatory text to the right?

:smiley:

That’s exactly what is wanted.

Trying to explain the matter in a slightly different way.
To begin with, the actual structure is:

<main>
  <section>
  <figure class="figure-left">
    <figcaption class="figcaption-top">
      <details>
        <summary class="summary-top">
          ... 
        </summary>
        <img 
          width="175"
          height="159" 
          ...
        >
      </details>
      <img 
        width="175"
        height="159" 
        ...
    </figcaption>
  </figure>
  <p>
   ... 
  </p>
  </section>
  <section class="clear">
  </section>
</main>

If, in the same structure, one could apply something like:

     <img 
          width= 30vw
          height= 28vw
          ...
        >

in both occurences, it would be perfect for the purpose, achieving an indentical look, now controllable by units of vw (in this example).
Only, HTML/CSS-wise, this cannot be done…

No you would never (rarely) do something like that as an image has an intrinsic aspect ratio and the height and width must be maintained at a correct aspect ratio which cannot be achieved by using both width and height together when based on a flexible measurement (excluding object-fit for the time being as you don’t want to crop the image in any way).

What you would usually do is give the image a percentage width based on either its container or the viewport and the image height would be set to auto which will maintain the aspect ratio of the image. You should never squash an image from its original aspect ratio unless its just a wild pattern of sorts.

e.g.Here’s one way to scale the image properly.

.figure-left img{
  box-shadow:0 0 10px 10px rgba(0,0,0,0.3);
  border:1px solid red;
  display:block;
  width:15vw;
  max-width:320px;
  min-width:135px;
  height:auto;
}

It has width based on the viewport and also a min and max width to stop it getting too big or too small. At all times the height must remain at auto.

I’ve added it to the codepen here:

Not also that I use a page-wrap div with a max-width to stop the page filling the viewport because on my 27" imac that would leave one long line of text that is impossible to scan. Its not always about the size of the layout but the size of the items in the layout and you can’t have long lines of text endlessly filling the viewport. Imagine on a 50" TV trying to read multiple lines of text that stretch from end to end. If you do some research you will soon see a lot of advice on what readable line lengths should be and what size the text should be :slight_smile:

Hope that helps :slight_smile:

1 Like

And how it helped - thank you!
The main points you mentioned are understood basically - sorry for my incomplete knowhow regarding sizes causing confusion… :blush:

A last Pencode is ready now, including the proposed control of the relative width of the figure.

Before finally closing the topic, two questions are remaining in my poor brain:

  1. in .summary-top {…}, align-content: center seems non-effective
    How could this be done differently?

  2. regarding .summary-top i{margin-left:.2rem; font-style:normal;}
    I don’t even have a clue as to what the ‘i’ in above declaration could mean?
    Furthermore, I was not able to see an effect of the declaration (for testing-purpose, it is deleted in the actual CodePen)

Regards
Uli

Well spotted it should be align-items:center and refers to the vertical alignment.

.summary-top{
  display:flex;
  align-items:center;
}

That will vertically align the symbol to the middle of the text. (If you wanted horizontal alignment then that rule above would require justify-content:center as well.)

In my code I used the <i> element (it means italic but has no real semantic significance these days) to hold the word ‘animation’.

   <summary class="summary-top">
            <span>Show </span> <b>Hide </b> <i>animation</i>
  </summary>

Therefore the style that I used .summary-top i {margin-left:.2rem; font-style:normal;} was just to add a little space to the left of that word (animation) in my design. (you used a non breaking space to get the gap but I avoid those and you missed the closing semi-colon anyway ;))

Also in your page you have just gone and made up your own html tags !!!

 <summary class="summary-top">
              <s-1>Start</s-1><s-2>Stop</s-2>&nbspAnimation <!-- &nbsp animation: -->
</summary>

There’s no such thing as s-1 and s-2 tags in html5. Don’t make your own html tags up as that defeats the point of using html5.

You could use a span and i element as in my example or use two spans with classes.

e.g.

  <summary class="summary-top">
              <span class="s-1">Start</span><span class="s-2">Stop</span>&nbsp;Animation <!-- &nbsp animation: -->
</summary>
.figcaption-top               summary .s-2{display:none;}
.figcaption-top details[open] summary .s-2{display:inline;}
.figcaption-top details[open] summary .s-1{display:none;}

Don’t just make stuff up lol :slight_smile: (Some advanced apps and programs like angular use their own tags but normal users don’t need to go there).

1 Like

Ok, I don’t any more. promised! :sunglasses:

All is so fine now, except for the horizontal centering of the details within/relative to the figcaption. I clearly must be doing something wrong. Have tried to apply

display: flex;
justify-content: center;
align-content: center;

to figure, figcation and details so far, to no avail…

I already answered that :slight_smile: (Unless you meant something else?)

.summary-top{
  display:flex;
  align-items:center;
 justify-content:center;
}

codepen.io_UliCP_pen_zYyZeWX

The align- values refer to vertical alignment on the default row display of flex and the justify- properties refer to the horizontal alignment. (If using flex-direction-column then both of those become reversed.)

1 Like

Thanks, was overseeing this in the maze of sooo many sizes around - it’s perfectly alright for the actual stage now.

Now have additionally implemented srcset along with 1x, 2x screen resolutions and want to post a conclusion with final sample code (SitePoint & one-page raw codes including links to images).asap.

Regards
Uli

P.S.:
Since the topic-title can’t be edited any more, the widely extended content of the topic isn’t reflected there properly. As soon as the final sample is available, one may see what to do best.

1 Like

Hello,
since I promised to upload at the least a pre-final version of what has been achieved - here it is. Sadly not well cleaned up - there are so many other priorities at this time…

One, using CodePen:

The other, html and css as standalone files.
section_figure_img_JpgAndGif_status4.standalone.html (2.5 KB)
section_figure_status4.css (1.5 KB)

I could imagine that other new users could make some use of it, once it is checked for errors and other weaknesses sufficiently.
In that case, possibly a new, separate topic with a suitably selected title would do best - I do not know really…

Regards
Uli
P.S.: If you like to check where it is used actually, see here.
It is in german language only at this time - the english page(s) are to be created in a second go.

1 Like

Hi all,
appending the remaining issue to here because it seems the most appropriate.

While validating the code to upload, I encountered a strange problem.

Having two figures like above, the srcsets in (class “figure-left”) correctly have a comma to separate the sources.

If now likewise a comma is added in the second figure (class “figure-right”), the img-file(s) are not found any more.

The CodePen is here:

There is an error in the code somwheres I can’t find out.

Could someone point me to it?

Thanks in advance
Uli

Remove the duplicate loading attribute and add the missing comma and it should validate ok (assuming you correct the mistakes in the missing head and title).

<section>
  <h5 id="BiegenUndAbkanten">Freies Biegen oder Abkanten</h5>
  <figure class="figure-left">
    <figcaption class="figcaption-top">
      <details>
        <summary class="summary-top">
          Animation&nbsp;
          <span-1>Start</span-1>
          <span-2>Stop</span-2>
        </summary>
        <img loading="lazy" width="150" height="150" src="
              https://sources.ulisblog.info/img/div/Biegeanimation_2D.wikipedia.0150x0150.gif
            " alt="" srcset="
              https://sources.ulisblog.info/img/div/Biegeanimation_2D.wikipedia.0150x0150.gif 1x,  
              https://sources.ulisblog.info/img/div/Biegeanimation_2D.wikipedia.0300x0300.gif 2x
            ">
      </details>
      <img loading="lazy" width="150" height="150" src="
            https://sources.ulisblog.info/img/div/Biegeanimation_2D.wikipedia.cmp.0150x0150.jpg
          " alt="" srcset="
            https://sources.ulisblog.info/img/div/Biegeanimation_2D.wikipedia.cmp.0150x0150.jpg 1x,  
            https://sources.ulisblog.info/img/div/Biegeanimation_2D.wikipedia.cmp.0300x0300.jpg 2x
          ">
    </figcaption>
  </figure>
  <p>
    Diese beiden Verfahren sind die gebräuchlichsten.<br>
    Die erste Abbildung zeigt das 'Freie Biegen', die zweite das 'Abkanten'.<br>
    Zum leichteren Verständnis können beide auch animiert betrachtet werden.
  </p>

  <figure class="figure-right">
    <figcaption class="figcaption-top">
      <details>
        <summary class="summary-top">
          Animation&nbsp;
          <span-1>Start</span-1>
          <span-2>Stop</span-2>
        </summary>
        <img loading="lazy" width="150" height="150" src="
              https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.0150x0129.gif 
            " alt="" srcset="
              https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.0150x0129.gif 1x,
              https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.0300x0258.gif 2x
            " >
      </details>
      <img loading="lazy" width="150" height="150" src="
            https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.cmp.0150x0129.jpg 
          " alt="" srcset="
            https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.cmp.0150x0129.jpg 1x,
            https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.cmp.0300x0258.jpg 2x
          " >
    </figcaption>
  </figure>
</section>

Also stop making stuff up :slight_smile:
<span-1>Start</span-1>

Also make sure your alternate images actually exist as a few are missing like this one:

https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.0300x0258.gif

“Also make sure your alternate images actually exist”

Before entering into side-aspects :innocent: , this exactly is the problem and it’s remaining after deletion of the second loading = lazy statements and adding one first single comma only.

The gif-file certainly ist existing - otherwise it never could show up without comma.

The actual CodePen is looking now like this (the gif doesn’t show):

These two are still missing;

https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.0300x0258.gif
https://sources.ulisblog.info/img/div/Swing-folding-ani.wikipedia.cmp.0300x0258.jpg

1 Like

Thank you so much! I was utterly confused because everything seemed to be ‘right’ as long as the code was ‘wrong’ :wonky:

(It is done now…)

1 Like

Yes and that’s a good example of why validating your code can find problems that you may have missed. :slight_smile:

What happened is that because you malformed the srcset the browser dropped out of that srcset rule and instead applied the original image from the src attribute. Your users would never get the higher quality images if their systems were capable.

Once you put the comma in place the browser tries to load the url you gave it but the image doesn’t actually exist. This is not an html error as such and so the browser just carries on.:slight_smile:

1 Like

Absolutely! I only can confirm.
For the records:
Originally, there were two errors within the same context.

  1. Missing commas
  2. Two misspelt filenames on the server

Only by checking in the validator, I was able to become aware about this.
Unable to solve the complete riddle, you pinpointed the culprits then.

Nice sunday evening
Uli

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.