Setting the size of a box using CSS in HTML pages

I am facing issues with resizing boxes. Below is the code snippet:

<!DOCTYPE html>
<html lang="en">
  <head>
    <style>
      .wrapper { 
        text-align: center; 
      } 
      #bubble { 
        display: inline; 
        -moz-border-radius: 15px;
        border-radius: 15px;
        margin: 5px;
        width: 100px; 
        height: 100px; 
        position: relative; 
        border: solid;
        border-width: 1px; 
        background-color: #999999;
        font-name: arial;
      }
    </style>

  </head>
  <body>
    <div class="wrapper"> 
      <div id="bubble">Box 6</div> 
      <br clear="all"> 
      <div id="bubble">Box 5</div> 
      <div id="bubble">Box 5</div> 
    </div>

  </body>
</html>

The issue I am facing is that despite specifying 100px x 100px size for the boxes in the style, Chrome displays them as 42px x 19px.

There might be a simple solution that I seem to have overlooked. -.-°

I appreciate any assistance provided. Thank you.

Answer №1

  1. Avoid using the same id for multiple elements, consider using classes instead.
  2. To ensure width/height properties work correctly, switch your display to inline-block or block.

I hope this information proves helpful.

 .box { 
    text-align: center; 
} 

.bubble { 
    display: inline-block; 
    -moz-border-radius: 15px;
    border-radius: 15px;
    margin: 5px;
    width: 100px; 
    height: 100px; 
    position: relative; 
    border: solid;
    border-width: 1px; 
    background-color: #999999;
    font-family: arial;
}

Click here for a demonstration on JSFIDDLE.

Answer №2

Switch out this

display: inline;

for this

display: inline-block;

Check out the demonstration here.

Answer №3

To achieve the desired dimensions, adjust the #bubble's display property to inline-block. This will transform it into a block element and ensure it receives the specified size.

Answer №4

Here is a suggestion to consider:

#bubble { 
    display: inline-block; 
    vertical-align: top;
    -moz-border-radius: 15px;
    border-radius: 15px;
    margin: 5px;
    width: 100px; 
    height: 100px; 
    position: relative; 
    border: solid;
    border-width: 1px; 
    background-color: #999999;
    font-name: arial;
  }

For further reference, you can view the codepen example

Answer №5

Swap out display:inline; with display:inline-block;

To make it 100x100px, you can also use:

 *, *:before, *:after {
  -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
 }

http://jsfiddle.net/mBBJM/4553/

Upon inspecting each circle, you will notice they are indeed 100px x 100px.

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

Changing the element tag and flipping escape characters in html entities

My control over the string source is limited, as I can only use html(). However, I am in need of cleaning up the chaos within the source, The goal is to remove all instances of <div class="page"></div>, while retaining its content. The challen ...

Iterating through styles in a selector's attribute

I am creating a site map layout. Looking for a solution similar to this: ul.site-map li[data-level="1"] { margin-left: 50px; } ul.site-map li[data-level="2"] { margin-left: 100px; } ul.site-map li[data-level="3"] { margin-left: 150px; } This code ...

What is the reason behind getComputedStyle having visibility set to visible?

What is the reason behind getComputedStyle always returning element visibility as visible even when no explicit visibility has been set? For instance: getComputedStyle($('#block1')[0],null).visibility; --- "visible" Meanwhile: $('#block1&a ...

Tips on assigning a value to a dynamically generated drop-down element

I used arrays of strings to populate drop-down menus. Is there a way to automatically set the value of each option to match the text content? el.value = opt; seems to be ineffective. var validCoursesKeys = ['opt 1','opt 2','opt ...

Reducing the amount of text displayed on ion-text to a minimum

HTML: <ion-list *ngFor="let message of messages"> <ion-item lines="none" type="button" button="true"> <ion-grid> <ion-row> <ion-col class="message"> <ion-text> ...

Skipping a JSON field in HTML/JavaScript when it is blank: A guide for developers

To develop an interactive program based on JSON input, I aim to display headers, subheaders, and choices derived from the JSON data. Some input fields may remain unfilled. For instance: Header Subheader Choice 1 Choice 2 Subheader2 Choice ...

Troubleshooting Dynamic Input Issue - Incorrect Appending Behaviour - Image Attached

I am working on a project that involves adding input fields dynamically using JavaScript. However, I've encountered an issue where the styling of the first input field is not applied correctly when it is clicked for the first time. You can see the dif ...

When an absolute positioned element exceeds the right border of its relative parent, its width will be truncated

When position: absolute; divs are placed inside or around a position: relative; parent, their height and width are based on the size and length of the text they contain. However, if one of these divs extends beyond the right border of the relative parent, ...

Generate a JSON array containing objects consisting of a combination of string and boolean values

My goal is to generate a list containing objects with names and boolean values by utilizing AJAX. This process is initiated in the following manner: $('.si-accordion').click(function () { $(this).siblings('.accordion_tab&apo ...

Struggling to implement a vertical scroll bar within a nested div element

Struggling to make a scroll bar appear in the box-content div, even after adding 'overflow-y:auto'. My specific requirements are: The entire layout should adjust according to the browser height. This is why I've set #wrap { ... height: 50 ...

Capture line breaks from textarea in a JavaScript variable with the use of PHP

I need help with handling line breaks in text content from a textarea. Currently, I am using PHP to assign the textarea content to a Javascript variable like this: var textareaContent = '<?php echo trim( $_POST['textarea'] ) ?>'; ...

"Create a New Browser Tab When User Interacts with a Hyperlink leading to an External Website

I am currently working on a recommendations app built with React and I want to enable users to navigate to external websites when they click on a component that displays information about that website. At the moment, I have implemented a wrapper that, upo ...

Text in various styles is layered on top of an image, ensuring that text in one style does not overlap text in another style

Struggling with placing text over an image? Trying to achieve different text styles but ending up with overlapping lines? Here's a snippet of HTML that works with only one text style: <li style="" class="portfolio-content-CV"> <div class ...

How can I show a div beneath a row in an HTML table?

Check out the code snippet below: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <style type="text/cs ...

What is the best method to extract individual data values from ul li tags using PHP?

As I navigate through a page filled with HTML codes, I stumble upon snippets like this: <ul class ='trainList'> <li> <div class="smallFont farelist no-discount "> <div class="train-no">ABC 701</div> ...

Transitioning smoothly between different backgrounds will be like changing the cursor color

As I work on my website, I encounter the need for a cursor that smoothly changes its color. Specifically, I want the cursor to appear blue (#0059ff) when hovering over a white background and white when over a blue background, with a seamless transition lik ...

Populating a div with letter-spacing

I'm facing a challenge in populating a div with text using letter-spacing. The issue at hand is that I am unsure of the width of the div. Initially, my thoughts leaned towards using text-align= justify, however, I found myself lost in the maze withou ...

Moving elements using CSS

Hi, I've been facing this issue with my web development since the start. Whenever I zoom in, the container also moves along. Is there any way to fix this problem? .darkslidecont{ width: 200px; height: 50px; position: relative; bac ...

What is the best way to use margin-top and margin-bottom in CSS?

Looking to perfectly center this modal in the middle of the screen with some margin all around. However, struggling to apply margin specifically to the top and bottom! export function Modal() { return ( <div className="fixed inset-0 z-[60] ...

I cannot seem to get the image to display properly, it keeps getting cut off and

I am trying to add an image to my website: https://i.sstatic.net/giAdT.jpg However, when I try to do this, the full image is not showing: https://i.sstatic.net/VRBlB.png This is the code I am using: <!DOCTYPE html> <html lang="en"> ...