How a child element in CSS can create a margin that spans the entire width of its parent

Constructing an overlay with a stylized container for text, but encountering an issue where the container is creating a margin that, when combined with the normal width of the elements, occupies the entire width of the parent element. Chrome dev tools indicate that the .flipcontainer element is responsible for this.

This behavior is quite odd and I am unable to determine the reason behind it.

Because of this margin being generated, if I wanted to position content to the right of the container, I would not be able to do so.

.flipcontainer {
  height: 230px;
  width: 150px;
}
.flipcalender {
  border: 1px solid #dddddd;
  border-radius: 25px;
  margin: 0 auto;
  margin-top: 0.2px;
  background: linear-gradient(white, #f4f2f2);
}
.mmouter {
  width: 100%;
  height: 100%;
  border: 1.5px solid #dddddd;
}
.mmmiddle {
  width: 98%;
  height: 98%;
}
.mminner {
  width: 98%;
  height: 98%;
  background: linear-gradient(white, #f4f2f2);
  position: relative;
}
.mmbreaker {
  width: 99%;
  background-color: white;
  height: 2px;
  position: absolute;
  z-index: 1;
  top: 115px;
}
#mmlightbox {
  display: block;
  width: 400px;
  height: auto;
  position: fixed;
  top: 30%;
  left: 40%;
  z-index: 999;
  background-color: white;
  padding: 10px 20px 10px 0px;
  /* margin-right: 239px; */
  margin-top: -100px;
  margin-left: -150px;
  border: solid 2px #f21c0a;
}
<div id='mmlightbox'>
  <div class='flipcontainer'>
    <div class='flipcalender mmouter'>
      <div class='flipcalender mmmiddle'>
        <div class='flipcalender mminner'>
          <p class='daysremaining'></p>
          <p>days</p>
          <div class='mmbreaker'></div>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №1

To align to the right, apply float: right; to the CSS of .flipcontainer as shown below:

.flipcontainer {
    height: 230px;
    width:150px;
    float: right;
}

For a demonstration, check out this JSFiddle example

The reason for the margin you noticed was because you set the width to '150px'.

Answer №2

By including the float: left property, you can eliminate the issue and incorporate content beside it.

.flipcontainer {
    height: 230px;
    width:150px;
    float: left;
}

Take a look at the demonstration on Fiddle http://jsfiddle.net/epe3bfdw/

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

Invoking functions within a jQuery extension

I've come up with this code to define the instance of my plugin: $.fn.someplugin = function(opts) { $(document).on('click', '.option-1', function() { alert(1); }); }; To make my plugin work, I utilize code similar to this ...

The getImageData function is returning undefined RGB values

I am trying to create a feature where by clicking on an image, I can retrieve the RGB values of that specific pixel. Below is the code snippet I have implemented: <html> <body> <canvas id="kartina" width="500" height="500"></canvas&g ...

Using 2 viewports depending on the device

My website looks great on all devices and desktop, but I want to set a different viewport for iPad. I would like the iPad to have the same width as my desktop version, which is 1100px wide. Currently, the site is designed with percentages and ems up to (ma ...

Make sure that the webpage does not display any content until the stylesheet has been fully loaded by

I am seeking to utilize ng-href for loading different Themes. One issue I am encountering is that the unstyled content appears before the stylesheet is applied. I have created a Plunker where I made changes to Line 8 in the last 3 Versions for comparison ...

Dynamic insertion of the current page's id into href links

Below is a link from a specific WordPress plugin: <a href='".home_url("?p=7&action=get_marks&id=$select_data2->id")."' ></a> I am looking to automatically detect the page_id when clicked for reloading the same page, like ...

Exploring carousel elements in Selenium using Python

As a user of Selenium, I am trying to loop through the games displayed in the carousel on gog.com and print out all the prices. Below are two random XPaths that lead to the information within the carousel: /html/body/div[2]/div/div[3]/div/div[3]/div[2]/di ...

What are the ways to incorporate the width property in @media queries within CSS?

I've been struggling to set the width inside @media in my code, but it's not working as expected. Here is what I have tried: mat-toolbar { app-toolbar-left { width: 35%; } app-toolbar-right { width: 22%; } } @me ...

The use of Angular's ngClass directive does not work within the link function

I have a straightforward directive that renders an element, and this is the template: <div class="nav-item"></div> The .nav-item class looks like this: .nav-item { height: 50; } Here's the directive in action: angular.module('m ...

Equal dimensions for all cards in the TailwindCSS gallery display

I am currently working on an image gallery in React with Tailwind CSS. Here's a glimpse of how it looks: https://i.stack.imgur.com/ABdFo.png Each image component is structured like this: <div className="flex items-center"> < ...

Adaptive Design - Content Fragmentation

I am currently working on a webpage layout that has the following HTML structure: <div class="row"> <div class="col3">test 1</div> <div class="col3">test 2</div> <div class="col3">test 3</div> </div ...

Troubleshooting CSS issues in HTML pages

I created an HTML file but the CSS properties are not displaying correctly in the browser. I'm not sure where I made a mistake. Instead of using a separate CSS file, I have included it directly in the HTML file. <!DOCTYPE html> <html> &l ...

The CSS3 animations using transit do not occur at the same time in Internet Explorer and Firefox

I am currently developing a presentation library to simplify my work. Naturally, animations play a significant role in this project. The library leverages Transit for smooth CSS3 animations. One specific animation involves an element sliding into or out o ...

Unable to retrieve session information from a different PHP page

I have been searching for solutions here but haven't had any luck so far. I am currently learning HTML and while working on a simple login feature, I have run into some issues. I am using XML as a makeshift "database" and PHP to retrieve the informati ...

reason behind text styling: thick 12 pixels height with line spacing of 25 pixels using "Arial" font

Question about CSS Size: Understanding font sizes in CSS {font: 14px/24px Arial, Helvetica, sans-serif} I've noticed some CSS code like this on the website .selector {font: bold 12px/25px "Arial";} I know that 'bold' refers to font w ...

Creating a table with a static first column and vertical text positioned to the left of the fixed column

To create a table with the first column fixed, refer to this fiddle link: http://jsfiddle.net/Yw679/6/. You also need a vertical text to be positioned to the left of the fixed column in a way that it remains fixed like the first column. The disparities be ...

The challenges of positioning HTML li elements in a floating layout

Check out my website: . I'm having an issue with the layout where two <li> elements are stacked on top of each other and one is floating next to them, but it's only floating next to the second one. How can I make it float next to the first ...

Guide to inserting text into an html element upon clicking an ASP:Button

In my code, there is a DIV that holds some text. Accompanying the text is an asp:Button. When this button is clicked, I aim to access and save this particular text. Nonetheless, it seems that once the button is clicked, the content of the DIV resets - lik ...

What is the best method to dynamically assign a class to a TD element in a data table when adding

I am looking to apply a class to the td element when receiving data from an ajax call Here is the default HTML code snippet <tr> <td>@fisrt.System_Code.Code</td> <td>@fisrt.System_Code. ...

Using HTML within a Material-UI Accordion component

I am attempting to display HTML content within an Accordion component. import {Accordion, AccordionDetails, AccordionSummary, Typography} from '@material-ui/core'; import { Badge } from 'reactstrap'; ... const buildAccordion = (f, i) ...

Issue with Safari div not exhibiting proper overflow functionality

I'm looking to set up a webpage with a single sidebar and content area. Here's how I envision it: <div id="mainWrapper"> <!-- Sidebar --> <div id="sidebar"> <p>Sidebar</p> <p>Sidebar< ...