What is the best way to adjust the size of an image using CSS, especially with flexbox

I'm attempting to arrange 3 images in a row using flexbox. I also need to adjust the size of the first image because it is too large. However, my CSS styles are not being applied correctly. Each image is enclosed in its own div with a class of flex-item-3 to indicate that they are flex items inside the flex container. Despite this, I am struggling to override the default CSS settings.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  font-family: 'Lato', 'sans-serif', 'arial';
  color: #fff;
  font-size: 15px;
  font-weight: 300;
  text-transform: uppercase;
  text-rendering: optimizeLegibility;
}

.wrapper {
  max-width: 100%;
  margin: 0 auto;
}

section {
  padding: 80px 0;
}

h2 {
  margin: 0;
  padding: 0;
}

.flex {
  display: flex;
  justify-content: space-between;
  background-image: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("img/truck.jpg");
  background-size: cover;
  background-position: center;
}

.flex-item {
  padding-top: 15px;
  height: 100vh;
}

.item1 {
  padding-top: 0;
  padding-left: 30px;
}

.logo {
  height: 90px;
}

.main-nav ul {
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
}

.main-nav a {
  color: white;
  padding: 1rem;
  text-decoration: none;
}

.main-nav a:hover {
  color: orange;
}

.hero {
  position: absolute;
  top: 50%;
  left: 25%;
  transform: translate(-50%, -50%);
}

.hero a {
  text-decoration: none;
  color: white;
  display: block;
  margin: 10px;
  padding: 10px;
  border-radius: 10px;
}

.btn {
  background-color: orange;
}

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

.flex-item-2 {
  color: #312c2c;
  width: 100%;
  text-align: center;
}

.second-flex-item p {
  margin-top: 20px;
  margin-bottom: 40px;
  font-size: 19px;
  color: #312c2c;
}

.second-flex-item h2 {
  font-weight: 900;
  font-size: 25px;
}

.flex-3 {
  display: flex;
  justify-content: center;
  max-width: 100%;
}

.flex-3-items {
  display: flex;
  width: 100%;
  height: auto;
}
<body class="wrapper">

  <header class="flex">
    <div class="flex-item item1">
      <img src="Resources/img/moBurgerzLogo.png" class="logo">
    </div>
    <nav class="flex-item main-nav">
      <ul>
        <li><a href="#">Our Story</a></li>
        <li><a href="#">Locations</a></li>
        <li><a href="#">Menu</a></li>
        <li><a href="#">Order now</a></li>
      </ul>
    </nav>
    <div class="hero">
      <h2>Best Burgers <br> In DA City(D.C)</h2>
      <a href="#" class="btn" btn-full>Order now!</a>
      <a href="#" class="btn" btn-ghost>View Menu!</a>
    </div>

  </header>

  <section class="flex-2">
    <div class="flex-item-2 second-flex-item">
      <h2>Established in 2017 in D.M.V</h2>
      <p class="story"> moBurgerz was founded in 2017 by owner Mahamed Ibrahim.<br> Since then we have been serving the best hand crafted burgers in the D.M.V.<br>All our meat is halal and all of our ingridients are organic.</p>
      <img src="Resources/img/white_truck.jpeg" class="truck-img">
    </div>

  </section>

  <section class="flex-3">

    <div class="flex-3-item meal-photos photo-1">
      <img src="Resources/img/cheeseSteak.jpg">

    </div>

    <div class="flex-3-item meal-photos">
      <img src="Resources/img/goodMoanin.jpeg">
    </div>


    <div class="flex-3-item meal-photos">
      <img src="Resources/img/moGul.jpeg">
    </div>

  </section>
</body>

Answer №1

Give this a shot

.brand {
  max-width: 100%;
  height: auto;

}

Answer №2

If you use the code

.flex-3-item img { max-width:100%; }
, it should solve the problem.

For more information, check out: Auto Resize Image in CSS FlexBox Layout and maintaining Aspect Ratio?

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

choose a distinct value for every record in the table

My goal is to only change the admin status for the selected row, as shown in the images and code snippets below. When selecting 'in-progress' for the first row, I want it to update only that row's status without affecting the others. <td ...

How can I center two divs within a wrapper div without also centering all the text inside?

Is there a method other than using display: inline-block and text-align:center that allows us to center two divs inside a wrapper div? I prefer not to have my text centered. ...

A hover effect in CSS that utilizes a psuedo element to overlay the primary element

When hovering, I want to achieve an effect that looks similar to the display below: To view my website, click here The relevant code is shown below with the !important attributes removed: .cta-button-menu, .cta-button-menu::before { transitio ...

Background image fixed with scrolling effect

I've been struggling with a parallax effect on my website. After seeing it work smoothly on other websites, I tried to implement it myself but couldn't quite get it right. The background image keeps moving when I scroll the page and I want it to ...

What are the best situations to utilize bootstrap and when should you avoid it?

When it comes to web development, there is often a debate on whether to use Bootstrap or custom CSS for designing a website. For my school project, I am tasked with creating a homepage and contact page using Bootstrap primarily. However, we are also requir ...

Crystal Reports does not recognize or integrate HTML elements

Despite entering HTML text on the field: https://i.sstatic.net/vyvQ2.png Even though I am using valid tags as explained in this resource: What HTML tags are supported in Crystal Reports 2008, my report is not generating HTML but only displaying the tags ...

What is the best way to create a CSS class for a list element in React?

I am facing an issue with styling buttons in my UI. These buttons represent different domains and are dynamically generated based on data fetched from the server using the componentDidMount() method. Since I do not know the quantity of buttons at the time ...

Bx slider - displaying partially hidden slides at the far right while utilizing a full-width carousel

Implementing a slider on my nodejs website using bx slider has been quite an experience. Below is how I achieved it: $(document).ready(function(){ $(".bxslider").bxSlider({ minSlides: 1, maxSlides: 40, slideWidth: 300, ...

Is it possible to access the operating system's native emoji picker directly from a website?

While there are numerous javascript plugins and libraries available for allowing users to select emojis for text inputs, both Windows and Mac operating systems already have their own native emoji pickers accessible via ⊞ Win. or CTRL⌘Space. Is there a ...

Is it more effective to implement react useState and conditional rendering for managing different screen sizes, or is it better to use

In my current project, I am using standard CSS3 and creating separate CSS files for each component. I am debating whether to incorporate an event listener with multiple return functions within my React component instead of having multiple media queries in ...

Proper alignment of div elements using Bootstrap

I am attempting to align 2 div elements side by side using Bootstrap code: <div class='col-12'> <div class='row'> <div class='col-6'> </div> <div class='col-6&a ...

"Implementing a function to automatically input a selected value from a dropdown menu into a text field

I'm facing an issue and need some help. I have a form with one select field and one text field. What I want is for the text field to display a value corresponding to the option selected in the select field. For example, if I choose "B" from the select ...

What is the best way to eliminate spaces, commas, and periods from a variable in javascript?

After attempting var res = str.replace(/ |,|.|/g, ""); and var res = str.replace(/ |,|.|/gi, "");, I'm still puzzled as to what I might be missing. var str = "Text with comma, space, and period."; var res = str.replace(/ |,|.|/g, ""); document.writ ...

Electron does not prioritize the @css prefers-color-scheme option

I recently completed an Electron project and decided to incorporate dark mode support into it. However, for some reason, the dark mode feature is not functioning properly. Below you will find the dark.css styling that I have included in every page: @medi ...

Removing white spaces from response HTML in JBoss 5.1 version

Does anyone know of a JBoss 5.1 plugin or utility that can automatically strip leading and trailing white spaces from HTML being sent as a response? Similarly, is there a way to do this for JSP files upon deployment? Any application-specific settings would ...

Transform preexisting Vue UI library measurements into pixels

I was curious about converting all existing units (em / rem) to pixels. How can I easily convert the entire output units to px? Are there any tricks or methods available? Currently, I am utilizing Vuesax UI to create a plugin for various websites and temp ...

Changing the Style of a CSS Module Using JavaScript

Embarking on a journey into Javascript and React, I am currently working on my first React app. My aim is to adjust the number of "gridTemplateRows" displayed on the screen using a variable that will be updated based on data. Right now, it's hardcode ...

Tips for referencing Google Maps initialization in individual files within a website application

After setting up my Google Maps API snippet: <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script> in the index.html file, I encountered the error: Uncaught InvalidValueEr ...

What is the best way to create a mirror effect on one div by clicking another div?

I have created a schedule grid and I am looking for a way to allow users to click on the UK hour and then have the corresponding U.S time highlighted. Is there a CSS solution for this? The functionality I need is to be able to select multiple hours. I have ...

Personalizing the fileTemplate selection in FineUploader

My English is not the best, so apologies in advance. I'm struggling to customize the FineUploader FileTemplate option. I don't want to use fineUploaderBasic; I want total customization. Initially, I managed to hide the file name and size after a ...