Creating a dynamic container with a square element and text inside: Steps to achieve a responsive design

In the code below, I am creating a responsive 'rectangle' and 'square', along with making the text inside the p tag responsive.

#rectangle
{
    display: flex;
    width: 500px;
    height: 150px;
    background-color: brown;
}
#square
{
    width: 300px;
    height: 130px;
    background-color: chocolate;
    margin: 10px;
}
<div id="rectangle">
   <div id="square">

   </div>

   <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente fugiat illo 
      dolorum assumenda commodi!
   </p>
</div>

Answer №1

To make the container sizes more responsive, consider using percentages instead of fixed pixels. Additionally, you can enhance the text styling by defining a font size in relation to the viewport width (vw). Here's an example:

<div id="cont">
  <div id="box">

  </div>
  <p id='message'>
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo, fuga! Architecto voluptatum laborum asperiores quas.
  </p>
</div>
#cont
{
    background-color: olive;
    display: flex;
    height: 10%;
    position: relative;
    width: 15%;
}
#box
{
    background-color: coral;
    height: 8%;
    margin: 5px;
    position: relative;
    width: 12%;
}
#message
{
    font-size: 3vw;
}

Answer №2

Here is a solution for you. To ensure responsiveness, utilize percentages (%) or viewport units (vh / vw)

#rectangle
{
    display: flex;
    width: 70vw;
    height: 40vh;
    background-color: brown;
    font-size: 2.3vw;
}
#square
{
    width: 100%;
    height: 100%;
    background-color: chocolate;
    margin-right: 3%;
     display: flex;
  align-items: center;
  justify-content: center;
}

.arrow-up {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 0; 
  height: 0; 
  border-left: 10vw solid transparent;
  border-right: 10vw solid transparent;
  border-bottom: 10vw solid black;
}
<div id="rectangle">
   <div id="square">
    <div class="arrow-up"></div>
   </div>

   <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aut, iusto. Sapiente fugiat illo 
      dolorum assumenda commodi!
   </p>
</div>

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

Transferring information between HTML pages using JSON and jQuery

After reviewing the topics, I was unable to find a complete answer. My objective is to populate a drop-down menu with text from another HTML file. Both HTML files are located on localhost. It is mandatory for the data to be in JSON format. Initially, I a ...

Facebook is failing to detect any meta tags in the header of my React web application

After checking my code on https://validator.w3.org/, everything seems fine. However, I noticed that Facebook is not reading most of the content from the head section - not even a single meta tag. On the other hand, Google is able to read all the content fr ...

Is it possible to pass multiple IDs into document.getElementById?

I am working on a form that contains 45 dropdown lists and currently, I am using the following code for validation. Is there a way to modify this code so that I can use a single function to validate all 45 dropdown lists? Below is the Function: function ...

Remove an item from an Ionic list

I am currently in the process of developing an Ionic to-do list application. I am facing an issue with the delete function where the delete button is not working as expected. When the button is clicked, nothing happens. HTML: <ion-view view-title="To ...

Guide on updating a table with query parameters in Html Agility Pack using C#

Struggling with parsing this URL using the Html Agility Pack: " The default table that shows up is always based on the closest contract date and the current date. I can parse the entire page without any issues, but when I try to request a different date ...

Having trouble adjusting the width of a Material-UI modal in React?

I'm having trouble adjusting the width of the dialog box to show all of the content without adding a horizontal scroll bar. I noticed that the blur effect is applied to most of the page, so why isn't the form extending with it? Any assistance on ...

Implementing a delegator with ExtJS 4.1: A step-by-step guide

As a newcomer to javascript, I've recently been tasked with maintaining an application built in Sencha ExtJS 4. One of the components I need to modify is a tooltip feature that displays information when hovering over certain elements. This tooltip app ...

What could be the reason behind the disappearance of text from the previously highlighted button in my calculator's "button grid" when I change the highlighted button?

Currently, I am in the midst of creating a tip calculator with a grid consisting of various percentage buttons. My main objective is to change the font and background color when any tip button is selected. Nevertheless, an issue has surfaced - whenever I h ...

Guide to transferring a Django text field to an HTML attribute and accessing it with JavaScript

Looking to transfer a caption from a Django template to JavaScript for an image? Below is the relevant portion of the HTML code: <ul id="portfolio"> {% for picture in gallery_selected.photo_set.all %} <li><img src={{ picture.path }} a ...

What is the best way to position my Jchartfx area graph below my gridview?

When my page loads, the graph appears like this. It consistently shows up in the top left corner even though it should be positioned underneath the grid view as intended. var chart1; function createGraph(mpy) { if (mpy == undefined) mpy = 12.00; ch ...

The form is not being submitted due to issues with JavaScript/JQuery

In the process of creating a JavaScript function that can detect links in text and trigger a JqueryUI dialog box with options like "Yes", "No", and "Cancel", I encountered an issue. While everything seemed to be functioning properly - displaying the dial ...

Experience the ultimate Safari/iOS responsive design for seamless browsing on all

I am experiencing an issue with my website. In my "toggle device" toolbar, I selected the responsive option for iPhone 7 Plus, Galaxy 8, and others. While my website looks good on some devices, it does not function as desired when opened on an iPhone (7+/ ...

Elements in Internet Explorer become unresponsive after being hidden or shown using jQuery

One issue I'm encountering is with a group of tabbed divs that I'm using jQuery hide() and show() to toggle the visibility. This method functions perfectly in most browsers, but unfortunately in Internet Explorer (IE), the hidden tabs become unre ...

"Unfortunately, the Datatables Individual Column Search feature is not compatible with the

I am currently using Datatables to showcase a large dataset with over a thousand rows in a table format. To enable users to search for specific information within each column, I have implemented the feature of individual column search. The initial setup of ...

Javascript is unable to find the ID of an HTML form

Struggling with a basic HTML form and a JavaScript form validator that aims to verify input in the "first name" field. However, I'm having trouble retrieving the first name form value to validate it properly in JS. Below is the relevant HTML code sni ...

sequential organization paired with double-column format

Looking for a CSS-only method to arrange an ordered list (ol) into two columns if it exceeds the height of its container. The number of items in the list can vary, and so can the height of the container. When attempting to set li with properties like widt ...

Issue with html2canvas image download in Firefox

I am currently using HTML2Canvas to try and download a div as an image. It works perfectly fine on Google Chrome, but I am experiencing issues with Firefox. Below is the code snippet: <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0. ...

Navigate to a specific section in an Accordion with the help of jQuery

I currently have 2 pages: page1.html, which contains a series of links, and page2.html, where an Accordion is located. The Query: I'm wondering if it's feasible to link directly to a specific section within the Accordion. For instance, if I want ...

Trouble Arising from Regional Settings in my Hybrid App Developed with CapacitorJS and Vue.js

Issue with capacitor app input Correct input in chrome app I'm facing a problem related to regional settings in my mobile application, developed using CapacitorJS and Vue.js 2. The datetime-local control is appearing in a language that isn't the ...

How can I effectively develop a versatile user interface for a website using Ruby on Rails that is compatible with all

Currently, I am in the midst of developing a web application using Ruby on Rails. Occasionally, I encounter challenges with cross-browser compatibility when it comes to CSS and Javascript. Are there any strategies you recommend to reduce these issues dur ...