Aligning a div with the children floating to the left

I am facing an issue with centering one div on the screen and aligning another div to the left of its parent #MyContent. Whenever I add a "float: left;" to #Latest, it causes a DOM error where #MyContent no longer holds #Latest and shrinks, leaving #Latest out as if it were positioned absolutely instead of relative.

Here is my current setup:

HTML:

<center>
    <div id="MyContent">
        <div id="Latest">
            <div class="Last"></div>
        </div>
    </div>
</center>

CSS:

#MyContent {
    position: relative;
    font-family: FontStencil;
    font-size: 12px;
    padding: 20px 20px 160px 20px;
    color: black;
    background: rgba(240, 240, 240, 0.2);
    border-radius: 18px;
    border: 1px solid #CCCCCC;
    top: 250;
    width: 950px;
    box-shadow: 0px 5px 15px -2px black;
}

#Latest {
    position: relative;
    font-family: FontStencil;
    float: left; /* When I remove THIS, everything works Fine BUT its all centered */
    text-align: left;
    font-size: 18px;
    padding: 20px 20px 30px 20px;
    color: #000033;
    background: white;
    border-radius: 18px;
    border: 1px solid #CCCCCC;
    left: 20px;
    top: 30px;
    width: 570px;
    box-shadow: 0px 1px 17px -5px black;
}

.Last {
    position: relative;
    font-family: SuperG;
    text-align: left;
    right: -18px;
    font-size: 12px;
    padding: 15px;
    color: #000033;
    background: white;
    border-radius: 18px;
    border: 1px solid #CCCCCC;
    top: 25px;
    width: 500px;

    height: 415px;
    box-shadow: 0px 1px 17px -5px black;
}

Despite setting everything to position: relative, when I apply float: left; to #Latest, it seems to act as if it's not. Any suggestions would be greatly appreciated.

Answer №1

Styling with CSS

#ContentBox{
font-family:Arial;
font-size:14px;
padding:25px 20px 150px 20px;
color:black;
background:rgba(220,220,220, 0.2);
border-radius:15px;
border:1px solid #999999;
top:230px;
width:900px;
box-shadow: 0px 5px 12px -2px grey;
margin: 0 auto;
    display: inline-block;
}

#Newest{
position:relative;
font-family:Arial;
float: left; /* Removing THIS fixes the alignment issue */
text-align:center;
font-size:16px;
padding:20px 20px 25px 20px;
color:#000022;
background:white;
border-radius:15px;
border:1px solid #999999;
left:10px;
top:20px;
width:550px;
box-shadow: 0px 1px 15px -5px grey;
}

.Recent{
position:relative;
font-family:Helvetica;
text-align:left;
right:-15px;
font-size:11px;
padding:12px;
color:#000044;
background:white;
border-radius:15px;
border:1px solid #999999;
top:20px;
width:470px;
height:385px;
box-shadow: 0px 1px 14px -5px grey;
}

Feel free to test out the CSS above. SEE DEMO

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

In what ways can CSS be used to create a smoother edge effect on images?

After attempting to add an image to my website, I noticed that its edges appear quite rough. https://i.sstatic.net/Xol9R.png(Note: In the image above, you can observe the jagged surface around the berry). This issue arose when I eliminated the background ...

ASP.NET Script Bundling delivers combined files, although receiving a 404 response code

I am currently working on a c# ASP.NET web application. I have successfully implemented JS bundling and made sure that everything is properly configured. Despite checking numerous similar errors on stackoverflow, I seem to be facing an issue. When I enter ...

Formik: encountering target as undefined while passing Material UI Date Picker as prop to React Component

I'm currently working on developing a component that can be reused. The idea is to pass form fields as props, but I ran into an issue when clicking on the datepicker field. The error message that pops up is: TypeError: target is undefined Any sugge ...

Steps to display a specific div section upon selecting a dropdown option and clicking the submit button using jQuery

I'm having an issue displaying a specific div section when selecting an option from a dropdown menu. I've written the code below, but it doesn't seem to be working. Can anyone please assist me with this? My actual requirement is that I only ...

Is there a way to prevent the second ul from appearing?

Seeking assistance with navigation. When clicking on the "Athletics" tab in the provided link, the second ul displays. Is there a method to hide this second ul and have it only appear upon hovering? ...

Tips for utilizing regex to locate words and spaces within a text?

I'm feeling so frustrated and lost right now. Any help you can offer would be greatly appreciated. I am currently dealing with an issue in Katex and Guppy keyboard. My goal is to create a regex that will identify the word matrix, locate the slash that ...

Is it possible to invoke a C# method within a string concatenation method when using HTML tags?

I have a method called RenderAppraisalImage() that uses a foreach loop to iterate through my images and create HTML tags for them using html.Append. I have also created a delete method and need to add a button tag to the html.append function so that when a ...

Issues with storing data in localStorage have been identified in the Facebook browser for iOS

When our web app (built using React) is accessed through the Facebook browser on iOS and Android, we have noticed some unusual behavior with the local storage. Our authentication process relies on storing a token in local storage and then retrieving it. Th ...

How can I implement a thumbnail editing feature similar to Facebook's display image uploader in an Asp.net application using c#?

How can I upload an image and display a specific part of it in a thumbnail of a custom size? I also want to personalize the appearance of the thumbnail. ...

Efficiently determine optimal menu item dimensions using CSS automatically

Is it possible to automatically position menu items using CSS so that the position is recalculated when the menu item text changes? Currently, I have a menu created with ul li's and I am using padding for positioning. However, if the text becomes long ...

Customizing skin CSS for DNN Portal and Page images

Currently, I have a unique custom skin that I personally created. It is implemented on multiple portals that I am responsible for managing. My goal is to incorporate the ability for the header image to change based on the specific page being viewed. The he ...

Move a single <div> element according to the screen resolution

I'm a beginner in coding and struggling with a specific problem. I need to adjust the position of a container based on screen size. For large and mid-sized screens, the container needs to be left-justified with a small amount of padding from the left ...

"Is it possible to create a loop function in JavaScript

Could someone please guide me on how to incorporate an endless loop or a consistent repetition into this section of my JavaScript code? <script> $(".modcontentnewestmore").hide(); $('.morebutton').click(function () { if ($('.modco ...

Transfer specified MySQL information to an Excel spreadsheet

I need help with exporting specific data from MySQL to Excel. I've successfully retrieved the necessary data from a MySQL table and organized it as required. https://i.sstatic.net/YZ0y2.jpg What is the best way to export the data from the current pa ...

Mastering the art of utilizing AJAX for autocomplete functionality

While utilizing the autocomplete feature from jqueryui (http://jqueryui.com/autocomplete/#remote) and fetching data from "source: "search.php"" The following script ... $( "#name" ).autocomplete({ source: "search.php", minLength: 2, select: function( ...

Exploring the concept of upserting records using the MongoDB $

I am working with two collections in my database: Regions and Registrations. var RegionSchema = new Mongoose.Schema({ name: {type: String}, registrations: [{type: Mongoose.Schema.Types.ObjectId, ref: 'registrations'}], ... }); The Registr ...

Improving the efficiency of AES decryption in Node.js

I had the idea to build a webpage that would display decrypted data fetched from the server. The app.js file on the server reads and decrypts all the data from a specific folder. var http = require('http'); var path = require('path'); ...

Is it necessary to enable validation for an Angular reactive form toggle?

Can you help with this issue I'm having? I have a radio button that asks the user if they have a massage certificate. If they answer yes, a file input should be displayed. By default, the file input should not be required, but if the user selects yes, ...

Node.js encountering unexpected pattern during RegExp match

Currently, I'm developing a script that aims to simplify local testing by creating a Node server for all my Lambda functions. My main challenge lies in extracting all the dbconfig objects from each file. To test out various patterns, I rely on . Surpr ...

A substitute for the maximum attribute that is compatible across different browsers in HTML5 and PHP

<input type="number" name="amount" max="6" /> Exploring the Combination of HTML5 and PHP In my attempt to utilize the above code within order.php using HTML5, I have encountered some challenges. Could incorporating PHP be a potential solution? This ...