So I need to display a box (position absolute) above my page when clicking on some button designed, inside this box will be a list of "tags" which should be displayed in a row.
But my problem is that I cannot manage to make the tags wrap properly, taking the maximum space of the box. I want to display as many tags as possible in a single row.
Any idea if this is possible ?
https://jsfiddle.net/e18d2ajh/
.vectors {
display: inline-flex;
min-width: 20vw;
max-width: 50vw;
background-color: #333;
padding: 15px;
margin-bottom: 15px;
}
.vector {
display: flex;
padding: .35rem;
background-color: #c0c0c0;
margin-right: .5rem;
}
<h5>
with few boxes
</h5>
<div class="vectors">
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
</div>
<h5>
with many boxes
</h5>
<div class="vectors">
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
</div>
Use flex-wrap property to wrap contents to next line
.vectors {
...
flex-wrap: wrap;
...
}
.vectors {
display: inline-flex;
flex-wrap: wrap;
min-width: 20vw;
max-width: 50vw;
background-color: #333;
padding: 15px;
margin-bottom: 15px;
}
.vector {
display: flex;
padding: .35rem;
background-color: #c0c0c0;
margin-right: .5rem;
}
<h5>
with few boxes
</h5>
<div class="vectors">
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
</div>
<h5>
with many boxes
</h5>
<div class="vectors">
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
</div>
You need a flex-wrap: wrap for .vectors and a flex-grow: 1 for .vector so the children occupy empty space left in the row after wrapping. Note, that might look ugly for the last row, solution is using pseudo element. Summary:
.vectors {
flex-wrap: wrap;
}
.vectors::after {
content: '';
flex: 100 0 0;
}
.vector{
flex-grow: 1;
}
Here's the codepen
You could set max-width:max-content on .vectores with flex-wrap:wrap and it would do the trick, like so:
.vectors {
display: inline-flex;
min-width: 20vw;
max-width: max-content;
background-color: #333;
padding: 15px;
margin-bottom: 15px;
/* lines I added */
flex-wrap:wrap;
gap:.5rem;
}
.vector {
display: flex;
padding: .35rem;
background-color: #c0c0c0;
}
<h5>
with few boxes
</h5>
<div class="vectors">
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
</div>
<h5>
with many boxes
</h5>
<div class="vectors">
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
<div class="vector">
Random text
</div>
</div>
Related
When I resize the browser window I want the number of the columns to change while boxes are flexible with flex-wrap: no-wrap;.
So I thought it could be the solution if I add breaks after divs and disable/able some of the breaks from CSS with #media. It looks like it is impossible to add a line-break while flex-wrap: no-wrap; is active.
I am a newbie and I want to learn CSS at its best, therefore, I am trying myself with getting responsive structures in different situations.
I have tried <br> tag, space-white: pre; and preline. I've also tried setting additional parent element to display: inline-block;. But they didn't work for me. I want to do it with only HTML and CSS if possible. But it isn't a mandatory limitation.
My html and css:
* {
margin: 0;
padding: 0;
}
body{
margin-left: 15px;
margin-right: 15px;
}
.car{
display: flex;
max-width: 500px;
min-width: 200px;
height: 50px;
border: 1px solid grey;
margin: 5px 20px;
}
.carParent{
display: flex;
flex-direction: row;
width: 1300px;
border: 1px solid orange;
}
<body>
<div class="carParent">
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
<div class="car"><h3>SOME TEXT AND IMAGE</h3></div>
</div>
</body>
You have flex-wrap:wrap for that, and to make it full responsive I've improved your code.
* {
margin: 0;
padding: 0;
}
body {
margin-left: 15px;
margin-right: 15px;
}
.carParent {
display: flex;
flex-wrap: wrap;
justify-content: space-around; /* try also: space-between or center */
max-width: 1300px;
margin: auto; /* to center in screen -- optional */
border: 1px solid orange;
}
.car {
border: 1px solid grey;
margin: 5px 20px;
padding: 1em
}
<body>
<div class="carParent">
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
<div class="car">
<h3>SOME TEXT AND IMAGE</h3>
</div>
</div>
</body>
I am trying to set cards with information in columns. As the texts displayed have different lenghts, I want to fixed the possition of the Learn More button related to the end of the card, so no matter what comes before, the buttons are always aligned.
Furthermore, I want to separate the cards between rows, but I haven't been able to find a solution yet, because if I change margins it only applies in the last row.
Here is my code:
<div class="row my-flex-card">
<div class= "col-xs-4 col-sm-4 col-md-4 col-lg-4" ng-repeat="woman in women">
<!--Card-->
<div class="card">
<!--Card image-->
<img class="img-fluid" ng-src="{{woman.image_url}}" alt="{{woman.name}}">
<!--Card content-->
<div class="card-body inline-block">
<!--Title-->
<h4 class="card-title">{{woman.name}}</h4>
<!--Text-->
<p class="card-text"> <h5>{{woman.field}}</h5> <br> {{woman.job}}</p>
<a class="btn btn-success" href="#!/women/details/{{woman._id}}">Learn more</a>
</div>
</div>
<!--/.Card-->
</div>
</div>
My CSS:
.my-flex-card > div > div.card {
height: calc(100% - 15px);
margin-bottom: 15px;
}
.row {
margin-bottom: 50px;
}
That .row feature isn't working.
This is how my website looks like right now:
Thank you :)
.parent {
display: flex;
flex-direction: row;
padding: 10px;
}
.parent .child {
padding-right: 10px;
flex-grow: 1;
width: 33%;
position:relative;
}
.parent .child .content {
height: 100%;
box-shadow: 0 0 1em gray;
}
.content img{
background-size:cover;
width:100%;
}
.content h3,p{
padding:10px;
}
.content input{
position:absolute;
bottom:5px;
margin-left: 35%;
margin-top:10px;
}
<div class="parent">
<div class="child">
<div class="content">
<div>
<img src="https://www.w3schools.com/html/pic_mountain.jpg"/>
<h3> test 3</h3>
<p>text text text text text text text text text text text text text text text text text text text</p>
</div>
<div><input type="button" value="click" /></div>
</div>
</div>
<div class="child">
<div class="content">
<div>
<img src="https://www.w3schools.com/html/pic_mountain.jpg"/>
<h3> test 2</h3>
<p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text tex </p>
</div>
<div><input type="button" value="click" /></div>
</div>
</div>
<div class="child">
<div class="content">
<div>
<img src="https://www.w3schools.com/html/pic_mountain.jpg"/>
<h3> test 1</h3>
<p>text text text text text text text text text text text text tex</p>
</div>
<div><input type="button" value="click" /></div>
</div>
</div>
</div>
make the box class with position relative :
.boxClassName{
position:relative
}
then make the button class with the following :
.buttonClassName{
position:absolute;
bottom:0;
}
I am trying to wrap my head around flexbox and I have hit a wall with something very simple that I can't seem to get right.
I have 6 columns that I want all the same height with 3 on each row. I have set the flex items to have a width of 33% but I have not set a height on anything. I thought once the flex items had content it would take the one with the greatest height and match everything to it.
Here is my markup:
.container {
width: 800px;
padding: 0 15px;
}
.row-flex {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin-right: -15px;
margin-left: -15px;
flex-wrap: wrap;
}
.flexbox {
flex: 0 0 33%;
padding: 0 15px;
}
.icon-box-1 {
position: relative;
margin-bottom: 50px;
background: #fff;
text-align: center;
border: 1px solid #eee;
padding: 10px;
}
<div class="container">
<div class="row-flex">
<div class="flexbox">
<div class="icon-box-1">
<h1>
One
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Two
</h1>
<h3>Title</h3>
<p>lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Three
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Four
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Five
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Six
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
</div>
</div>
The equal height columns feature comes from align-items: stretch, which is an initial setting on a flex container. It makes flex items consume all available space in the cross axis.
If you check the actual size of each flex item, you will see that they are, in fact, equal height on each row (demo).
The problem is that the content of each item (.icon-box-1) is not stretching full height. It's just height: auto (content height), by default.
In order for the content to stretch full height, add display: flex to each flex item, so align-items: stretch goes into effect, like on the parent (demo).
Then use flex: 1 to make the content fill the remaining space on the main axis (demo).
.container {
width: 800px;
padding: 0 15px;
}
.row-flex {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin-right: -15px;
margin-left: -15px;
flex-wrap: wrap;
}
.flexbox {
flex: 0 0 33%;
padding: 0 15px;
border: 1px dashed red; /* for illustration */
display: flex; /* new */
}
.icon-box-1 {
flex: 1; /* NEW */
position: relative;
margin-bottom: 50px;
background: #fff;
text-align: center;
border: 1px solid #eee;
padding: 10px;
}
<div class="container">
<div class="row-flex">
<div class="flexbox">
<div class="icon-box-1">
<h1>
One
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Two
</h1>
<h3>Title</h3>
<p>lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Three
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Four
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Five
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Six
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
</div>
</div>
Try adding "display: flex" to .flexbox and "flex: 0 1 auto" to the icon box so it fills the heights out. Here ya go:
.container {
width: 800px;
padding: 0 15px;
}
.row-flex {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin-right: -15px;
margin-left: -15px;
flex-wrap: wrap;
}
.flexbox {
flex: 0 0 33%;
padding: 0 15px;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.icon-box-1 {
position: relative;
margin-bottom: 50px;
background: #fff;
text-align: center;
border: 1px solid #eee;
padding: 10px;
flex: 1 0 auto;
}
<div class="container">
<div class="row-flex">
<div class="flexbox">
<div class="icon-box-1">
<h1>
One
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Two
</h1>
<h3>Title</h3>
<p>lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Three
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Four
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Five
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
<div class="flexbox">
<div class="icon-box-1">
<h1>
Six
</h1>
<h3>Title</h3>
<p>lots of random text, lots of random text, lots of random text</p>
</div>
</div>
</div>
</div>
I am working on a site, of which has to have a description section. I am trying to achieve this by having two Bootstrap columns, one sized 8 and then another sized 4 to make sure it is equal to 12. Then in the column which is 8, I want to have two columns inside, to achieve one column of text on the left and then a second column of text on the right.
There is just a problem, as it doesn't seem to be working and whenever I try to do this, it just creates a second column underneath the first one inside of the 8 column.
I have attached an image to make it easier to see what I got and what I am trying to achieve. Any help is much appreciated.
Image of current situation:
What I am trying to achieve:
.partLineDesc{
margin-top: 30px;
text-align: center;
}
.leftContDesc{
margin-top: 20px;
background-color:grey;
}
.rightContDesc{
background-color:grey;
margin-top: 20px;
}
.cottonImg{
margin-top: 15px;
text-align: left;
}
.partLineDesc2{
margin-top: 20px;
text-align: center;
}
.securInfo{
margin-top: 30px;
text-align: center;
background-color:#eff4f9;
border-radius: 10px;
border: 2px solid #dddddd;
padding: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-8">
<div class="partLineDesc">
<img src="partDesc.png" alt="line seperation" class="img-responsive" style="width:1000px; height:5px;">
</div>
<div class="leftContDesc">
<div clas="col-md-6">
<p>text text text text text text text text text text text text
<br>text text text text text text text text text text text text
</p>
<img src="cottonImg.png" alt="100% Cotton" class="img-responsive" style="width:100px; height:100px;">
</div>
</div>
<div class="rightContDesc">
<div clas="col-md-6">
<p>text text text text text text text text text text text text
<br>text text text text text text text text text text text text
</p>
</div>
</div>
<div class="partLineDesc2">
<img src="partDesc.png" alt="line seperation" class="img-responsive" style="width:1000px; height:5px;">
</div>
</div>
<div class="col-md-4">
<div class="securInfo">
</div>
</div>
</div>
Your left and right DIV's wrap the Bootstrap col-md-6 columns so they no longer float next to each other. Also, always put nested col-*s inside another row so the padding is correct..
<div class="container-fluid">
<div class="row">
<div class="col-md-8">
<div class="partLineDesc">
<img />
</div>
<div class="row">
<div class="col-md-6">
<div class="leftContDesc">
<img />
</div>
</div>
<div class="col-md-6">
<div class="leftContDesc">
<p>
</p>
</div>
</div>
</div>
<div class="partLineDesc2">
<img/>
</div>
</div>
<div class="col-md-4">
<div class="securInfo">
</div>
</div>
</div>
</div>
Demo: http://codeply.com/go/yRQum3xKKY
It seems your bootstrap columns are all over the place.
You really need to wrap everything you're trying to split into columns into an overhead div that way you're saying that your main container is taking up 12 columns of that grid then you decide which of those 12 the inside columns need to take up.
Quick mock-up below.
---
.partLineDesc{
margin-top: 30px;
text-align: center;
}
.leftContDesc{
margin-top: 20px;
background-color:grey;
}
.rightContDesc{
background-color:grey;
margin-top: 20px;
}
.cottonImg{
margin-top: 15px;
text-align: left;
}
.partLineDesc2{
margin-top: 20px;
text-align: center;
}
.securInfo{
margin-top: 30px;
text-align: center;
background-color:#eff4f9;
border-radius: 10px;
border: 2px solid #dddddd;
padding: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-sm-8">
<div class="partLineDesc">
<img src="partDesc.png" alt="line seperation" class="img-responsive" style="width:1000px; height:5px;">
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="leftContDesc col-sm-4 col-md-4 col-lg-4">
<p>
text text text text text texttext text text text text text
<br> text text text text text texttext text text text text text
</p>
<img src="cottonImg.png" alt="100% Cotton" class="img-responsive" style="width:100px; height:100px;">
</div>
<div class="rightContDesc col-sm-4 col-md-4 col-lg-4">
<p>
text text text text text texttext text text text text text
<br> text text text text text texttext text text text text text
</p>
</div>
<div class="col-sm-4 col-md-4 col-lg-4">
<div class="securInfo">
</div>
</div>
</div>
<div class="partLineDesc2">
<img src="partDesc.png" alt="line seperation" class="img-responsive" style="width:1000px; height:5px;">
</div>
</div>
Fiddle
I have 2 main sections in each row, each section has an image and some text. How can I split these sections in new line on media query for mobile phones? If I put display-direction: column; on .row-flex then image AND text will also break and I don't want that. I want them to split like it is in image
.row-flex {
display: flex;
}
.col-1 {
flex: 1;
}
.col-2 {
flex: 3;
}
<div class="row-flex">
<a href="#" class="col-1">
<img src="http://placehold.it/90x90">
</a>
<div class="col-2">
<p>text text text text text text text text</p>
</div>
<a href="#" class="col-1">
<img src="http://placehold.it/90x90">
</a>
<div class="col-2">
<p>text text text text text text text text</p>
</div>
</div>
There is no such display-direction: column, what you are looking for is: flex-direction: column, and you need to wrap the elements to make them display:flex in a row
.row-flex {
display: flex;
flex-direction: column;
}
.col-1,
.col-2 {
display: flex
}
.col-1 div {
flex: 1;
}
.col-2 div {
flex: 3;
}
<div class="row-flex">
<div class="col-1">
<a href="#">
<img src="http://placehold.it/90x90">
</a>
<div>
<p>text text text text text text text text</p>
</div>
</div>
<div class="col-2">
<a href="#">
<img src="http://placehold.it/90x90">
</a>
<div>
<p>text text text text text text text text</p>
</div>
</div>
</div>