What steps should I take to resolve this css issue?

I'm currently working on a website and having some issues with displaying images properly. The images should be placed under their respective titles; for instance, the alcohol photo should be positioned under the alcohol title, and the nervous system photo should be under the nervous system title.

Here's a visual of how it appears at the moment: https://i.sstatic.net/KdpTs.png

This is my current code:

HTML: CSS:

If you can offer any assistance, I would greatly appreciate it. Thank you in advance.

Answer №1

It is recommended that all images be enclosed within the same div container. For instance, the alcohol image should be placed in:

<div class="science">
    <div class="alco">Image for Alcohol goes Here</div>
    <div class="nersys">Image for Nersys goes Here</div>
</div>

Answer №2

Check out this example in the HTML file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Science - Portfolio</title>
<link rel="stylesheet" type="text/css" href="styles/science.css"/>
</head>

<body>
  <header>
    <div class="nav">
      <ul>
        <li class="home"><a href="index.html">Home</a></li>
        <li class="about"><a href="english.html">English</a></li>
        <li class="news"><a href="#">Hosptality & Catering</a></li>
        <li class="contact"><a href="#">Leisure & Tourism</a></li>
        <li class="contact"><a href="#">BTEC Computing</a></li>
        <li class="contact"><a href="#">BTEC Business</a></li>
        <li class="contact"><a href="#">CV</a></li>
      </ul>
    </div>
  </header>

  <div class="science">
    <center><h2>Science:</h2></center>
  </div>

  <div class="center-block">
    <div class="alco">
      <h4>Alcohol:</h4>
       <div class="alcoimage"><a href="file:///N|/Documents/My Documents/Year 11/Computing/Website home version/of mice and men.html"><img src="images/Science/alcohol.jpg" width="400" height="357" alt=""/></a></div>
    </div>
<div class="nersys">
    <h4>Nervous System:</h4>
     <div class="alcoimage"><a href="file:///N|/Documents/My Documents/Year 11/Computing/Website home version/cannabis speech.html"><img src="images/Science/NervousSystem.jpg" width="291" height="291" class="nerimage" /></a></div>
    </div>
  </div>



<div id="wrapper">
    <div id="footer">
      <p><center>Contact Me:</center></p>
      <p><center><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94a5a5f8f5fafef5f7d4f5f6f6f1edf2fdf1f8f0bae3fdf8e0e7bae7f7fcbae1ff">[email protected]</a></center></p>
    </div>
  </div>

</body>
</html>

Also, here is a snippet from the CSS file:

....
  .science {
      padding-top: 30px;
  }

  .center-block{
      text-align: center;
  }
  .center-block .alco {
      display: inline-block;
      vertical-align: top;
      text-align: center;
      padding-right:150px;
  }
  .center-block .nersys{
        display: inline-block;
        text-align: center;
        padding-left:150px;
  }

  .alcoimage {
      padding-top: 60px;
  }

  #footer {
      background:#40ea3c;
      width:100%;
      height:80px;
    position:absolute;
    bottom:0;
    left:0;
    color: white;
  }

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

Modifying content on links that are dynamically created

I have some dynamically added link elements that are initially hidden from the page. These links are generated by a third party telerik control, and I need to change the text of these links using jQuery. I have created a rule (selector) that targets the ...

Injecting Custom HTML Tag through JavaScript on Page Load in Google Tag Manager

When attempting to inject events into the data layer upon loading DOM pages on my website, I encountered an issue. Since I lack access to the website code and developers are reluctant to make additions, I decided to implement this through a custom HTML tag ...

Determine the percentage of clicks on an HTML5 canvas radial progress bar

Recently, I designed a circular progress bar displaying a specific percentage. However, I am facing a challenge in determining how to calculate the percentage when a user clicks on either the black or green part of the circle. Could you provide insight on ...

What is the best way to adjust image size according to the dimensions of the parent container using CSS

I am working on a card game using Bootstrap styling and I have a container with a background image of a card table (1000x1000). As I resize the browser window, the card table image shrinks to 800x800, then to 500x500, and finally to 200x200. My issue is th ...

Certain web browsers are experiencing difficulty in scrolling down on the website

We are facing an issue with a recently launched website where it won't scroll in specific browsers. We've observed that users on Mac using Chrome are unable to scroll down the page. Any assistance would be greatly appreciated as we suspect it cou ...

"Effortlessly slide up or down with jQuery Dropdown: smooth functionality in Chrome, minor glitches in

First things first, I'm just diving into the world of javascript so please bear with my not-so-great code It seemed to work fine on Chrome but when I checked it on Firefox, everything went haywire Fiddle: jsfiddle.net/7NCcY/ <html> <head> ...

Stacking components on top of one another using CSS

I have been experimenting with a dynamic sliding jQuery menu. By adjusting the drop-down area slightly upward using a negative margin, I was hoping to layer the dropdown on top of its parent element that triggers the action. I attempted using z-index witho ...

The default padding and margin in Bootstrap are making the images protrude beyond the edges of the container

I have an issue where my images are stretching into the padding or margin that bootstrap uses to separate columns. I want to maintain the column division but avoid having the images stretch. While I have managed to shrink the image using padding, the white ...

What is the best way to restrict the selection of specific days of the week on an HTML form date input using a combination of JavaScript, React, and HTML?

I need help customizing my Forms Date Input to only allow selection of Thursdays, Fridays, and Saturdays. I've searched for a solution but haven't been successful so far. Is there any JavaScript or HTML code that can help me achieve this? Below ...

Learn how you can swap out UI elements instead of simply appending new ones onto the existing interface. Discover the power of JavaScript, the Fetch API, and Dom

Currently, I am working on a small project to learn more about APIs and how to interact with them effectively. This project involves searching for and displaying characters from a TV show using data obtained from an API. My issue arises when I try to make ...

Is there a way for me to choose multiple checkboxes simultaneously?

I have a dynamically created HTML table with checkboxes added for each row. $.each(data, function(id, value) { rows.push('<tr><td><input type="checkbox" autocomplete="off" class="chkbox" name="chkbox" value="'+value.site+' ...

Is there a way to post to a remote website programmatically with authentication using the WebClient interface?

I have an interesting scenario with my website at http://localhost/abc.htm that requires authorization. <form method="POST" action="/change"> <input type="hidden" name="node" value="12 4A 72 1" /><table> <tr> <td> ...

Sync Data Automatically from SQL Database

For the past two months, I've been researching how to achieve an effect similar to the auto-updating sales on the page. So far, I haven't had any luck. I do have a PHP file that counts the number of results in a database and displays them as a n ...

It seems that the Bootstrap 4 Modal Pop up window is having difficulty closing

I recently completed a project on creating a matching game. After all the cards are successfully matched and the game finishes, a congratulatory modal pops up. However, I encountered an issue where the modal would not close after clicking the "Play Again" ...

Importing data from json into HTML/JavaScript

For a small project, I am working on adding product data to a JSON file and then loading that data into the JavaScript section of my HTML code. However, I keep encountering errors where Microsoft Visual Code indicates that the object I am trying to load is ...

"Exploring the process of retrieving controller data through an AJAX request for the purpose of dynamically populating

My HTML code looks like this: <form method="get" name="form"> <select name="grade" data-url="{{ path_for('get.student') }}"> <option value="">-- Choose Grade --</option> <option value="10">10< ...

Javascript retrieve the style of an element in every possible state

I am interested in retrieving the line height of an element; it's a simple task. Here is a method that I know works: console.log(document.getElementById("myDiv").style.lineHeight); console.log($("#myDiv").css('lineHeight')) ...

Eliminate (strip away logos) specific HTML code from webpage without the use of JavaScript or CSS

The specific code that needs to be removed is: <p style="text-align:center;">Created by <a href="http://www.fancywebsite.com" target="_blank">FancyWebsite</a></p> Maybe using PHP functions like str_replace() or trim() could do the ...

Updating the correct list item in an unordered list on a Bootstrap modal pop-up submission

I am dealing with an unordered list of messages where each message within a list item is clickable. <ul id="home-message-list" class="messages"> <li> <a href="#"> <span class="linkClick" name="message">< ...

Unable to hide content in Shopify using @media

How can I hide a Facebook like button when the browser window is resized to a certain width? This is the code I am using: @media all and (max-width: 300px) { .fb-like { float: right; display: none; } } While this code works on regular websites, it do ...