Can the first row of a flex-box begin in the second column and end in the third column?

Can a layout be created with two rows and three columns without adding any extra elements using the flex property or any other method?

.parent{
display:flex;
flex-direction:column;
}

.child1{
  background:lightblue;
}

.child2{
display:flex;
border:1px solid red;
}

.child2 div{
flex:1;
background:green;
}
<div class="parent">
 <div class="child1">it should start in 2nd column and end with 3 column</div>
 <div class="child2">
  <input type="checkbox" />
  <div>some test goes here </div>
  <button>button 2</button>
 </div>
</div>

Here is what is needed:

https://i.sstatic.net/IELvO.jpg

Answer №1

Approach utilizing flexbox.

  1. Define 3 columns in the .child2 class: 40px for the checkbox, the main content, and 60px for the button.
  2. Implement webkit-line-clamp: 3 to set line limits.
  3. Utilize calc() to calculate the width of .child1 so it matches the main content width in .child2. Adjust content alignment with margin-left: 40px.
  4. Make use of CSS variables for ease of adjustment.

*,
::after,
::before {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

:root {
  --input-width: 40px;
  --button-width: 60px;
}

body {
  display: grid;
  place-items: center;
  background-color: hsl(215, 100%, 98%);
  position: relative;
  overflow-x: hidden;
}

.parent {
  max-width: 400px;
  display: flex;
  flex-direction: column;
}

.child1 {
  width: calc(100% - var(--input-width) - var(--button-width));
  display: flex;
  padding: 0.5em 0;
  margin-left: var(--input-width);
  color: gray;
}

.child2 {
  display: flex;
}

.child2 input {
  flex: 1 0 var(--input-width);
}

.child2 div {
  flex: 0 1 auto;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.child2 button {
  flex: 1 0 var(--button-width);
}
<div class="parent">
  <div class="child1">23-Oct-2019, 8:00 AM</div>
  <div class="child2">
    <input type="checkbox" />
    <div>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. A optio quod recusandae cupiditate, dolores consectetur nihil veritatis doloremque nam, maxime itaque omnis? Voluptatem ratione consequuntur animi aliquam expedita eos alias. Ipsum consequuntur
      laborum ipsa labore autem accusamus mollitia minima placeat harum, odio explicabo eaque aliquam adipisci consectetur delectus praesentium nemo. Odio eos ex, autem quam alias molestias ab quae temporibus.
    </div>
    <button>button 2</button>
  </div>
</div>

Answer №2

Implementing this layout with flexbox can be quite challenging as it is not its primary use. A helpful resource for flexbox is available at: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

For a more suitable approach, consider utilizing grid instead: https://css-tricks.com/snippets/css/complete-guide-grid/

.parent {
  display: grid ;
  grid-template-columns: 1fr 4fr 2fr;
  grid-template-rows: 1fr 3fr
}

.child1 {
  background: lightblue;
}

.child2 {
  border: 1px solid red;
  background: green;
}
<div class="parent">
  <div class="item"></div>
  <div class="item child1">it should start in 2nd column and end with 3 column</div>
  <div class="item"></div>
  <div class="item child2">
    <input type="checkbox" />
  </div>
  <div class="item">some test goes here </div>
  <button class="item">button 2</button>
</div>

This design may not be perfect, but it achieves the desired outcome

Answer №3

HTML Code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

  <div class="date">
    23-October 2019 , 8:00 AM
  </div>

<div class="input">
<input type="checkbox">
</div>

<div class="text"> 
  Lorem ipsum dolor sit amet, consecte <br> tur adpiscinc elit, sed do eiusmod te <br> sed 
  do eiusmod te sed do...
  
</div>

<div class="final">
  Service : Platform Service
</div>



</body>
</html>

CSS Styles:

.date{
  font-size: small;
  padding-top: 5px;
  padding-bottom: 10px;
  padding-left: 37px;   
}

.input{
  margin-left: 8px;
  float: left;
}

.text{
  display: inline-block;
  padding-left: 10px;
}

.final{
display: block;
padding-left: 37px;
padding-top: 10px;;
}

Final Output: View Image

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

Struggling with integrating HTML Canvas within Vue.js

Currently, I am attempting to upload an image by utilizing HTML canvas. My decision to use canvas stems from the fact that I will be superimposing additional images based on the data received from the API, and this process seems more straightforward when u ...

What steps should I take to get my fixed position to function properly in Internet Explorer 6?

I've attempted the following to solve my issue: body {height: 100%;overflow: auto; body #cornerImage {position: absolute;bottom: 0;} I also tried this solution: { margin:0; padding:0; } html, body { height: 100%; overflow:auto; } body #fixe ...

Addressing Layout Problems When I Enlarge the Browser Width

My website is www.adventureswithross.com When the device width is larger than 601px, I have specific requirements: I need the menu and custom header to be seamlessly connected without any spacing in between. To address the issue of space above the custo ...

After incorporating an additional element, the li:nth-child(odd) selector is no longer functioning correctly

I previously had a setup where items in a list would have alternate colors using jQuery: $('ul.follows li:nth-child(odd)').addClass('alternate'); Everything was functioning properly until I introduced an a tag before the list items. N ...

The eot file converted online is not functioning as expected

I have tried converting the 'Helvetica Neue Bold' ttf to eot online, but unfortunately it does not seem to work in IE8 and below. The font face I used is as follows: @font-face { font-family: 'HelveticaNeueBold'; src: url(&apo ...

Unusual display of fonts on Chrome

Recently, I encountered a strange issue with font rendering on Chrome/Opera compared to Firefox. The problem can be seen in the preview below - pay attention to the pink text. It appears blurry initially but sharpens once text input is focused. This same i ...

Transmitting HTML through a Java socket connection

I am facing an issue where I am attempting to send the code from 'index.html' using Java socket wrapped in BufferedWriter. However, when I try to connect to 'localhost:port' in a browser, I encounter different results: text output (&l ...

Guide to sending multiple checkboxes using jQuery AJAX in CodeIgniter

I'm encountering an issue with my code when I click the 'Simpan' button, the response in the URL is: Output in URL: localhost/rootappl/moduls/krs myCheckboxes%5B%5D=KFT106&myCheckboxes%5B%5D=KFT107&submit=Simpan HTML CODE: [IMG] ...

Is it possible for me to use AJAX to load content from a string? I am attempting to postpone the activation of certain HTML

I need help optimizing my HTML page that includes certain sections with large Javascript files and images, which are initially hidden. Even when set to "display: none," the browser still loads all the content. One solution could be moving those sections in ...

Hosting services and content management system for a website built with Twitter Bootstrap

Embarking on a new venture to create a website for a Custom Home Building company, I am eager to learn and grow in web development. Although I have some programming experience, please bear with me as I ask my newbie questions. I have been searching high a ...

Show a different image with a matching title each time the page loads

I need help creating a JavaScript script that will display a random image from an array along with an associated title each time the page loads. Is there a way to do this without using an onload function placed in the body tag? Currently, my code relies o ...

Css styling for text highlighting

It's been some time since I encountered a CSS problem, but here I am facing one. In short, I want to highlight text with a gradient background, which I managed to achieve using the <span> tag and setting a background image on it. However, I ran ...

Retrieve a time stamp value from a database and showcase it using jQuery

My database query is retrieving the timestamp of when an item was entered, which I am then echoing back to my main page using PHP. The timestamp is in the format YYYY-MM-DD HH:MM:SS:MS and is displayed correctly in an HTML table. However, when I click on a ...

The Javascript function is designed to function exclusively with onclick events or setTimeout functions

I am currently working on a website that I want to be responsive to the window size. However, I am facing an issue with vertical alignment. I have created a jQuery function to handle this, and it works well for divs with images but not so well for a div wi ...

Utilizing Jquery to Integrate Hashtags

I'm looking to implement a feature where any text I write starting with a # symbol automatically changes color to blue, and then returns to black once I hit the space key to end the text. I attempted to achieve this using the following logic within a ...

Is there a substitute for bootstrap select in Rails?

In order to style select tags with Bootstrap, we had to utilize the gem: bootstrap-select However, due to the high volume of options in our data-heavy application, the select dropdowns are causing significant slowdown (loading times, drop down performance ...

Creating unique ID tags using AngularJS

I am struggling with creating an HTML structure that looks like this: <ul> <li id="r1_1">Root node 1 <ul> <li id="child_node_1">Child node 1</li> <li id="child_node_2">Child node 2</ ...

Guiding motion of a parental container using a button

This seems like a fairly straightforward task, but I'm getting a bit frustrated with it. Is there a way to move an entire div by simply holding down the mouse button on a particular button? let container = document.getElementById('abo ...

CSS Positioning: the container is not the right size for its content dimensions

Code Snippet: <div content> <div post> <div post> ... </div> Styling: .post { margin: 0; padding: 110px 20px 20px; float: left; width: 560px; position: relative; display: block; } #content { display ...

The Angular HTML Autocomplete feature is not functioning as intended when hosted on a CDN in Chrome, despite setting it to "nope" or "off"

When setting Autocomplete to "nope" or "off" in my input box for surname, I'm still able to select from the autocomplete list. This issue occurs when accessing our Ui app through CDN at link [https:// Xyz. net], but works correctly when accessing it d ...