<container> rectangular form

.products
{
  width: 100%;
  height: 500px;
  background: gray;
}

.box
{
  width: 250px;
  height: 300px;
  background: darksalmon;
  border: 1px solid #000;
}
<div class="products">
  <div class="box">
    <p>Ola</p>
  </div>
</div>

My objective is to enclose the paragraph within a square. However, the current code displays both divs together and only shows the content inside the paragraph.

The desired layout is illustrated in the following image:

Answer №1

.items
{position:relative;
  width: 100%;
  height: 500px;
  background: gray;
}

.container
{p
  width: 250px;
  height: 300px;
  background: darksalmon;
  border: 1px solid #000;
}
<div class="items">

    <p>Hello</p>
  </div>
  <div class="container">
</div>

Answer №2

give this a shot...

background-color: ;
    width: 500px;
    border: 30px solid teal;
    padding: 30px;
    margin: 30px;

Answer №3

Have you attempted

<p class="container">...</p>

deleting the div enveloping your text block?

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

Elements in Motion

Working on a parallax effect, I've managed to assign unique scroll speeds to (almost) every element. Moreover, these elements are programmed not to activate their scroll speed until they enter the viewport. Below is the JavaScript code for trigger co ...

Is there a way to create a fixed container aligned to the right and have the parent container handle scrolling?

My setup is as follows: Full width, 100px height header The header is always visible at the top. Full width, remaining height details The content of details can scroll vertically and horizontally. A fixed 200px width, full height container is right- ...

Determining height of an element in AngularJS directive prior to rendering the view

As I dive into the world of Angular, any assistance is greatly welcomed. My goal is to vertically align a div based on screen size (excluding the header and footer) when the page loads, the window resizes, and during a custom event triggered by the user ex ...

Best practices for arranging several divs with CSS

I am in the process of creating a main header for several web pages I'm working on. The layout I have in mind includes an image, centered text below the image (all to the left of the main header), a main header that I want to be in the center of the p ...

How to place a div within another div without using absolute positioning

I've been searching for a solution to this issue, but nothing seems to be working. I want the inner div to be positioned at the bottom of the outer div, with a 5px margin separating them. However, using absolute positioning disrupts the width and cent ...

Why are my indents disappearing when I save in VS Code?

Just starting out with HTML and running into an issue where my indents keep disappearing whenever I save. Here's an example of what's happening. Before saving: After saving: I've experimented with different formatting tools and double-che ...

Using XSLT to convert HTML into the desired text format

It has been almost two decades since my last encounter with XSLT. I am attempting to transform documents, like the HTML snippet below, into the desired output. <p> おばあさんは、とても <ruby><rb>喜</rb><rp>(</rp ...

Can someone explain why my button icons are not aligning to the center properly?

I have a small issue with the icons I pulled from react-icons - they appear slightly raised within the buttons. How can I position them in the middle? That's my only query, but I can't post it alone due to mostly having code in my post. What an ...

Trouble arises with the jQuery keydown function

Currently, I am encountering an issue with a straightforward jQuery code implementation. In addition to the problem description, I have included the HTML structure below, The current functionality works as expected in setting focus on the input field upo ...

align text vertically over an image

I've come across this question many times, but none of the answers seem to solve my issue. My challenge is centered around aligning text on an image with regards to vertical positioning. Below is the code I'm working with: <div class="col-sm- ...

What is the best way to center a parent container vertically?

I currently have a main grid with grid items that are also containers, set as inline-sized containers to allow for different internal layouts based on their width. How can I horizontally align the main grid in the center once it exceeds a certain width? A ...

Internet Explorer 7 has been selected, a dropdown menu appearing over another dropdown

Hey everyone, I could really use some help with this issue. I'm currently working with chosen.js and I'm having some trouble with dropdowns. Please take a look at this picture for reference: problem with dropdowns Below is the HTML code I'm ...

What steps do I need to take in order to change an HTML div's background to a black

My current project involves dynamically loading HTML content stored on disk into a specific div element. This is achieved by using the following code: $('#FictionContent').load('Content/HuckFinn.html'); Just to provide some background ...

When enlarging or extending the container, text starts to spill out

My issue is that the text content is overflowing the designated box or container - any ideas on how to fix this problem? I have attempted to utilize max-width and max-height, but unfortunately, I am unable to get them to function as intended. Here's ...

Make the image take up the entire screen in HTML

My goal is to display an image that fills the entire screen. Here's how my HTML code looks: <!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8" /> <title></title> </head> ...

What is the best way to ensure a div element on a printed page has a space between its bottom edge and the physical paper, as well as a space between its top

Within my div element lies a collection of other div elements. These elements contain lengthy text that may span multiple pages. I am attempting to print this text starting 50mm from the top edge of every physical paper, and stopping 20mm before the edge o ...

Influence of scoped styles on external webpages

I'm facing an issue with my nuxt app where I have two pages, each with different background styles. However, the background of one page is overriding the other. index.vue <style scoped> body { background-color: #ffffff; } #banner { backgr ...

Could you please advise me on where I should apply line-height in order for it to work properly?

My div is structured like this: https://i.sstatic.net/3fUNs.png I am trying to decrease the spacing between the lines. I attempted adding a line-height attribute to both the parent div and one of the label elements like this: <div class="row" ...

Every time I try to load the webpage with the Django ModelForm, I keep encountering the "This field is required" error

I created a model named Announcement in my models.py file and also the corresponding form in forms.py. Next, I implemented a simple create view for it in my views.py and displayed it on the frontend using the django-crispy-forms package. However, every tim ...

The website shifts as you navigate to a new page

Could use some insight on an issue with my website . Whenever I navigate to a different page, like the "Rules" page from the main site, the container seems to shift down slightly. Any ideas on what could be causing this? I've been struggling to pinpoi ...