Adjusting the image size would cause website functionality issues

I just started my journey with FCC, and I'm currently working on my first project which is the Tribute Page. I would really appreciate some feedback on my code, as I'm not entirely confident in it. However, my main issue right now is making the image responsive by using

max-width: 100%; 
display:block; 
height: auto;

But whenever I try to make the image responsive this way, it ends up being too large, causing the text that should be below it to overlap. I'm puzzled as I thought block-level elements shouldn't behave this way. Here's the link to my Codepen for reference, thank you! https://codepen.io/spccbw/pen/VwLQPjv

*{
margin: 0px;
padding: 0px;
}
#banner{
  border: 1px solid red;
  background-color:yellow;
  height: 90px;
  width: 100%;
}
h1, h2{
  text-align:center;
  font-family: Arial;
  margin-top: 10px;
  color: red;
  
}
#image{
  max-width: 100%; 
  display:block; 
  height: auto;
  margin: 0 auto;

}

#img-div {
  width: 100%;
  padding-top: 20px;
  border: 2px solid green;
  background-color: #e8dd5f;
}
#img-caption{
  margin-top: 5px;
  font-family: Arial;
  font-weight: bold;
  text-align:center;
}
#tribute-info{
  padding-top: 10px;
  background-color: #ede7a6;
}
#tribute-info p{
  display:block;
  font-size: 30px;
  text-align:center;
}
ul{

list-style-type:none;
margin-top:10px;
text-align:center;
font-family: Monospace;
}
li{
font-size: 1.3em;
}
.bold{
font-weight:bold;
font-size: 1.4em;
font-style:normal;
text-transform:uppercase;
}
#footer-text{
font-style:italic;
}
<!DOCTYPE html>
<html>
<head>

  <title>Franky</title>
</head>

<body>
  <div id="main">
    
   <div id="banner"> 
    <h1 id="title">Franky the Robot</h1>
    <h2>GOAT Character</h2>
   </div>
    
    <div id="img-div">
      <img id="image" src="https://static.zerochan.net/Franky.full.2514784.jpg">
      <p id="img-caption"> Franky being cool, as usual</p>
    </div>
 
       <div id="tribute-info">
      <p>List of things Franky Enjoys</p>
         <ul>
          <li> <span class="bold">Cola</span> - Possibly his favorite of all </li>
           <li> <span class="bold">Robots</span> It's because he is one! </li>
          <li> <span class="bold">Possibly Robin</span> Really.. who doesn't? </li>    
         <ul>
         <p id="footer-text"> If you actually want to know about Franky you should most definitely visit <a href="https://onepiece.fandom.com/wiki/Franky" id= "tribute-link" target="_blank" > <span class="bold">click here</span></a>
    </div>
      
 </div>
    </div>
         
</body>
  <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
</html>

Answer №1

The dimensions of the image have been set to 400px each. The containing div is properly configured for responsive layouts.

#image{
  width: 100%;
  height: 100%;
  margin: 0 auto;
  display: block;
}

For a more comprehensive approach to responsiveness, consider delving into media queries and tools like bootstrap.

I trust this information proves useful.

Answer №2

Get rid of the height: 430px; property from the #img-div.
By limiting the container height, you restrict the content from expanding beyond a certain size. To conceal overflowing content, use overflow: hidden.
If you want to ensure the picture does not exceed 430px in height, specify height: 430px; instead of height: auto; (or height: 100%; if the container remains as is). This will always set your image at a fixed height of 430px, even though it may distort wide images.
In essence, the container dictates the maximum space available for the inner content to occupy.

*{
margin: 0px;
padding: 0px;
}
#banner{
  border: 1px solid red;
  background-color:yellow;
  height: 90px;
  width: 100%;
}
h1, h2{
  text-align:center;
  font-family: Arial;
  margin-top: 10px;
  color: red;
  
}
#image{
  max-width: 100%; 
  display:block; 
  max-height: 100%;
  margin: 0 auto;
}

.img-container {
  height: 200px;
  width: 200px;
  margin: 0 auto;
}

#img-div {
  width: 100%;
  padding-top: 20px;
  border: 2px solid green;
  background-color: #e8dd5f;
}
#img-caption{
  margin-top: 5px;
  font-family: Arial;
  font-weight: bold;
  text-align:center;
}
#tribute-info{
  padding-top: 10px;
  background-color: #ede7a6;
}
#tribute-info p{
  display:block;
  font-size: 30px;
  text-align:center;
}
ul{
  
  list-style-type:none;
  margin-top:10px;
  text-align:center;
  font-family: Monospace;
}
li{
  font-size: 1.3em;
}
.bold{
  font-weight:bold;
  font-size: 1.4em;
  font-style:normal;
  text-transform:uppercase;
}
#footer-text{
  font-style:italic;
}
<!DOCTYPE html>
<html>
<head>

  <title>Franky</title>
</head>

<body>
  <div id="main">
    
   <div id="banner"> 
    <h1 id="title">Franky the Robot</h1>
    <h2>GOAT Character</h2>
   </div>
    
    <div id="img-div">
      <div class="img-container">
        <img id="image" src="https://static.zerochan.net/Franky.full.2514784.jpg">
      </div>
      <p id="img-caption"> Franky being cool, as usual</p>
    </div>
 
       <div id="tribute-info">
      <p>List of things Franky Enjoys</p>
         <ul>
          <li> <span class="bold">Cola</span> - Possibly his favorite of all </li>
           <li> <span class="bold">Robots</span> It's because he is one! </li>
          <li> <span class="bold">Possibly Robin</span> Really.. who doesn't? </li>    
         <ul>
         <p id="footer-text"> If you actually want to know about Franky you should most definitely visit <a  href="https://onepiece.fandom.com/wiki/Franky" id= "tribute-link" target="_blank" > <span class="bold">click here</span></a>
    </div>
      
 </div>
    </div>
         
</body>
</html>
  

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

Assign a new class to the child element of **this**

Can you please explain how to apply a class to the child elements of this? I am looking to give a different background color to all Compliant items. For example: <div class="tab"> <tr><td class="compliance">Compliant</td>< ...

What is the most effective way to obtain a customer's latitude and location by prompting them to drop a pin on Google Maps?

My Android app has an API, but on my website I'm wondering how I can retrieve a person's location by having them place a marker on a Google Map. Is there a standard method for this? I need to obtain the latitude and longitude coordinates and send ...

HTML and JavaScript are not communicating properly

Need help with creating a slideshow using JavaScript. The code works on JSFiddle, but not in my local environment. Can someone point out where I might be going wrong? HTML5 <!DOCTYPE html> <html> <head> <title>slider</titl ...

What is the best way to format page content to fill the entire width of the screen?

I noticed that my content shrinks when the browser width is reduced using dev tools. From the header navigation to the footer, everything is contained within a container element with the following CSS: .container { width: 800px; margin: 0 auto; ...

Create a PHP script that directly sets a cookie based on user input from a

In the code snippet provided below, I have attempted to create a simple name input form that will be stored as a cookie in the browser. However, it seems that the functionality is not working as expected. Can anyone help me identify the issues in this co ...

Center text vertically within a div using CSS

I need assistance with aligning my text vertically centered and left aligned to the logo in my HTML & CSS code. How can I achieve this with the code provided? Link to Fiddle: http://jsfiddle.net/z6yet59f/ .slogan { background:#eaeaea; float:lef ...

Customizing hover effects for select field options

I need help customizing the background color of a dropdown menu when hovered over. I attempted to assign a class "page-limit-option" to the option element, but it didn't work. Should I create a new style component instead of using the option? <sele ...

Does Internet Explorer 10 support the FormData object?

I've developed a JavaScript app that enables me to upload images asynchronously, and it works seamlessly in most browsers. However, the infamous Internet Explorer is causing some trouble... To address this issue, I devised a workaround for IE9- versi ...

Setting the color for the :hover and :active states on a react JSX component: A step-by-step guide

<button onClick={fetchExchangeRates} style={{ backgroundColor: `${selectedColor}` }} className="hover text-white px-3 py-1 flex justify-center items-center gap-2 text- rounded-md" > Convert <FontAwesomeIcon className=&apo ...

What is the most effective method to horizontally center a div element when its width and height are not predetermined

Let's say there is a div element on the page like this: <div class="center"></div> The CSS style for this div may look something like this: .center{ background:red; position:absolute; left:50%; top:50%; margin-left: ...

Instructions on incorporating svg into pug using a mixin

I've created a mixin mixin icon(url) svg() use(xlink:href=url) Below is the code to output - var features = [ { icon: +icon(img/time.svg) } ] each item in features +feature(item.icon) Can someone point out wher ...

Arrange multiple lines in a straight line

I am currently utilizing bootstrap 5 for my project. <div class="col-lg-3 col-md-6"> <h5 class="text-light mb-4">Stay in contact</h5> <p><i class="fa fa-map-marker-alt me-3"></i>619 ...

Creating a full-width tab card with Bootstrap-Vue: A step-by-step guide

I stumbled upon something similar in the documentation for bootstrap-vue: A card with tabs: https://i.sstatic.net/HoVEC.png Now, how can I style the tabs to look like this: https://i.sstatic.net/dbsRj.png This is my current code: <b-card no-body ...

``I am having trouble getting the Bootstrap carousel to start

I am having trouble getting the Bootstrap Carousel to function as expected. Despite including all the necessary code, such as initializing the carousel in jQuery.ready, the images are stacking on top of each other with navigation arrows below them instea ...

Displaying items in a row when the navbar is collapsed: Bootstrap 4 tips

Is there a way to change the display of items in the collapsed navbar so that they appear next to each other rather than in a column? You can see how it currently looks here: Navbar collapsed. My goal is to have the image displayed next to the username ins ...

Django class-based views not rendering HTML

I'm feeling confused about why my HTML template is not displaying properly. Currently, I am working on understanding Class-based views in Django rather than using functions. The URL seems to be functional because the "{% extend base.html %}" stateme ...

IE8 compatibility problem with ASP.NET MVC 3.0 internal application

We are currently working on an ASP.NET MVC 3.0 (Razor & HTML 5) application running on IIS 7.5 that is required to be compatible with IE8. The site's content is displayed correctly when compatibility mode is OFF. However, if it is switched on, some e ...

Styling the `<thead>` tag in Internet Explorer 7 (IE

This code is functioning correctly in IE8, Firefox, Chrome and other browsers. However, there seems to be an issue with IE7 not recognizing the following line: .defaulttable thead{border-right:55px solid #c7c9cf;} As a result, I am seeing no border in IE ...

Adding alternative content when embedding an SWF file in HTML5 - What's the best way to do it?

I am looking to incorporate an SWF file into HTML5. Currently, I have successfully used this code: <embed src="main.swf" width="550" height="400" /> However, I am wondering how I can display alternative content (such as an animated GIF image, or a ...

What is the best way to align an image gallery in the center

After referencing this link, I attempted to create an image gallery. However, the code aligned the images to the left side of the page. With a total of 9 images in the gallery, my objective is to arrange them in a 3x3 grid at the center of the page, with ...