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

Avoiding special characters in URLs

Is there a way to properly escape the & (ampersand) in a URL using jQuery? I have attempted the following methods: .replace("/&/g", "&amp;") .replace("/&/g", "%26") .replace("/&/g", "\&") Unfortunately, none of these are y ...

The feature to swap out the thumb of a range slider with an image is currently not

I'm attempting to design a unique range slider using CSS. <style> .slide-container { width: 300px; } .slider { -webkit-appearance: none; width: 100%; height: 5px; border-radius: 5px; background: #FFFFFF; outline: none; opacity: ...

Showing the Datepicker from jQuery right in the middle of the screen

Here's the generated code as default: <div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper- clearfix ui-corner-all ui-datepicker-multi ui-datepicker-multi-2" style="width: 34em; position: absolute; left: ...

Change the div attribute when clicking on a corresponding link

For the full code, please visit: https://plnkr.co/edit/6TTLVcsXLV7C1qXSMQV0?p=preview Here is an angular ui bootstrap accordion with nested panels: <uib-accordion close-others="oneAtATime"> <div ng-repeat="sub in subdivisions"> < ...

The image slide change feature ceases to function properly when incorporating two separate functions

I have a function that successfully changes the image of a container every 5 seconds. However, I am facing an issue when trying to add 2 containers side by side and change their images simultaneously. When I run the functions for both containers, only one ...

The customized styling for Material Angular does not seem to properly apply to <md-card> elements within ui-views

I am trying to achieve a specific effect on the ui-views <md-card id="sidebar" flex="20" class="sche-card" layout-padding="true"> <div ui-view="card" autoscroll="false"></div> </md-card> However, I am facing an issue where the car ...

What steps can I take to ensure that the original field does not regain focus once the dialog is closed?

My users prefer not to switch from the keyboard to mouse while filling out an input form. To address this, I am using the onFocus event to display a JQuery UI Dialog. However, when I use the dialog's close(); function, the dialog reopens as the origin ...

Navigate through the contents of a table featuring intricate colspan and rowspan elements, while keeping both headers and left columns in

I am facing a challenge with a dynamically generated table that has complex structure including colspans and rowspans. My goal is to fix the headers and, if possible, even lock the first few rows on the left side while allowing the content of the table to ...

Joomla CSS styling malfunctioning

I've been exploring the creation of an in line menu using Joomla 1.6 and CSS. The issue arises when Joomla removes <span class="dmenu"> from the document before saving, despite having all cleanup options turned off. This led me to try a couple ...

text/x-handlebars always missing in action

I'm currently working on my first app and I'm facing an issue with displaying handlebars scripts in the browser. Below is the HTML code: <!doctype html> <html> <head> <title>Random Presents</title> ...

What is the best way to embed sections of one HTML page into another page?

Is there a method I can use to embed sections of one webpage within another webpage? The dilemma arises from the fact that the second page has a distinct style compared to my main page. Is it feasible to apply the alternate style solely to specific content ...

guide for interpreting a complex json structure

I'm attempting to extract data from a JSON file that has multiple layers, like the example below. - "petOwner": { "name":"John", "age":31, "pets":[ { "animal":"dog", "name":"Fido" }, ...

JavaScript stylesheet library

What is the top choice for an open-source JavaScript CSS framework to use? ...

Exploring different options for parsing HTML content and extracting text from strings that do not contain HTML/XML tags

When looking at this particular solution for stripping HTML tags from a string, the process involves passing the string to rvest::read_html() in order to generate an html_document object. Subsequently, this object is input into rvest::html_text() to obtai ...

Having trouble displaying a background image on a React application

Public>images>img-2.jpg src>components>pages>Services.js> import React from 'react'; import '../../App.css'; export default function Services() { return <h1 className='services ...

When utilizing jQuery to retrieve the height of position:absolute elements, the script is being executed twice, resulting in inaccurate values being returned on

The issue I'm encountering with detecting the height of absolutely positioned content is demonstrated in this JSFiddle. I am working on creating a tabbed panel where users can select a room type and then a sub-type. The sub-types (ul.sub-types) are s ...

Utilizing JavaScript to add classes to a parent element

When a user clicks on a link, I want to add a class to the <li> tag that wraps around it. Here is an example: <ul> <li><a href="#">Just an Example</a></li> </ul> How can I target the <li> element enclosing ...

Accordion checkbox with dynamic features

Currently, I am dynamically populating data into a jQuery accordion. My goal is to include a checkbox just before the <h2> text. <div id="checkbox"> <h2> <span> <input type="checkbox" class="mycheck" value="apple" / ...

Tips for receiving notifications when the Collapsible collapses

I'm having trouble figuring out how to receive notifications when the Collapsible is expanded and collapsed. Currently, I am not receiving any type of notification. Any suggestions on how to make this work? Below is my code: --Imported jQuery < ...

What is the best way to center text on an HTML canvas?

Is it possible to center an h1 tag in the middle of an HTML canvas using either JavaScript or HTML? I already have a CSS file for canvas styles. HTML <body> <canvas id="myCanvas"></canvas> <script src="canvas.js"></scri ...