What are the best ways to ensure a website is responsive in a vertical

When designing a responsive webpage, I encountered an issue with the body element not properly expanding the content vertically. Despite enlarging the web content horizontally, the body failed to adjust its height accordingly, resulting in unwanted black areas on the page.

body {
  background-color: black;
  padding-bottom: 10vh;
  padding-top: 10vh;
  padding-right: 10vh;
  padding-left: 10vh;
  margin: 0;
  height: 100%;
  align-content: center;
  justify-content: center;
  position: relative;
}

#wrapper {
  position: static;
  align-items: center;
  height: 100%;
  width: 100%;
  align-content: center;
  display: flex;
  flex-direction: row;
  margin: 0 auto;
  justify-content: center;
  overflow: auto;
}

#wrapper2 {
  align-items: center;
  width: 100%;
  height: 100%;
  align-content: center;
  display: flex;
  flex-direction: row;
  margin: 0 auto;
  justify-content: center;
  overflow: auto;
}

img {
  width: 100%;
  height: 100%;
  display: block;
}

.cell1 {
  width: calc(100% / 3);
  text-align: center;
  background-size: contain;
  height: 100%;
  background-position: center;
  position: relative;
}

.cell2 {
  width: calc(100% / 3);
  text-align: center;
  background-size: contain;
  height: 100%;
  background-position: center;
  position: relative;
}

.cell3 {
  width: calc(100% / 3);
  text-align: center;
  background-size: contain;
  height: 100%;
  background-position: center;
  position: relative;
}

.dogname {
  color: white;
  top: 20px;
  font-family: 'Roboto Condensed', sans-serif;
  text-align: center;
  position: absolute;
  width: 100%;
  margin: 0;
}

.dogtext {
  color: white;
  top: 0;
  font-family: 'Roboto Condensed', sans-serif;
  text-align: center;
  position: relative;
  width: 100%;
  margin-bottom: 30px;
  margin-top: 0px;
  display: none;
}

@media screen and (max-width: 500px) {
  #wrapper {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
  }
  #wrapper2 {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
  }
  .cell1 {
    width: 100vw;
  }
  .cell2 {
    width: 100vw;
  }
  .cell3 {
    width: 100vw;
  }
  .dogname {
    display: none;
  }
  .dogtext {
    display: block;
  }
  body {
    background-color: black;
    height: 100%;
    padding: 0;
    margin: 0;
  }
}
<body>
  <div id="wrapper">

    <div class="cell1">
      <p class="dogname">David Neal</p>
      <img src="images/image1.jpg" />
    </div>

    <p class="dogtext">After the hunt (1870) by David Neal</p>

    <div class="cell2">
      <p class="dogname">BG Tiepolo</p>
      <img src="images/image2.jpg" />
    </div>

    <p class="dogtext">Portrait of a Toy Spaniel Belonging to the Infanta Maria Josefa of Bourbon (1763) by Giovanni Battista Tiepolo</p>

    <div class="cell3">
      <p class="dogname">AF Desportes</p>
      <img src="images/image3.jpg" />

      <p class="dogtext">Chienne blanche devant un buisson de sureau (1714) by Alexandre-François Desportes</p>

    </div>
  </div>
  <div id="wrapper2">

    <div class="cell1">
      <p class="dogname">JC Merck</p>
      <img src="images/image4.jpg" />

      <p class="dogtext">Ulmer Dogge (1705) by Johann Christof Merck</p>

    </div>

    <div class="cell2">
      <p class="dogname">John Wootton</p>
      <img src="images/image5.jpg" />

      <p class="dogtext">A Grey Spotted Hound (1738) by John Wootton</p>
    </div>

    <div class="cell3">
      <p class="dogname">EH Landseer</p>
      <img src="images/image6.jpg" />

      <p class="dogtext">A Distinguished Member of the Humane Society (1838) by Edwin Henry Landseer</p>


    </div>
  </div>
</body>

Answer №1

The solution you choose may vary based on your specific goals, but in most cases, utilizing media queries for both height and width can be effective.

@media screen and (max-width: 800px) , screen and (max-height: 600px) {
  ...
}

Answer №2

Typically, your webpage adjusts vertically according to the content's height. To ensure it is always at least one viewheight tall, add this line to your css:

html, body {
    min-height: 100vh;
}

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

The collapsible menu does not toggle when I tap on the icon

I am currently troubleshooting an issue with this link "https://sampledemos.online/training/index.html" where the toggle feature is not functioning properly. Below are the codes I have written: <aside id="layout-menu" class="layout-menu m ...

Inject the HTML code into a bash script and perform operations on it

Could someone help me with a bash scripting question? I'm new to this, so I may have missed it if it's already been answered. I want to pass the html source code of a web page to my script, which will then modify or scrape the web page of its HT ...

What is the best way to ensure that my text is perfectly centered both horizontally and vertically within this DIV?

What's the best way to vertically and horizontally center text? Here is an example code that needs to be centered: <div style="display: block; height: 25px;"> <span id="ctl_txt" style="background-color: rgb(255, 0, 0);"> Basic ...

The hover effect in CSS brings life to list items when filled with content

I am attempting to create an animation for an <li> element that gives the illusion of a fill effect moving from left to right when hovered over. This is my current progress: ul { list-style-type: none; } .hoverTest { float: left; margin-right: 1 ...

Using the Firefox API to determine if a tab is currently active

I remember hearing about a feature that was introduced in some recent versions of Firefox allowing developers to check if a tab is active or not using JavaScript. However, I am having trouble finding more information about it online. Can you share the li ...

Position the paper-icon-button so that it is aligned to the top-right corner of the scaffold

Looking for a way to... <core-scaffold id="core_scaffold"> <core-header-panel mode="seamed" id="core_header_panel" navigation flex> <core-toolbar id="core_toolbar"></core-toolbar> <core-menu valueattr="label" ...

Are the buttons appearing within a pop-up display?

I am having an issue with my Javascript popup buttons. Whenever the popup appears, the buttons that come after the one clicked appear on top of the popup container, and the previous buttons appear behind it. How can I ensure that the popup container displa ...

What is the best way to select an element based on its relationship to another Element object using a selector?

I am currently developing a small library in which I require the ability to select a relative element to the targeted element using the querySelector method. For instance: HTML <div class="target"></div> <div class="relative"></div& ...

Grid system that adapts without distortion

My goal is to create a grid that maximizes the number of elements in its width without stretching them to fit the entire window. That's why I'm utilizing CSS grid with the auto-fill property, which is almost achieving the desired outcome. I want ...

Mobile devices are having issues with CSS rendering

I've encountered an issue with my CSS code. It seems to be working fine until the @max-width:767 media query, but then it stops working on the resolution immediately below it, which is @425. However, it starts working again on resolutions below that. ...

Apply borders to the table provided in the email using Python

Presently, I am utilizing this approach for sending tables in emails via Python instead of attaching them: Send table as an email body (not attachment) in Python import smtplib from smtplib import SMTPException import csv from tabulate import tabulate te ...

Combining the background images of two separate <div> elements results in a deeper shadow effect than when they are individually displayed

Encountering an issue with overlapping background images that results in a darker shadow where they intersect, causing an uneven appearance. The problem arises with a flexible height box containing semi-transparent background images designed to create att ...

Inserting lines into the text, creating a visually appealing layout

Can a notepad design be created using CSS only? Is it feasible to include lines between text lines without using underscores? I want it to look like this example but with minimal spacing between lines and no manual insertion of span tags since the text wi ...

mandatory data fields for an HTML form

I'm having some trouble creating an HTML form with mandatory input fields. The code I have so far is shown below: <div class="col-sm-6"> <label for="city" class="form-control">City ...

Utilizing HTML and Javascript for streaming audio and recording voice

Working on a new project that involves streaming audio files (mp3) and recording voice messages. Initially considered using Flash, but the challenge is making the website iPhone-friendly as per the client's request. Is there a technology available th ...

Tips for creating CSS styles for a selected input field

I seem to be stuck in a situation where my screen looks similar to the screenshot provided. There are four input elements that I would like to have bordered just like in the image, complete with a circled tick mark. I've managed to create these four i ...

Using Jquery: Removing the strikethrough effect upon the second click!

Currently in the process of learning Jquery and experimenting with using a button to apply a "text-decoration" to a list item upon clicking. However, I encountered an issue where I couldn't figure out how to use the same button to remove the "text-dec ...

`Why are my overflow-x and flex-wrap not functioning as expected in React JS?`

Having trouble aligning all the movie posters in a single line? It appears that your overflow-x and flex-wrap properties aren't functioning as expected in your App.css. Here's a snippet of your App.css: body { background: #141414; color: ...

How to show a tooltip inline by utilizing CSS styling

Working on a sticky side bar menu with a tooltip feature. While it appears correctly in Chrome and Safari, the tooltip is off-center in IE. This snippet seems to be causing the issue: /* Vertically center tooltip content for left/right tooltips */ .tool ...

I can't seem to figure out why the removeChild() function is not functioning properly in my

Recently, I've been working on a search website where users can input either a partial or full name and then click a button to display a list of actors whose names contain that specific string in a hint-like fashion. These names are sourced from a MyS ...