Position two child divs side by side within a parent div

Here's what I have accomplished so far: http://jsfiddle.net/cHKF4/3/

However, I am aiming to incorporate small boxes (box1 and box2 inside late)

#late {
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #00fff3;
    height: 200px;
    width: 960px;
    margin: 0 auto;
    margin-top: 30px;
}

#box1 {
    position: relative;
    border-style: solid;
    border-width: 1px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
    margin: 0 auto;
}

#box2 {
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
}

Appreciate your help.

Answer №1

Would this solution work for your needs (box1 and box2 positioned side by side and centered within late, with late centered on the webpage) :

<div id="late">
    <div id="inner">
       <div id="box1"></div>
       <div id="box2"></div>
    </div>
</div>​

#late {
    border: solid 3px #00fff3;
    height: 200px;
    width: 960px;
    margin: 30px auto 0 auto;
}

#inner {
    width: 408px;
    height: 100%;
    margin: 0 auto 0 auto;
}

#box1 {
    border: solid 1px #55fff3;
    height: 100%;
    width: 200px;
    float: left;
}

#box2 {
    border: solid 3px #55fff3;
    height: 100%;
    width: 200px;
    float: left;
}
​

Answer №2

I'm not entirely clear on the goal you're aiming for. Are you attempting to center #box1 and #box2 within #late?

If you simply want to place them next to each other inside #late, here is my preferred method: http://codepen.io/SaraSmith/pen/oPqwe

Answer №3

To achieve the desired layout, apply the style float:left to both #box1 and #box2

#box1 {
    float:left;
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
}

#box2 {
    float:left;
    position: relative;
    border-style: solid;
    border-width: 3px;
    border-color: #55fff3;
    height: 100%;
    width: 200px;
}

Answer №4

Experiment with this!

#box2 {
position: fixed;
top: 20px;
left: 20px;
}

Ensure the parent container maintains a relative position.

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

Is there a way to update an image dynamically within CSS using the :before pseudo-element?

I am attempting to dynamically change the background image, but I am having trouble accessing the wrapper before "wrapper:before{}" from jQuery $('.wrapper:before) .wrapper:before { content: ""; position: fixed; left: 0; right: 0; z-index: -1; displa ...

Tips for generating a new div for every iteration:

I am currently using asp.net with c# along with a Master Page. I have been attempting to create a new div for each loop in the while statement in order to customize the design as I desire. Is there a way to achieve this or is there an alternative method th ...

Center align a font-awesome icon vertically next to a paragraph of text

Is there a way to align a font-awesome icon on the left side of a text paragraph while keeping the text on the right side, even if it's longer and wraps underneath the icon? I've tried various code snippets but haven't found a solution yet. ...

Emphasize multiple anchor points

I am looking to highlight two sections of a page simultaneously. Here is what I currently have: <li class="langLI" style="list-style-type:none"><a href="/non-discrimination-and-language-assistance##French">| French Creole</a></li> ...

The combination of loading and scrolling JavaScript code is not functioning properly on the website

I created an HTML webpage that includes some JavaScript code to enhance the user experience. However, I encountered an issue when trying to incorporate a load JavaScript function alongside the scroll JavaScript function on my page. The load script is posi ...

Hide only the table that is being clicked on, not all tables

Essentially, I am using document.querySelectorAll() to retrieve an array of div elements. In my function, handleClick(), each time the button is clicked, I want to hide the table associated with that specific button. This is the current situation: https:/ ...

The getBBox() method of SVG:g is returning an incorrect width value

Hey there, I've been attempting to determine the width of a <g> element and it consistently returns 509.5 pixels regardless of what I do. Initially, I assumed this was the actual size and not scaled. However, upon opening the SVG in Illustrato ...

Extract content from an HTML element and transfer it to PHP

Alright, listen up. I've got a task at hand where I need to fetch some information from my database by calling a PHP page through a link (<a href='name.php'>). Let's just say the code is speaking louder than my words: <?php ...

What is the best way to keep a header row in place while scrolling?

I am looking to keep the "top" row of the header fixed or stuck during page scrolling, while excluding the middle and bottom rows. I have already created a separate class for the top row in my header code: view image description ...

Revolutionizing Zen Cart with slimMenu

Is there a smarter person out there who can help me understand why the slimMenu is breaking when I add these files to the bottom of the page? <link href="includes/templates/westminster_new/css/age-verification.css" rel="stylesheet"> <script src=" ...

What is the method for adjusting the success button's color using SASS?

My current theme's success button is green, but I want to change it to yellow. How can I achieve this? In the _variables.scss file, the following lines are present: $btn-success-color: $btn-default-color !default; $btn-success-bg: ...

Trouble organizing a collection of destinations based on their geolocation and proximity

To address this issue, my approach has been to feed variables into the value attributes of an option list and then sort it based on these values. When manually assigning values, everything works smoothly, for example: <option id="link1" value="1">A& ...

Error in Angular 2 component when loading background images using relative URLs from an external CSS skin

In my angular2 component, I am utilizing a third-party JavaScript library. The skin CSS of the component attempts to load images using relative URL paths. Since I am following a component-based architecture, I prefer to have all component dependencies enca ...

Trigger video to play or pause with every click event

Looking to dynamically change the HTML5 video tag with each click of an li tag. Here is the current structure: <div class="flexslider"> <ul class="slides"> <li> <video> <source type="video/mp4" src="http://t ...

Enhance your images with a hover zoom effect while viewing an overlay on top

Is there a way to make an image still zoom in on hover even when it has an overlay using CSS? I am currently working with Bootstrap 5.2 Thank you in advance. .trip-card { position: relative; } .trip-card img { border-radius: 30px; } .overlay { ...

AngularJS Validation does not verify the step limitation of an HTML number input field

Why isn't AngularJS validating the step="0.01" attribute in the second input? It seems to be working fine for the min and max attributes, but not for step. For instance: When entering 0.005, it still evaluates submitNewEntryForm.submitNewEntryAmount. ...

HTML5 full-screen API and its compatibility with different browsers

I'm curious to know the level of support for HTML5 full-screen API in popular browsers. Which is the earliest version of each browser that fully supports it? And for any browsers that don't (like IE I suppose), are there third-party libraries ava ...

How to achieve horizontal auto-scrolling in an image gallery with jQuery?

Hey there, I'm currently working on an Image Gallery project. I have arranged thumbnails horizontally in a div below the main images. Take a look at this snapshot img. My goal is to have the thumbnails scroll along with the main pictures as the user ...

Enabling the autowidth label expands the width of the td element

I am facing an issue where a label inside a table td grows in only one line when its width is greater than the td width. This results in the td expanding and not showing all the text. I would like the label to break into a new line when its width exceeds ...

What is the best way to include a background image in a div within a React component?

I'm currently following a tutorial on creating an RPG game using React. The tutorial can be found at this link. I am trying to replicate the presenter's code by typing it out myself. However, I'm running into an issue when attempting to add ...