Home > Mobile >  Is it possible to start the first row on second colum and end with third column in flex-box?
Is it possible to start the first row on second colum and end with third column in flex-box?

Time:10-05

Is it possible to make single 2 rows with 3 column without adding any additional elements in flex or any other suitable way?

.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 the requirement:

flex-as-column

CodePudding user response:

Solution with flexbox.

  1. Need to define in .child2 class, 3 columns. For the checkbox 40px, the main content and for button 60px.
  2. Using webkit-line-clamp: 3 to set the line limits
  3. Calculate the width with calc() for .child1 to determine the same width as the main content in .child2. And shift content with margin-left: 40px
  4. For easy to use, we use css variables

CodePudding user response:

this is really hard with flexbox as it's not really designed for this. my favorite flexbox helper: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

You're much better off using grid for this: 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>

Dirty design but does what you want

CodePudding user response:

HTML :

<!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:

.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: Picture

  • Related