How to prevent child elements from overlapping the max-width of their parent in HTML using flexbox [screenshot provided]

Can someone help me create this CSS layout? The parent div has a max-width of 1500px, uses display flex, and has a gap of 18px. It contains two children with IDs #text and #news... the news child is designed to overlap and touch the right edge of any screen size.

https://i.sstatic.net/ZxNHp.png

html{
 border:1px solid red;
}
html:after{
content:"HTML";
color:gray;
}
.main{
 display:flex;
 flex-flow:row;
 max-width:350px;
 color:black;
}

.main .child-1 {
 flex: 1 1 40%;
 border:1px solid #000
}

.main .child-2 {
  flex: 1 1 100vw;
  border:1px solid #000;
}

.main ul p {
 display:block;
 width 250px; // Whatever
}

ul{
 list-style:none;
 display:flex;
}
<div class="main">
   <p class="child-1">Some lorem Text</p>
   <div class="child-2">
     <ul>
       <li><p>1</p></li>
       <li><p>2</p></li>
       <li><p>3</p></li>
       <li><p>4</p></li>
     </ul>
   </div>
</div>

Answer №1

utilizing negative margin can help you accomplish the desired outcome.

div{
  border: 1px solid;
  min-height: 100px;
}
.parent{
  display: flex;
  max-width: 250px;
  padding: 20px;
  column-gap: 20px;
}
.text{
  width: 25%;
}
.news{
  width:75%;
  margin-right: -20px;
}
<div class="parent">
  <div class="text"></div>
  <div class="news"></div>
</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

``Is there a way to retrieve only a specific portion of an HTML

Greetings everyone! Here is a snippet of my sample code: <?php $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/x ...

Within the flask framework, I am experiencing an issue where paragraphs are being overwritten. My goal is to find a

Snippet of HTML: <div class="split left" > <div class="centered"> <div class="container"> <p>Hi!</p> </div> <div class="darker"> <p>{{message}}& ...

Issues with the HTML <div> tag placement in the center

I am encountering an issue while creating a basic HTML website. I want the image and white fields to fill the entire screen (100% width), but they seem to be constrained by some margin on both sides. As a beginner in web development, I believe the solution ...

What is the secret to creating double-width characters that are precisely double the size of single-width characters?

When using terminal, many fonts that support double-width characters display them as exactly twice the width of single-width characters. For instance, these two lines should appear with the same width: あああ aaaaaa However, this consistency is not ma ...

Is anyone experiencing difficulties with IOS 8.3 when trying to assign colors to Font Awesome icons using content?

I'm encountering an issue on IOS 8.3 where I click a checkbox and the arrow color should be green, but it shows up as black instead. Is there a bug fix for this in IOS or is it simply not supported? Here is my SASS/css code: input[type="checkbox"] ...

Utilizing border-image property to showcase four dots in each corner of my div container

I'm having trouble applying a gradient color to my border using the border-image property. When I use border-image: linear-gradient(-180deg, #2D6BD0 0%, #83B8FF 100%);, I'm only seeing a single dot in each corner of my DIV. Does anyone know why t ...

Centralize Checkboxes with Bootstrap

Is there a way to center the checkbox input both vertically and horizontally within its parent column? The image below illustrates the parent column and checkbox. I have attempted using classes like text-centered, d-flex justify-content-center, and align- ...

Hover effect not functioning as expected on Mobile Safari

Looking to create a hover effect for images on an HTML website. The idea is to have the image shade and display details when hovered over. Here is the CSS code: /* Hover overs */ .folio4:hover .face { opacity:1; cursor: pointer; } ...

Function for masking phone numbers is adding additional "x's" to the input field

My phone number formatting script is supposed to add dashes after the third and sixth characters, as well as insert an "x" after the 10th character for extensions. However, it is adding extra "x's" after the 12th character, resulting in the incorrect ...

When my webpage is opened in Firefox, I notice that it automatically scrolls down upon loading

I recently embarked on the task of building a website from scratch but ran into an unusual bug in Firefox. The issue causes the page to scroll down to the first div, completely bypassing its margin. I want to clarify that I am not seeking a solution spe ...

Hover effect for entire div using CSS

I am presenting several boxes with a box class Check out my CSS below .box { width:100%; min-height:20px; color:#000000; font-size:16px; border:1px solid #666666; } .box a { color:#000000; font-size:16px; text-decoration:underline; } ...

Create a new CSS rule within a class, and remember to save the changes to

Upon opening page 1.html, I utilize JavaScript to dynamically add a background image to the body of the page. To achieve this, I use the following code: document.body.style.backgroundImage = "url(http://www.example.com/image.jpg)"; This code effectively ...

The process of dynamically populating data into a select element through an Ajax request using JavaScript may seem complicated at

I am working on an html page that includes two select options. The values for these select options are retrieved from a Servlet via an ajax call in the onclick() function. However, I am encountering an issue where the data is not populating into the sele ...

Ensure the central alignment of the focused item within the horizontal scroll

I have successfully implemented a horizontal scroll container using <HTML/> and CSS: body { background-color: #212121; } .scroll_container { height: 100px; width: 400px; display: flex; align-items: center; overflow-y: hidden; width: 1 ...

Numerous filter passages

How can I make an image white on hover using CSS filters and transitions? .uni-im img { filter: brightness(0) invert(1); } I have added a transition property for a smooth effect: .uni-im img { filter: brightness(0) invert(1); transition: fil ...

Enable the contenteditable attribute on a div element to allow for both valid and invalid states

Is it possible to implement the required attribute on a div with contentEditable="true"? I am looking for a way to ensure that the field has both valid and invalid states. ...

Place an image in a div so that it is centered both vertically and horizontally

I have been trying to center an image both horizontally and vertically, but it seems like my code is not working properly. Here is what I have so far: #parent { position: relative; float: left; width: 700px; height: 400px; overflow: hi ...

Exploring the Uses of JQuery Functions

The functions below are working as expected, but when I try to include the custom functions next() and prev(), something is off with the script. Where could the issue be stemming from? function next() { $('#up').click(function() { ...

Display or conceal the grid template row for content that is empty or if the grid area is not displaying

display: grid; grid-template-columns: var(--side-bar-width) 1fr; grid-template-rows: 60px 1fr 90px; gap: 0px 0px; grid-template-areas: "Sidebar Header" "Sidebar Body" "Player Player"; I ...

I only notice certain text after carefully inspecting the elements in Google Chrome

While creating an application on Sitefinity (ASP.NET), I encountered an issue where certain elements, such as button text and labels, were not loading correctly when running the application. However, upon inspecting the element, they appeared to be working ...