The div elements appear perfectly without any text, but as soon as I add text within the boxes, it alters their appearance

After inserting an image and some text, I encountered a strange issue with my code. Specifically, when adding text to the box element, it did not display as expected. I am perplexed by this behavior and unsure of the root cause.

I suspect that the problem lies in the .divver class within my code. Despite incorporating the full grid layout and proper positioning for the <div> elements, the desired outcome was not achieved.

Could the solution involve adjusting padding or margins? Perhaps varying the width of each box might resolve the issue. Any guidance on how to address this anomaly would be greatly appreciated.

Your assistance is invaluable,

Ring Games

Answer №1

display: inline-block typically aligns elements based on their baseline.

When the elements are empty, this baseline is at the bottom of the element itself.

However, once you add text, the baseline shifts to that of the text. This results in the text's bottom being aligned with the other elements' bottoms.

If this layout isn't working for you, consider using display: grid;, display: flex;, or even column-count: 3;. If you're unable to switch, adding vertical-align: top; might solve the issue.

Answer №2

To enhance your design, consider utilizing absolute positioning in the CSS code snippet provided below:

      .front {
        background: #e0e0e0;
        width: 100%;
        height: 200px;
        border: 5px solid black;
      }
      @keyframes animateonload {
        0% {top: 0; left: 200px; background: #80ed9d;}
        25% {top: 200px; left: 200px; background: #9f80ed;}
        50% {top: -101px; left: -900px; background: #eda380;}
        75% {top: 900px; left: 200px; background: #3e6b66;}
        100% {top: 450px; left: 100px; background: #ccfa8c;}
      }
      body {
        animation-name: animateonload;
        animation-duration: 5s;
        animation-iteration-count: 1;
        position: relative;
        width: 100%;
        height: auto;
      }
      .divver3 {
        width: 33%;
        height: 600px;
        background: #faa68c;
        font-size: 20px;
        display: inline-block;
        grid-column: 3;
        grid-row: 1;
      }
      .divver2 {
        width: 33%;
        height: 600px;
        background: #faa68c;
        font-size: 20px;
        display: inline-block;
        grid-column: 2;</answer2>
    </div></answer2>
<exanswer2><div class="answer accepted" i="61770886" l="4.0" c="1589351090" a="Sm9obg==" ai="11111119">
<p>Consider adjusting your positioning to be absolute with the following CSS example:</p>

<p><div>
<div>
<pre class="snippet-code-css lang-css"><code>      .front {
        background: #e0e0e0;
        width: 100%;
        height: 200px;
        border: 5px solid black;
      }
      @keyframes animateonload {
        0% {top: 0; left: 200px; background: #80ed9d;}
        25% {top: 200px; left: 200px; background: #9f80ed;}
        50% {top: -101px; left: -900px; background: #eda380;}
        75% {top: 900px; left: 200px; background: #3e6b66;}
        100% {top: 450px; left: 100px; background: #ccfa8c;}
      }
      body {
        animation-name: animateonload;
        animation-duration: 5s;
        animation-iteration-count: 1;
        position: relative;
        width: 100%;
        height: auto;
      }
      .divver3 {
        width: 33%;
        height: 600px;
        background: #faa68c;
        font-size: 20px;
        display: inline-block;
        grid-column: 3;
        grid-row: 1;
      }
      .divver2 {
        width: 33%;
        height: 600px;
        background: #faa68c;
        font-size: 20px;
        display: inline-block;
        grid-column: 2;</answer2>
<exanswer2><div class="answer accepted" i="61770886" l="4.0" c="1589351090" a="Sm9obg==" ai="11111119">
<p>Try changing the position to absolute by referring to this method:</p>

<p><div>
<div>
<pre class="snippet-code-css lang-css"><code>      .front {
        background: #e0e0e0;
        width: 100%;
        height: 200px;
        border: 5px solid black;
      }
      @keyframes animateonload {
        0% {top: 0; left: 200px; background: #80ed9d;}
        25% {top: 200px; left: 200px; background: #9f80ed;}
        50% {top: -101px; left: -900px; background: #eda380;}
        75% {top: 900px; left: 200px; background: #3e6b66;}
        100% {top: 450px; left: 100px; background: #ccfa8c;}
      }
      body {
        animation-name: animateonload;
        animation-duration: 5s;
        animation-iteration-count: 1;
        position: relative;
        width: 100%;
        height: auto;
      }
      .divver3 {
        width: 33%;
        height: 600px;
        background: #faa68c;
        font-size: 20px;
        display: inline-block;
        grid-column: 3;
        grid-row: 1;
      }
      .divver2 {
        width: 33%;
        height: 600px;
        background: #faa68c;
        font-size: 20px;
        display: inline-block;
        grid-column: 2;
        grid-row: 1;

      }
      .divver1 {

          width: 33%;
          height: 600px;
          background: #faa68c;
          font-size: 20px;
          display: inline-block;
          grid-column: 1;
          grid-row: 1;
          position: absolute;

      }
      .div {
        width: 100%;
        height: auto;
      }
      .divver1 h1 {
        text-align: center;
        margin: 0;
      }
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title> Ring Games - Official Site</title>
  </head>
  <body>

    <div class="div">
      <div class="divver1">
<h1>this is some text</h1>
      </div>
      <div class="divver2">
      </div>
      <div class="divver3">
      </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

What is the best way to apply fill to SVG using Tailwind CSS?

I tried using the code provided, but unfortunately, I was unable to Override the fill. The issue seems to have been resolved, but can someone help me achieve this using tailwind CSS? <div className=""> <svg className="text- ...

How to position text in the center of an image and ensure it is responsive?

I am currently in the process of trying to center the text "WHAT" over the image in col-2. <div class="row"> <div class="col-2"> <div class="stackParent"> <img class="stack-Img" ...

What is the best way to conceal the bottom portion of an image?

My image in the header overlaps with the next section's features (image-phone). https://i.sstatic.net/4g0SO.jpg I've tried changing the position and z-index types. If I crop the image, it's not ideal and difficult to fix ;) How can I stru ...

What is the solution for correcting the caret position in the Notification box?

I've encountered an issue with my Bootstrap dropdown notification system. I've noticed that the caret, which is intended to be positioned below the message icon, often moves away from it when viewed on different devices or screen sizes. Is there ...

Steps to center an HTML canvas on the screen

I attempted to center my canvas horizontally using <div style="text-align:center;">, but the y axis remains unchanged. How can I position the HTML canvas in the center of both the x and y axes? Any suggestions on how to achieve this alignm ...

Submitting the form does not result in the textbox being cleared

I have been attempting to clear the txtSubTotal text box upon clicking the PROCEED button, but it seems that my efforts have been in vain despite trying various code examples, including those from SO. btnProceed/HTML <input type="submit" name="btnProc ...

Steps to access the file path of a swf document stored in a MYSQL database and display it on a web page

There seems to be an issue with my code below. The database I am working with is named nisreen, and the table within it is called ana. My goal is to retrieve the path of a SWF file from the database and display it on a web page. <!DOCTYPE html PUBLIC ...

Preventing Paste Function in Electron Windows

Currently, I am utilizing Electron and attempting to prevent users from pasting into editable content. While paste and match style remains enabled, the functionality is flawless on Mac devices. However, there seems to be an issue on Windows where regular ...

What causes the cancel button to add spaces and create a line break in the textarea field?

Whenever I click the "cancel" button, the textarea inexplicably receives 26 spaces before any existing text and a carriage return after it. This issue occurs when the cancel button is styled in the traditional HTML manner: <button type="reset" name="re ...

Unable to utilize the standard Bootstrap color scheme within Sass

After importing the bootstrap scss with the provided code snippet @import "node_modules/bootstrap/scss/bootstrap"; I experimented with altering default bootstrap variables such as : $border-radius: 1rem; However, I encountered a challenge when ...

Implementing a Custom CSS Theme in JavaFX

Hey everyone, I stumbled upon this amazing JavaFX theme called Flatter on . I've been attempting to implement it for a couple of hours now, but I'm struggling with the process. Can someone provide me with a detailed guide on how to activate thi ...

Place a picture within a specified View

I am encountering an issue with my profile image in the header component. The source of the image is coming from the database as a string array. However, when I fetch the user picture from the database, it appears slightly cut off from the top, giving the ...

Aligning pictures in a vertical arrangement across various rows

Is it possible to style a bunch of images in CSS without defining anything in HTML, so that they appear in multiple rows aligned vertically with each row containing 5 or 6 images? The current code using .wrapper displays the images endlessly in one row. C ...

Employing jQuery Mobile Cache Manifest with PHP

Exploring the use of jquery mobile cache manifest, I'm curious to know if it's compatible with Php files as well. Appreciate any insights. ...

Creating a two-column grid layout using Bootstrap 4 is a simple and efficient process. Let's see how

I've been struggling to get this to display side by side in a two-column grid. Even after following Bootstrap tutorials, I can't seem to make it work. Check out the code below: <div class="row"> <div class="col-md-8 ...

Vue.js transition-group does not apply the *-move class

As I dive into learning Vue, I find myself wondering if I may have overlooked something fundamental or stumbled upon a bug. Despite multiple readings of the documentation at https://v2.vuejs.org/v2/guide/transitions.html#List-Move-Transitions, I still can& ...

Having trouble with the nth-child CSS property in Bootstrap?

My cards need some styling adjustments - specifically, I want the first and third card in each row to have a top margin of 50px. Strangely, this doesn't seem to work with Bootstrap, but it does with pure CSS. Is there a specific class in Bootstrap tha ...

Tips for increasing the spacing in information on a Python-based website

I am facing an issue with my code that is intended to format the data like this: Searching for: 5456 Child Unit ID: 32455 Unit Location: Test Despite writing the code to create this indentation, it doesn't seem to be working when I view it on ...

Apply a uniform style to a selection of <a> tags using CSS

As a beginner in web programming, I am currently exploring ASP.NET. In my project, I have three links structured like this: <ul style="margin-top:10px;"> <a style="background-color:transparent;padding:0px;" href="..."><img src="..."/> ...

The functionality of the page becomes disrupted when multiple timers are used after the setInterval function is executed in

My webpage fetches multiple data for a table, with one of the columns displaying date and time values from which countdown timers run. Each row has its own timer and functions correctly. However, when I added JavaScript code to refresh the table every 10 ...