What is the best way to align a div with the side of a tab when the screen width is limited?

I have created a webpage similar to a news page, and it functions perfectly on a 16:9 display. However, it faces difficulties when viewed on tabs with smaller widths. I am considering three solutions to address this issue:

  1. Adjusting the margin that holds the div away from the left side of the tab to decrease in width exponentially.
  2. Making the margin disappear under a certain width.
  3. Exploring alternatives to using margins to keep the div away from the side of the tab, and making adjustments for smaller tab widths.

While I have seen other pages successfully implement these solutions, I have been unable to find resources or examples online. I have not attempted any changes due to my limited knowledge in solving this particular problem. Here is an example of the code I have:

<html>
<body>
    <div style= "width:60%; margin-left:20%;">
    <p style="
    margin:0px;
    word-wrap:break-word;
    margin-top:0px;">Praesent semper, leo ac scelerisque 
volutpat, massa ex volutpat dui, in 
suscipit mauris neque auctor quam. 
Vestibulum vel finibus elit.</p>
    </div>
    </body>
    </html>

To illustrate the issue, when the page is scaled down to around 1000px width, the excessive empty space becomes evident. Thus, I seek to eliminate the margin entirely and set the width to 100%. Additionally, I want to explore options beyond using margins.

In one attempt, I tried the following code:

<html>
<body>
    <div style= "width:60%;  margin: 0 auto; min-width:500px">
    <p style="
    margin:0px;
    word-wrap:break-word;
    margin-top:0px;">Praesent semper, leo ac scelerisque 
volutpat, massa ex volutpat dui, in 
suscipit mauris neque auctor quam. 
Vestibulum vel finibus elit.</p>
    </div>
    </body>
    </html>    

Despite some improvements like removing margins and hiding empty parts under a specific threshold, this method still requires horizontal scrolling on smaller screens.

Eventually, I received assistance from various individuals across different platforms and successfully resolved the issue using flexbox. I am grateful for the helpful input provided.

Answer №1

It would be beneficial for you to delve deeper into flex-box

div {
  display: flex;
  flex-flow: flex-start;
  width: 100%;
}
div p {
  flex: 1;
}

If this solution does not align with your initial query, consider revising the question

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

What are some ways to expand the width of a textarea without altering the surrounding div element

Is there a way to resize a textarea using Pure CSS without affecting the structure of the table: Heading: <div class="pure-u-1 pure-u-md-1-8"> <label class="boldText">Nmbr</label> </div> <div class="pure-u-1 pure-u-md-2-5"> ...

How to position a div in the center on top of a full-width slideshow using CSS

I am facing a challenge with positioning the banner slideshow controls div in the middle of the screen on top of a full-width slideshow. The main container's width is set to 100%, which is causing issues with centering the controls div. I have attemp ...

Interacting with a button element specified with the role attribute inside a div container using Selenium

Is there a way to interact with the button using the HTML tag provided below? <div class="_1WZqU PNlAR" role="button">OK</div> I attempted the following methods: driver.findElement(By.xpath("//button[text()='OK']")).click(); driver ...

Styling chat messages from users using Javascript

Using Python, I've developed a websocket server for a web chat feature. The chat box, where user messages are displayed, is sized at 83px in height and 1176px in width. Instead of the traditional vertical list display of messages, I want to show user ...

Adjusting the URL variable based on the selected checkbox option

My mobile website offers users the option of a bright or dark interface using a checkbox styled like an iPhone IOS7 switch. The functionality is working as expected, but I'm now facing an issue with passing the status of the checkbox between pages. I ...

Is there a discrepancy in height between Chrome's mobile emulator and the iPhone simulator?

Currently, I am conducting a layout test for a PhoneGap application using the Framework7 framework across the Chrome mobile emulator (iPhone 6) and Xcode iOS simulator. However, I am facing difficulties with aligning the vertical layout on both simulators. ...

Changing results in a 1px movement of the image

Despite referencing this specific discussion thread, I still couldn't resolve the issue in my case (unless I placed the suggested code incorrectly). Essentially, when hovering over a link in Firefox, some images underneath shift by 1px (not all of th ...

Having trouble dividing an HTML file?

Currently, I am working on creating a very basic web page that is divided into two parts. Each part will have its own HTML file: Welcome.html & Welcome.css: <html> <head> <link rel="stylesheet" type="text/css" href="Welcom ...

A guide on utilizing radio buttons to delete specific rows within a table with the help of AngularJS

My current issue involves using radio buttons to delete rows in a table. The problem I'm encountering is that multiple rows are being deleted at once instead of just one. You can view an image of my table here. As we all know, with radio buttons, onl ...

How to Use CSS to Crop a String from the Middle

My file has a long name and I am using CSS text-overflow: ellipsis to crop it. <style> #fileName { width: 100px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } </style> <div id="fileName"> ...

transmitting data for COVID tracking page built in Django

I need help creating a Covid tracker page using Django. I have set up the HTML framework with Bootstrap, but I'm struggling to fetch and display the Covid data on my page. I know how to retrieve the data using the request module, but I'm unsure o ...

Prevent the transfer of data from webpage

Is there a way to prevent users from copying content on a web page? I want to ensure that no text can be selected by the user. I am currently working on asp.net and would appreciate any creative ideas or solutions. ...

Navigating origin policy using a RESTful API

Is there an effective way to bypass the same domain origin policy using a RESTful API? For example, can I utilize a URL like and then implement a JavaScript function to retrieve the source of ? function datareceived(googlesource){ alert(googlesource ...

If the SASS condition matches the variable for the background color, then

I attempted to create a conditional statement in my component using Sass @if and @else. The condition I set was that if background == var(--bg-danger), the color should be white. However, it only returned white and did not trigger the else condition. @mixi ...

What is causing the elements to not fill the entire width of the page?

How can I make 6 flex items have the same width and occupy the full width with minimal margins between them? Currently, there is too much margin, especially on larger screens. Any suggestions on how to achieve this without excess spacing? Thanks! Example: ...

Stay tuned for updates on elements being loaded into a div from an external source

I have a project in progress that involves integrating HTML and JQuery. One of the tasks is to replace a div with a new one from an external HTML file using the load('some.html #someDiv') method. Everything was going smoothly until I tried to li ...

Is there a way to design a form that appears as though it's levitating above a div element?

I am new to web development and currently practicing by converting PSD designs into HTML pages. I am facing an issue where I need to create a form that appears to be floating on top of a div, with the form being taller than the div itself. Here is an illu ...

SQL query returns a surprising outcome

Below is the table content (mTable) id | sent | number --------------------------------------- 23 | 2017-03-02 00:00:00 | 0 23 | 2017-03-04 00:00:00 | 0 45 | 2017-03-15 00:00:00 | 1.8 45 | 2017-03-17 00:00:00 | 1.9 id: i ...

Utilizing document.write to switch up the content on the page

Every time I attempt to utilize document.write, it ends up replacing the current HTML page content. For instance, consider this HTML code: <body> <div> <h1>Hello</h1> </div> and this jQuery code: var notif = document. ...

Determine the possible width of a concealed element

I am currently customizing the lavalamp plugin to be compatible with dropdown menus, but I have come across a minor issue. I am trying to determine the offsetWidth of a hidden element. Obviously, this question is a bit nonsensical. What I actually need is ...