I try to ajust some dynamic content so it fit onto label to be printed.
The label has a row (.symbolContainer) that can contain 0 or more images. The objective is to shrink that .symbolContainer and those images if the content of .text box need more spaces.
EDIT: The row of images should not wrap, but shrink from 75px to a minimum of 25px.
Seem to me that flexbox is the way to go, and it ended up with 3 levels of nested flexbox, but the images inside the .symbolContainer won't shrink.
Content of .text div can overflow the .body div, but I will adjust the font-size with javascript after.
It is possible to acheive this with flexbox or other tricks?
Here is what I have done so far. Comment in CSS is what I wanted to do.
.container {
width: 3.5in;
height: 5in;
border: 1px solid black;
border-radius: 6px;
display: flex;
flex-direction: column;
}
.title {
font-weight: bolder;
font-size: 24px;
text-align: center;
}
.body {
background-color: #aad9fa;
flex: 1;
overflow: hidden;
display: flex;
flex-direction: column;
}
.symbolContainer {
display: flex;
justify-content: center;
background-color: #c1f1bf;
flex: 0 1 75px;
/* Height is 75px but shrink if need to */
/* No minimum height because can be empty */
}
.symbolContainer>img {
flex: 0 1 75px;
/* Size start at 75 px then shrink */
min-width: 25px;
/* but don't shrink pass 25px */
align-self: flex-start;
}
.text {
font-size: 22px;
flex: 1;
/* Take maximum possible space */
}
.footer {
text-align: center;
height: 30px;
background-color: green;
}
<div class='container'>
<div class='title'>
A title that can be multiline because of his variable length
</div>
<div class='body'>
<div class='symbolContainer'>
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/flamme.svg">
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/nocif.svg">
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam bibendum risus ex, nec gravida augue iaculis vel. Nam malesuada vitae libero ac tempus. Aenean et ipsum ac justo malesuada venenatis. Proin consequat tellus et varius mattis. Vestibulum
cursus dui in tincidunt pellentesque. Nullam feugiat lacus sem, et dapibus sapien maximus eu.
</p>
<p>Vivamus ullamcorper odio ex, sed rhoncus tellus sagittis eu. Proin egestas erat metus, sed congue dolor efficitur ac. Fusce ultrices quis urna vel tristique. Ut fermentum ipsum tellus, vel accumsan dui malesuada nec. Vivamus aliquam justo vel tortor
luctus, non venenatis lectus sagittis. Morbi feugiat sem nec elit varius ultricies.</p>
</div>
</div>
<div class='footer'>
This is the footer. Can be fixed height
</div>
</div>
You don't need those layers for the Flex Containers in order to do the images responsive.
Symbol Container should be:
.symbolContainer{
min-width: 0; /* resize as what you want */
margin: 5px; /* resize as what you want */
}
img {
width: 450px; /* resize as what you want */
max-width: 100%; /* resize as what you want */
max-height: 450px; /* resize as what you want */
}
.imgContainer{
display: flex;
justify-content: center;
flex-wrap: wrap;
}
Now the html should change to:
<div class='body'>
<div class='imgContainer'>
<div class='symbolContainer'>
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/flamme.svg">
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/nocif.svg">
</div>
</div>
...
That should do what you want. Be aware to resize to what you want.
Hope it helps!
pd. It's based on this post:
https://medium.com/#sashatran/check-out-the-page-here-7d71a2c43a10
Related
I want to make responsive vertical menu with icons, that would shrink with transition (fade in to left) when screen width is to small. It would look like this - normal menu:
(icon1) Position1
(icon2) Position2
(icon3) Position3
and after shrinking window to let's say 800px it should fade into the left and look like this:
(icon1)
(icon2)
(icon3)
How do I make such thing using only HTML and CSS?
To make the element fade out when the page width gets smaller than 800px, for screensizes bigger than 800px, you need to give the list items a position of relative, set the list items left property to 0 and opacity to 1 so that they'll be displayed normally, and for screensizes smaller than 800px, change the left value to 100% and opacity to 0 so that it'll not be displayed anymore. next set its transition property for all screen sizes to 'all 1s ease-in-out' so the sliding will be smooth.
for the icon and the item to be displayed on the same line, just set the display of the li containing the item and the icon to flex and their align-items property to center so they'll be horizontally aligned.
#media only screen and (max-width: 800px) {
.hide-800 {
left: 100%;
opacity: 0;
}
}
#media only screen and (min-width: 800px) {
.hide-800 {
left: 5px;
opacity: 1;
}
}
.item {
position: relative;
transition: all 1s ease-in-out;
}
.row {
display: flex;
position: relative;
align-items: center;
}
.list {
overflow: hidden;
}
<body>
<ul class='list'>
<li class="row">
<span class="icon">icon1</span>
<div class="item hide-800">item1</div>
</li>
<li class="row">
<span class="icon">icon2</span>
<div class="item hide-800">item2</div>
</li>
<li class="row">
<span class="icon">icon3</span>
<div class="item hide-800">item3</div>
</li>
</ul>
</body>
*{
text-decoration: none;
}
body{
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
img{
width: 2em;
}
.content{
float: left;
border: 5px solid red;
width: 80%;
margin-left:10px;
}
a{
display: flex;
flex-direction: row;
}
.navbar {
width: 15%;
overflow: auto;
}
.navbar a {
float: NONE;
display: block;;
padding: 12px;
color: rgb(125, 137, 240);
text-decoration: none;
font-size: 20px;
font-weight: bolder;
}
.navbar a:hover {
background-color: rgb(37, 179, 171);
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
}
#media only screen and (max-width: 1500px) {
.hide-800 {
display: none;
}
.content{
width: 85%;
}
.navbar {
width: 10%;
overflow: auto;
}
}
<body>
<div class="navbar">
<div class="image"> <img src="icons/home.png"> <div class="hide-800">DASHBOARD</div> </div>
<img src="icons/files.png"> <div class="hide-800">E-PRESCRIPTIONS</div>
<img src="icons/profile-user.png"> <div class="hide-800">MY PATIENTS</div>
<img src="icons/send.png"> <div class="hide-800">INVITE</div>
<img src="icons/profile-user.png"> <div class="hide-800">MY PROFILE</div>
<img src="icons/settings.png"><div class="hide-800">SETTINGS</div></a>
</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum aliquet at neque nec maximus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Pellentesque condimentum pellentesque faucibus. Phasellus lobortis nisi sollicitudin arcu hendrerit interdum. Nulla semper tellus at dignissim rhoncus. Phasellus laoreet semper metus, eget aliquet urna mattis in. Etiam laoreet ut purus suscipit pharetra. Aliquam rutrum, risus vitae egestas ultricies, ligula lorem lobortis arcu, at dignissim felis mauris vitae lorem. Vivamus urna libero, facilisis nec tincidunt eu, ultricies eu arcu. Sed id aliquet lorem, eu egestas arcu. Cras cursus vulputate felis nec facilisis. Nunc et arcu rhoncus, fermentum lectus eu, sagittis velit. Curabitur nisi dui, semper nec felis sed, tempor blandit neque. Cras varius aliquet diam in maximus. Proin ultricies, sem eget lacinia lobortis, mauris quam venenatis neque, a rhoncus metus odio vel diam.</div>
</body>
This question already has an answer here:
Fitting child into parent
(1 answer)
Closed 3 years ago.
I am trying to add two divs to an element. The first div should have a fixed height and position. The second div should take up the rest of the space (if needed), but never exceed it. I've prepared the following example, to display the desired output.
#container {
border: 1px solid black;
height: 200px;
width: 200px;
display: flex;
flex-direction: column;
}
#fixed {
flex: 0 0 50px;
background: red;
}
#free {
flex: 1;
}
#scroll {
max-height: 100%;
overflow-y: scroll;
background: blue;
}
<div id="container">
<div id="fixed">Should always appear</div>
<div id="free">
<span>Should always appear</span>
<div id="scroll">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
This example displays the problem that arises when the contents of the second div are too large.
#container {
border: 1px solid black;
height: 200px;
width: 200px;
display: flex;
flex-direction: column;
}
#fixed {
flex: 0 0 50px;
background: red;
}
#free {
flex: 1;
}
#scroll {
max-height: 100%;
overflow-y: scroll;
background: blue;
}
<div id="container">
<div id="fixed">Should always appear</div>
<div id="free">
<span>Should always appear</span>
<div id="scroll">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse porta nec dolor a dignissim. Nunc auctor felis a turpis tincidunt auctor. Suspendisse venenatis volutpat sodales. Maecenas sodales est non quam vestibulum fermentum. Nulla venenatis
sapien sit amet augue ultricies molestie. Sed neque nulla, venenatis non est a, imperdiet dictum tortor. Nam at odio rutrum, convallis neque blandit, viverra urna. Maecenas scelerisque risus eu mollis ornare. Nullam tincidunt tempus vehicula. Aenean
at porttitor ex. Fusce tincidunt nulla velit, id gravida lacus vestibulum nec.
</div>
</div>
</div>
I would accept any answer that solves this problem regardless of what combination of css and html is used (that doesn't change the order of the elements), as long as no javascript and no more height properties are added (i.e top: 40px;, min-height: calc(100% - 40px); ...), with the exception of 0, auto and 100%.
Edit: Added min-height: 0 to div's css as well as an updated fiddle.
If I understand the question correctly, is this what you're looking for?
#free {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
Jsfiddle: https://jsfiddle.net/nick_zoum/Lod38e9a/3/
I have a simple section which display list items and image, here is how it should look :
I know its simple using framework like bootstrap etc but I want to use only flex.
Here is html:
<section class="info-section">
<div class="main-info">
<div class="main-info_left">
<h2>Nature from air</h2>
<p>Mauris consequat libero metus, nec ultricies sem efficitur quis. Integer bibendum eget metus ac accumsan. Integer sit amet lacus egestas, semper est quis, viverra ex.</p>
<ol class="info-list">
<li>CPellentesque eget nunc sit amet urna ullamcorper fermentum et eu leo. Nunc vel nibh tempor, pharetra lectus congue, luctus orci.
</li>
<li>CPellentesque eget nunc sit amet urna ullamcorper fermentum et eu leo. Nunc vel nibh tempor, pharetra lectus congue, luctus orci.
</li>
<li>CPellentesque eget nunc sit amet urna ullamcorper fermentum et eu leo. Nunc vel nibh tempor, pharetra lectus congue, luctus orci.
</li>
<li>CPellentesque eget nunc sit amet urna ullamcorper fermentum et eu leo. Nunc vel nibh tempor, pharetra lectus congue, luctus orci.
</li>
<li>CPellentesque eget nunc sit amet urna ullamcorper fermentum et eu leo. Nunc vel nibh tempor, pharetra lectus congue, luctus orci.
</li>
</ol>
</div>
<div class="main-info_right">
<span><img src="images/drone.png"></span>
</div>
</div>
</section>
Here is css I have tried:
.main-info{
display: flex;
justify-content: center;
flex-direction: row;
align-items: center;
}
ol {
counter-reset:li; /* Initiate a counter */
margin-left:0; /* Remove the default left margin */
padding-left:0; /* Remove the default left padding */
}
ol > li {
position: relative;
margin: 21px 0 57px 2em;
padding: 22px 41px;
list-style: none;
background: #fff;
}
ol > li:before {
content:counter(li); /* Use the counter as content */
counter-increment:li; /* Increment the counter by 1 */
/* Position and style the number */
position:absolute;
top:-2px;
left:-2em;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
width: 54px;
height: 54px;
border-radius: 50%;
/* Some space between the number and the content in browsers that support
generated content but not positioning it (Camino 2 is one example) */
margin-right:8px;
padding: 17px;
border: 1px solid rgb(63, 78, 118);;
background:#fff;
font-weight:bold;
font-family: proximaNova;
text-align:center;
}
li ol,
li ul {margin-top:6px;}
ol ol li:last-child {margin-bottom:0;}
here is Jsfiddle : http://jsfiddle.net/bmL7jogu/1/
Unfortunately I dont get the result I want , what do I need to change to get what I want? newbie to flex though
I suppose you want to achieve a vertically counting list items that wraps to rightside. You have already managed to customise incrementing numbers, which seems to be working great.
The actual element in which you want to apply display: flex; is <ol>, which is the parent of <li> creating the columns. Also, by default flexbox will pile up horizontally rather than vertically, and thus you need to apply flex-direction: column; to achieve vertical direction. Finally, adding flex-wrap: wrap; will let flexbox children to 'wrap' to next line, in our case to rightside of the first columns. By configuring e.g. max-width: 50%; to <li> you can adjust how many columns will be displayed when wrapped.
To summarise, below code will achieve desired list items:
ol {
display: flex;
flex-direction: column; /* Make flex children pile up 'vertically'. */
flex-wrap: wrap; /* Wrap children to next 'column'. */
max-width: 60%; /* To prevent covering the drone image. */
max-height: 600px; /* Set maximum height so columns will wrap. */
margin-left: 0; /* Remove the default left margin */
padding-left: 0; /* Remove the default left padding */
counter-reset: li; /* Initiate a counter */
}
ol > li {
position: relative;
margin: 21px 0 57px 2em;
padding: 22px 41px;
max-width: 50%;
list-style: none;
}
In addition, I would recommend you to set your drone image as background-image to .main-info as it seems to be behaving more as a background. By this way, you can avoid struggling with nested flexbox to achieve your design.
Final code:
https://jsfiddle.net/dorapen/7rdb096t/
I hope this answers your question.
You have to set display: flex to the parent and then add order:1 to the first item and then order the others.
.parent{
display: flex;
flex-wrap: wrap;
}
.parent .order1{
order: 1;
}
.parent .order2{
order: 2;
}
.parent .order3{
order: 3;
}
<div class="parent">
<p class="order3"></p>
<p class="order1"></p>
<p class="order2"></p>
</div>
You can also do it with property column-count: 2;
Hope it helps!
I am a CSS/HTML auto learner, apologies if my question is stupid.
I want a div which is 40% wide minimum with its content justified but when more items will be added in this div its width grows accordingly.
This is what I have so far:
.hcontainerbutton {
display: flex;
width: 40%;
background-color: blue;
align-items: center;
justify-content: space-around;
right: 30%;
left: 30%;
position: absolute;
bottom: 0!important;
}
both with width:40% or min-width:40% the div doesn't grow if I add more items into it
Wrap .hcontainerbutton in a container and apply flexbox and height properties to it. This can be used to position .hcontainerbutton instead of position: absolute.
Add min-width value to .hcontainerbutton
You can test this layout by adding and remove .content divs and viewing in full screen.
body {
margin: 0;
}
.container {
display: flex;
justify-content: center;
height: 100vh;
}
.hcontainerbutton {
min-width: 40%;
background-color: blue;
display: flex;
justify-content: space-around;
margin-top: auto;
}
.content {
background: pink;
width: 100px;
height: 100px;
}
<div class="container">
<div class="hcontainerbutton">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
</div>
Based on your requirements, this can be done with normal CSS itself, you need not go for flex, Here is an explanation on what is done.
First we set the width and height of html and body tag, then using margin:0px remove the margins set by the browser.
html,
body {
width: 100% height: auto;
margin: 0px;
}
Now the parent that will wrap the centered div will have to have the CSS property text-align:center, basically what this does is, it will center align elements with display property inline-block.
.parent {
text-align: center;
}
Then coming to the main div, which has the class hcontainerbutton, we can set the max-width(in the example I use 40%) and min-width(in the example I use 80%) to whatever is needed. The CSS property display:inline-block ensures it takes the width of the content alone. The CSS property word-wrap:break-word ensures the text is broken and maintains the widht of the div.
Below is a working snippet of the code.
html,
body {
width: 100% height: auto;
margin: 0px;
}
.parent {
text-align: center;
}
.hcontainerbutton {
word-wrap: break-word;
min-width: 40%;
max-width: 80%;
display: inline-block;
}
<div class="parent">
<div class="hcontainerbutton"> asdf
</div>
<div class="hcontainerbutton"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eleifend magna augue. Morbi sagittis eu urna et facilisis. Nam finibus erat justo, vel porta magna aliquam a. Pellentesque faucibus molestie libero vitae condimentum. Nunc condimentum tincidunt
nulla, id suscipit magna dignissim id. Nulla dapibus suscipit velit et viverra. Mauris non gravida justo. Sed efficitur eleifend elementum. Integer non mattis mi. Etiam vestibulum viverra erat, eget dapibus tellus iaculis ut. Mauris ullamcorper magna
sapien, ac gravida odio blandit varius. Fusce eu placerat enim. Etiam nec elementum dui. In fermentum massa sed augue interdum aliquam. Nunc lacinia blandit elit a iaculis.
</div>
</div>
I am learning CSS flexbox and was doing a simple layout where I wanted the first flex child to displayed with 100% width of the parent and rest flex items wrapping below. Also, the wrapped flex items should occupy width in a specific ratio (easy to set with 'flex' property).
To do this I set "flex-basis" property of first flex item to 100% and set flex property of next 2 to the ratio I want. Here is what the pertinent CSS looks like (link to complete fiddle is below):
.main{
max-width: 1000px;
margin: 100px auto;
display: flex;
flex-flow: row wrap;
}
/*using ususal shorthand notation*/
.flex-item:nth-child(1) {
flex:1 100%;
}
.flex-item:nth-child(2) {
flex:2;
}
.flex-item:nth-child(3) {
flex:3;
}
This should set the first item's width to 1000px and for the next two as 400px and 600px respectively; wrapped and displayed below the first child.
But for some reason the CSS breaks, and the 2nd and 3rd items are pushed outside main container.
What more strange is that adding margin to the flex items fixes the whole thing and I don't understand how this is happening (I must be doing something stupid). Even addding some border or padding to the '.flex-item' rule works.
.flex-item{
margin: 5px;
}
Here is the JS Fiddle. You can try un-commenting the '.flex-item' rule in CSS to see what is going on.
I was lazy not to add the any prefixes (since almost every new browser supports it) ,but the problem is same across latest FF, IE and chrome.
The second and third elements have 0 width, so they can fit in any place ..
That's way they stay in the first line.
just set 1px for basis, and they will be in the second row
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}
body{
font-family: 'Raleway', Helvetica, sans-serif;
font-size: 14px;
font-weight: 300;
color: #555;
}
.main{
max-width: 1000px;
margin: 20px auto;
border: 1px dotted #999;
padding: 20px;
display: flex;
flex-flow: row wrap;
}
/* adding any border, margin, padding rules here fixes it */
.flex-item:nth-child(2) {
flex:2 1px;
background-color: lightyellow;
}
.flex-item:nth-child(3) {
flex:3 1px;
}
.flex-item:nth-child(1) {
flex:1 100%;
}
<div class="main">
<p class="flex-item">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non consequat lorem. In dignissim mauris eu est commodo, ac ullamcorper dui facilisis. Sed feugiat eros quis facilisis feugiat. Pellentesque eu quam egestas, facilisis augue eu, aliquam mi. Nunc nunc metus, eleifend id finibus sit amet, imperdiet eget mi.
</p>
<p class="flex-item">
In dignissim mauris eu est commodo, ac ullamcorper dui facilisis. Sed feugiat eros quis facilisis feugiat. Pellentesque eu quam egestas, facilisis augue eu, aliquam mi. Nunc nunc metus, eleifend id finibus sit amet, imperdiet eget mi.
</p>
<p class="flex-item">
In dignissim mauris eu est commodo, ac ullamcorper dui facilisis. Sed feugiat eros quis facilisis feugiat. Pellentesque eu quam egestas, facilisis augue eu, aliquam mi. Nunc nunc metus, eleifend id finibus sit
.flex-item:nth-child(2) {
flex:2 1px;
}
.flex-item:nth-child(3) {
flex:3 1px;
}