Bizarre display of miscellaneous items on the monitor

Hey there, I've been working on creating a div to display information about both the Civilian and Vehicle that users input. Initially, everything worked perfectly with my HTML and CSS until I introduced two additional divs into the layout. With just one div, the design looks like this. However, adding the extra div causes it to appear differently, as shown in this image.

I'm confused about what's causing this issue. When I apply a background to the entire content, there's no white space between "Information:" and "Civilian:". Moreover, adjusting the width of the two divs to %49.99 while setting the display to inline-block results in the elements extending off-screen, as illustrated here.

Apologies if these seem like basic problems to fix within my HTML/CSS code. My knowledge in web development is limited, so I'm experimenting with jQuery to make some modifications. Below, you'll find the snippets from my HTML and CSS files:

HTML:

    <div id="civinfo">
        <h1>Information</h1>
        <!-- CIV SIDE -->
        <div>
            <h2>Civilian: </h2>
            <span><h3>Name: </h3><p id="civname">None, None</p></span>
            <span><h3>Warrant: </h3><p id="civwarrant">None</p></span>
            <span><h3>Citations: </h3><p id="civcit">None</p></span>
        </div>
        <!-- VEH SIDE -->
        <div>
            <h2>Vehicle: </h2>
            <span><h3>Plate: </h3><p id="vehplate">None</p></span>
            <span><h3>Stolen: </h3><p id="vehstolen">None</p></span>
            <span><h3>Registered: </h3><p id="vehregi">None</p></span>
            <span><h3>Insured: </h3><p id="vehinsured">None</p></span>
        </div>
    </div>

CSS:

#civinfo {
    margin: 0;
    padding: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    background: #000000;
    width: 35%;
    height: 30%;
    display: none;
    font-family: 'Lato', sans-serif;
    color: white;
    border-radius: 10px;
}
#civinfo h1 {
    text-align: center;
    font-size: 35px;
    margin: 8px;
}
#civinfo div {
    margin: 0;
    padding: 0;
    display: inline-block !important;
    width: 45%;
    height: auto !important;
}
#civinfo div h2 {
    text-align: center;
    margin: 0 5px;
    font-weight: 400;
    font-size: 20px;
}
#civinfo div h3 {
    display: inherit;
    font-weight: 400;
    margin: 0 10px;
}
#civinfo div span {
    display: inline-block;
    margin: 0;
    padding: 0;
    margin-bottom: 5px;
    width: 75%;
    height: auto;
}
#civinfo div p {
    float: center;
    text-align: center;
    display: inherit;
    padding: 5px 15px;
    background: #bbbbbb;
    color: black;
    border-radius: 25px;
    font-size: 16px;
}

Answer №1

<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: lightblue;
}

h1 {
    color: white;
    text-align: center;
}

p {
    font-family: verdana;
    font-size: 20px;
}
.content-wrapper{
display:flex;
}
.content-wrapper > div{
width:50%;
}
.content-wrapper > div > span{
display:flex;
}
h1{
display:block;
}
</style>
</head>
<body>
 <div id="civinfo">
        <h1>Information</h1>

        <div class="content-wrapper">
        <!-- CIV SIDE -->
        <div>
            <h2>Civilian: </h2>
            <span><h3>Name: </h3><p id="civname">None, None</p></span>
            <span><h3>Warrant: </h3><p id="civwarrant">None</p></span>
            <span><h3>Citations: </h3><p id="civcit">None</p></span>
        
        <!-- VEH SIDE -->
        
            <h2>Vehicle: </h2>
            <span><h3>Plate: </h3><p id="vehplate">None</p></span>
            <span><h3>Stolen: </h3><p id="vehstolen">None</p></span>
            <span><h3>Registered: </h3><p id="vehregi">None</p></span>
            <span><h3>Insured: </h3><p id="vehinsured">None</p></span>
        </div>
    </div>
</div>
</body>
</html>

For a better layout, both the civilian and vehicle information are now wrapped in one flexbox div. Please try modifying the CSS as needed for customization.

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 could be causing the issue with my linear gradient not displaying correctly on top of my background image in Rails and Sass?

I am struggling to get a linear gradient to display over a background image. Despite trying various solutions from other questions, I still can't get it to work with my current code... .bottom-pic { width: 100%; height: 425px; ...

Is it possible to execute an Ajax Request using JQuery?

I've been attempting to update the content within a <div> using a JQuery Ajax Call, but unfortunately I'm encountering some difficulties. Whenever I click on the onclick <a> element, nothing seems to happen. Below is the code that I a ...

How to center a label vertically within a button group using Bootstrap

How can I vertically align labels for 2 inline elements inside a horizontal form without using hacks like display:table? So far, this is the code I have tried: bootply ...

React component allowing for the reuse of avatars

As a novice in React, I've encountered a challenge. My goal is to develop a simple reusable component using MUI. Specifically, I aim to create an avatar component that can be easily customized with different images when called upon. I want the flexibi ...

Step-by-step guide to creating a dynamic button that not only changes its value but also

I am trying to implement a translation button on my website that changes its value along with the text. Currently, I have some code in place where the button toggles between divs, but I am struggling to make the button value switch as well. Given my limit ...

Any suggestions on how to repair this Node.js login interface?

Currently grappling with setting up a Node.js application with a MySQL database to create a basic login functionality. Encountering an issue: Cannot POST /login <body class="hero-image"> <div id="container"> <div ...

Having an issue with jQuery where trying to append a remove button to a list results in the

Looking to create a dynamic list where users can easily add new items by clicking a button. As each item is added, a corresponding remove button should also be displayed. The issue I'm facing is that every time a new item is added, an extra close but ...

Move the Div element up and down when clicked

When a tag is clicked, the corresponding div opens and closes. I would like the div to slide down and up slowly instead of appearing immediately. <a href="" class="accordion">Click here</a> <div class="panel" id="AccordionDiv"> ...

Is there a method to access a website, trigger JavaScript functions, and subsequently retrieve the HTML content using PHP?

I am currently exploring options to access a webpage, execute JavaScript functions on it (thus altering the HTML content), and eventually save the modified version of the page. I'm uncertain if this approach is feasible, and if not, are there alternat ...

What causes the disparity between Chrome's print preview and printed output? [HTML - CSS]

In my Angular demo project, I have included basic text and a table. There is a print button that calls window.print() to print the page with applied styling. printPage() { window.print(); } CSS: @media print { @page { size: landscap ...

Customizing a ControlsFX PopOver in a JavaFX application

I am looking to personalize the appearance of a JavaFX PopOver control. I have a button that triggers the display of the PopOver. Below is a functional example: package custompopover; import javafx.application.Application; import javafx.event.ActionEvent ...

Resounding achievement following the completion of the upload

I'm looking to display the message "success" on the same page as my form if it uploads correctly. I am new to PHP and not sure how to achieve this. Can anyone help? index.php <form action="upload" method="POST"> <input name="field1 ...

Modify table row background color using PHP based on its position in the table with the use of a function

I am having trouble formatting my table to highlight different rows in distinct colors. The top row should be one color, the second row another, and the bottom two rows a different color each. This is to represent winners, teams getting promoted, and tho ...

Challenges encountered while attempting to animate the CSS clip feature in WebKit

I've been searching everywhere for a solution to my issue, but none of them seem to work. As someone new to CSS3 Animations, I appreciate your patience. I created a simple animation using CSS3 that functions perfectly in IE and Firefox, however, it ...

Can someone guide me on how to align text to the bottom border of a page?

Is there a way to adjust the position of the header text ("bottom text") so that it appears just above the bottom border of the page? I have attempted modifying styles and classes within the footer, style, and h3 tags but have not had any success. Below ...

Using PHP to insert data from a form with multiple checkbox selections into a MySQL database

Having a form with various fields like Textinputs, Checkboxes, Radios...and seeking to submit it to a MySQL database. Oddly enough, when I remove the checkboxes HTML and associated PHP code, everything functions properly, and all information is successfull ...

Displaying a list of values in Angular using data retrieved from an Entity Framework query

Is there a way to populate a list (ul li) with data from an array that is populated through Entity Framework code? Currently, I am able to populate an option dropdown successfully using the following code: <select class="form-control" name="Search" ...

Tips and tricks for ensuring images maintain their aspect ratio and height when resizing for responsiveness

I am facing an issue with my two-column layout. One column contains an image and the other column has text and buttons with a fixed height. To ensure the image is responsive, I have set the width to 100% and height to auto. However, upon resizing, the aspe ...

Experiencing discrepancies in pixel height while conducting tests using Nightwatch

Let me start by sharing some details about my machine setup: Operating System: CentOS 7 Graphics Drivers: kmod-nvidia (dedicated GPU) I am currently testing a webpage using Nightwatch, and one of the requirements is to ensure that a background image&apo ...

Mozilla browser experiencing issues with mouse move event functionality

Here, I have a background image on the body and with the following script, when the user moves the mouse, the image in the background also moves. body { background-image: url('../images/1.png'); background-size: 98%; background-posi ...