Why do my designs always seem to fall apart as soon as I include a figcaption?

My website has a gallery, but as soon as I add figcaption to the images, everything seems to shift to the center. What am I doing wrong? I'm at a loss on how to fix this issue.

  #image{
position: inherit;
width:300px;

-webkit-transition:all 1s;
transition:all 1s;
margin-top:10px; 

}

#image:hover{
position: inherit;
-webkit-transform:scale(3);
transform:scale(3);
margin: 0 auto; 
highslide: auto;
}

figure.img img {  
max-width: 300px;
height: auto;

}
figure.img figcaption {  
padding: 5px;
font: bold italic 90% Georgia,serif;
color: #17432e;
width: 300px;
margin-left: 0px;
}
.pictures {

margin: 100px auto;
width: 980px;
}
.clear {
clear: both;
}

After making all the recommended changes, my body now looks like this:

<div align="center">
    <figure class="img">

            <img id="image" src="pics/1.jpg" class="passe-partout">
            <figcaption>Exploring nature</figcaption>
    </figure>
    <figure class="img">
            <img id="image" src="pics/2.jpg" class="passe-partout">
            <figcaption>Summer vibes</figcaption>
    </figure>
    <figure class="img">
            <img id="image" src="pics/3.jpg" class="passe-partout">
            <figcaption>Urban beauty</figcaption>
    </figure>
    <figure class="img">
           <img id="image" src="pics/4.jpg" class="passe-partout">
            <figcaption>Cozy retreat</figcaption>
    </figure>

    <div class="clear"></div>
    </div>

Answer №1

Check out the effective solution below.

---Custom CSS Style--

figure img{
position: inherit;
width:300px;
-webkit-transition:all 1s;
transition:all 1s;
margin-top:10px; 
}

figure img:hover{
position: inherit;
-webkit-transform:scale(3);
transform:scale(3);
margin: 0 auto; 
highslide: auto;
}

figure> figcaption {  
padding: 5px;
font: bold italic 90% Georgia,serif;
color: #17432e;
width: 300px;
margin-left: 0px;
}

/----HTML Markup -----/

<div align=center class="pictures">
  <figure class="img">
    <img id="image" src="http://lorempixel.com/200/200" class="passe-partout">
            <figcaption>In the village</figcaption>

  </figure>
          <figure class="img">
            <img id="image" src="http://lorempixel.com/200/200" class="passe-partout">
            <figcaption>In the village</figcaption>

  </figure>
  <figure class="img">
            <img id="image" src="http://lorempixel.com/200/200" class="passe-partout">
            <figcaption>In the village</figcaption>

  </figure>

</div>

View the Live Demo here. http://jsbin.com/musovipo/1/

Answer №2

I have enhanced the code's validity by eliminating multiple identical ids and enclosing each img/figcaption pair within a figure element. In order to display the figures on the same line, I added 'display: inline-block' to the figure elements.

CSS

div.img img {
    width: 300px;
    max-width: 300px;
    height: auto;
    position: inherit;
    -webkit-transition: all 1s;
    transition: all 1s;
    margin-top: 10px;
}

    div.img img:hover {
        position: inherit;
        -webkit-transform: scale(3);
        transform: scale(3);
        margin: 0 auto;
        highslide: auto;
    }

div.img figcaption {
    padding: 5px;
font: bold italic 90% Georgia,serif;
color: #17432e;
width: 300px;
margin-left: 0px;
}

div.img figure {
    display: inline-block;
}

HTML

<div class="img">
<div align=center class="pictures">
    <figure>
    <img src="pics/1.jpg" class="passe-partout">
    <figcaption>In the village</figcaption>
    </figure>
    <figure>
    <img src="pics/2.jpg" class="passe-partout">
    <figcaption>August</figcaption>
    </figure>
    <figure>
    <img src="pics/3.jpg" class="passe-partout">
    <figcaption>The bridge</figcaption>
    </figure>
    <figure>
    <img src="pics/4.jpg" class="passe-partout">
    <figcaption>A charming house</figcaption>
    </figure>
    <div class="clear"></div>
</div>

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

Dynamic Design with Pure CSS

I am in the process of creating a flexible layout design. Everything appears to be functioning as intended on FF, Chrome, Safari and IE8 However, I have encountered an issue with IE7. It seems to be related to the floated containers. I have attempted a fe ...

The JavaScript code is failing to load

Ensuring my HTML and JavaScript code is well-organized, I have separated all the JavaScript code into different files. However, when attempting to insert the code into the HTML page, it does not function as expected: <html xmlns="http://www.w3.org/199 ...

Operating a slider on a web page built with HTML

I am currently working on developing a loan calculator that involves two range sliders interacting with each other to display monthly payments in a label. Here are the specific requirements: Display only 5 values on the "Month" range slider: 12,18,24,30,3 ...

Display an HTML image within a span tag and ensure it is aligned to the bottom

I am facing a layout issue with 2 images that are placed side by side within their tag . The sizes of the images are different, but they are both anchored at the top of their parent element. <span style="position: relative; left: 0; top: 0; vertical- ...

Unable to position the button next to the search bar

I'm struggling to get my search bar aligned next to my dropdown button. I've tried various alignment methods without success. Both buttons are within a container, causing the search bar to span 100% of the container's width. I also attempted ...

instructions on how to showcase a text message within the fontawesome square icon

Can someone help me with styling my code? I want to display a text message inside a square box with dimensions of 1x. <span class="fa-stack fa-5x" style="margin-left:5%"> <i class="fa fa-square-o fa-stack-2x"></i> </span> ...

Issue with HTML and CSS Grid alignment coupled with CSS syntax error on RBRACE

I'm in the process of updating my website indexes and decided to incorporate grids. However, when attempting to implement grids using Dreamweaver, I encountered several issues. Firstly, an error message appeared stating "Expected RBRACE at line 72, co ...

What is the best way to implement a seamless left-to-right sliding effect for my side navigation using CSS and Javascript?

I am currently working on creating a CSS and JavaScript side navigation. Below is the code that I have implemented so far: var nav = document.getElementById('nav'); function show(){ nav.style.display = "block"; } .side-nav{ background-color:bl ...

What is the best way to display a single form upon page reload if a radio button in Laravel 6.0 has not been selected?

Dealing with two forms within a single view comes with its challenges. Specifically, when one of the radio buttons is not selected and the page is reloaded, both forms are displayed. I attempted to use the 'check' attribute on one of the radio bu ...

Can you explain the process of implementing @media queries in SASS?

I am having some trouble understanding the syntax for media queries in SASS. I attempted to use this particular line of code, but it resulted in an error: @media screen (max-width: 1550px) #server-name left: 80% ...

Automatically insert personalized CSS design markers into Material-UI elements using code

Within my react-redux app, I am utilizing material-ui components. The initial UI prototype was established using adobe-xd, which has the capability to export character styles (design tokens) in a CSS file format: :root { /* Colors: */ --text-color: #F8E29 ...

What is the best way to design a content page with linked boxes to various arrays in PHP?

How can I create a PHP menu template that navigates to different pages? I am new to PHP and still learning. I want to achieve something similar to this image: https://i.stack.imgur.com/ylfe8.jpg I have the code for the navigation bar, but I need help crea ...

Utilizing Rvest for extracting data from LinkedIn profiles

I've been trying to scrape my LinkedIn profile using Rvest, but I encountered a problem in the experience section. The XPath below was supposed to retrieve the experience section, but it's returning 0 nodes: Test <- read %>% html_nodes(xpa ...

Creating a sleek design for an HTML input with a rounded border

I am facing an issue with my input box. I have added a clear button using the 'x' button, but it seems to be affecting the border of the input box. As seen in the image below, the right border is round while the left border remains straight. How ...

Storing HTML table data into a MySQL database table

I am currently working on a project where I need to submit data from an HTML table into a MySQL table. The first two columns of the HTML table are fetched from a MySQL table named 'student', and the third column needs to be filled in online. My g ...

Updating values in MySQL using PHP requires two consecutive reloads

Hey there! I recently created a message deletion button, but for some reason, it takes two reloads to see the changes pop up. The rest of my code is working fine, so I won't be sharing that part here... <?php while($r = $replies->fet ...

What is the best way to utilize the JavaScript split() method to effectively split pasted text based on new lines?

Could use some assistance with this, please? I am working on contenteditable div elements and I need to enable the ability to copy and paste numbers into them. The numbers may be structured in columns and rows, similar to Excel. Upon pasting, the text sh ...

Tips for managing an event using the bxSlider callback API

I am currently using bxSlider to create a slideshow on my website. However, I now want to implement a manually controlled slideshow that also displays text content related to each image below the slideshow: Here is the code I have so far: <!--SlideSho ...

Moving DOM Elements around

Objective: Looking to relocate an element within the DOM structure. Condition: Although I am familiar with using jQuery for this task, I am currently working in an environment without access to it. Therefore, I need a pure JavaScript solution. Example: ...

Render JSON data retrieved from an AJAX request as a formatted HTML display or table

Code for displaying JSON data $('body').on('click','#check_history',function () { var settings = { "async": true, "crossDomain": true, "url": "https://url.com", ...