I'm currently working into a project with ReactJS and TailwindCSS where I'm making sort of a "grid" of resizable textareas and the behavior is almost how I want, except when i resize any element on the right side of the screen, which causes it to break to next line due of flex-wrap and then the resize I was doing gets recalculated taking into consideration that the textarea and the mouse positions are different than before (this is the problem).
I want to know if it's possible to make it work in the way I'm going and would be really helpfull any tip or workaround at it.
<div class="container">
<textarea></textarea>
<textarea></textarea>
<textarea></textarea>
<textarea></textarea>
<textarea></textarea>
<textarea></textarea>
</div>
.container{
min-height: 100vh;
background-color: lightgray;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
textarea {
resize: both;
height: 200px;
width: 250px;
max-height: 400px;
max-width: 550px;
}
Here is a Codepen with an example (written in HTML and CSS).
Here is an image that illustrates the textarea while resizing
This is what happens when the resize exceeds the flex limit and the wrap happens
is that what you want to do?
<div class="up_container">
<textarea></textarea>
<textarea></textarea>
<textarea></textarea>
</div>
<div class="down_container">
<textarea></textarea>
<textarea></textarea>
<textarea></textarea>
</div>
.up_container,
.down_container {
min-height: 50vh;
background-color: lightgray;
display: flex;
flex-direction:row;
gap: 10px;
}
textarea {
resize: both;
height: 200px;
width: 250px;
max-height: 400px;
max-width: 550px;
}
you must define a width to your container and a min-height to your textarea. I think that's what you want?
.container{
width:200vh;
min-height: 100vh;
background-color: lightgray;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
textarea {
resize: both;
min-height: 200px;
width: 250px;
max-height: 400px;
max-width: 550px;
}
Related
I want to have a container that includes an image and a caption.
The container should always be the same size, the caption height might change.
In my mind the caption should get the auto height, depending on it’s size and the rest of the containers height will be allocated to the image.
I tried doing that with a div and i worked flawlessly. When I exchange the placeholder div with an actual image tag, the image will take the 100% height of the container, not of its allocated flex space in the container.
Why is that and how can I fix it?
Example showing the difference between div and image tag:
https://codepen.io/lkssmnt-the-lessful/pen/QWqbxNK?editors=1100
.project {
height: 500px;
width: 500px;
display: flex;
flex-direction: column;
}
.project img {
height: 100%;
width: 100%;
object-fit: cover;
}
Add overflow: hidden to the .img tag. - This has the negative effect of snipping the bottom of the image off, however.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrapper {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.project {
height: 500px;
width: 500px;
border: 5px solid red;
margin: 1rem;
display: flex;
flex-direction: column;
}
.project p {
padding: 1rem;
}
.project img {
overflow: hidden;
height: 100%;
width: 100%;
object-fit: cover;
}
.project .test {
height: 100%;
width: 100%;
background: beige;
}
<div class="wrapper">
<div class="project">
<div class="test"></div>
<p>Project 1</p>
</div>
<div class="project">
<img src="https://images.unsplash.com/photo-1518676590629-3dcbd9c5a5c9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80">
<p>Project 2</p>
</div>
</div>
i have doing my portfolio but i'm not good with CSS.
I'm using the Flexbox to do the design desktop and mobile but it not working...
It is like this, as i want, using flex-direction: column,:
Code of the div parent:
display: flex;
justify-content:center;
align-items:center;
background-color:#C4C4C4;
min-height: 100vh;
flex-direction: column;
But when i put in responsive, it stay like this:
The elements outside of div parent..
The code is the same, only changes the background-color.
background-color: red;
width:800px;
height:650px;
margin: 30px;
It not stay corrects.
If i dont use the flex-direction: column, it stay like this:
Someone why?
Your main issue was missing max-width: 100%; in the children so the width:800px would not overflow the container parent, take a look at the snippet
section {
display: flex;
justify-content: center;
align-items: center;
background-color: #C4C4C4;
min-height: 100vh;
padding: 15px 30px;
box-sizing: border-box;
}
#media(max-width:800px) {
section {
flex-direction: column;
}
}
div {
max-width: 100%;
width: 800px;
height: 650px;
margin: 15px
}
div:first-of-type {
background-color: red;
}
div:last-of-type {
background-color: blue
}
<section>
<div>red</div>
<div>blue</div>
</section>
max-width not set the width of the children elements.
Make sure you set a width to all of your containers; it looks like you want the gray container to fill the viewport, and the blocks to be evenly distributed.
Here's a working example:
.container {
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
text-align: center;
background-color: gray;
width: 100vw;
height: 100vh;
}
.block {
background-color: #C4C4C4;
min-height: 33vh;
width: 90vw;
}
<div class="container">
<div class="block" style="background-color: red">
A
</div>
<div class="block" style="background-color: blue">
B
</div>
</div>
I'm trying to format a HTML DIV in a way that the margin-top is set responsively based on the div's height: jsfiddle
There's another div inside the wrapper, that has a display: none set to it, but it may change when the user inputs a wrong password. Thing is, there is a div below that it's being pushed down when display: content is set to the second div. I want the content of the page to responsively go upwards instead of downwards.
How's now:
How it should be:
Given your example, your goal and your preference to avoid flexbox due to IE10, I think your best option is to use display:table for this container.
With this, you have the ability to use vertical-align properties in the "table-cell".
Check the example below. I added a toggle button to show/hide your captcha for demo purposes. May want to view it full screen to get the effect.
$("#toggle").on('click', function() {
$(".captcha").toggle();
});
html,body {
height: 100%;
}
.outer-wrapper {
height: 100%;
width: 100%;
background: #eeeeee;
display: table;
}
.inner-wrapper {
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;
height: inherit;
}
.login-wrapper {
background-color: #172238;
color: white;
width: 200px;
text-align: center;
height: auto;
display: block;
margin: 0 auto;
}
.captcha{
margin-top: 250px;
display: content; // This one changes
}
.homologation-line {
min-width: 200px;
background-color: #ffd800;
color: black;
text-align: center;
height: 30px;
}
#toggle {
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="toggle">toggle captcha</button>
<div class="outer-wrapper">
<div class="inner-wrapper">
<div class="login-wrapper">
<p>Login</p>
<div class="captcha">
ENTER THE DIGITS:
</div>
</div>
<div class="homologation-line">
HOMOLOGATION
</div>
</div>
</div>
I cannot get my list to be full height. My code is more complicated with nested components. But I can still get this to replicate using this code. Here is a plunk. http://plnkr.co/edit/R0QgLz8cjyRHYOLf4uJW
styles.css
html, body {
min-height: 100%;
height: auto;
margin: 0;
}
app.component.css
.container {
height: 100%;
background: black;
color: white;
list.component.css
.row {
display: flex;
flex-direction: row;
}
.list {
width: 33%;
height: 100%;
flex-direction: column;
display: flex;
border-right: groove white 1px;
border-top: groove white 1px;
}
.item {
width: auto;
height: 100%;
flex-direction: column;
display: flex;
}
list.component.html
<div class="contents">
<button (click)="updateDocuments()">Update Document</button>
<div class="row">
<div class="list">
<div *ngFor="let document of documents; let i = index;">
{{i + 1}}. {{document}}
</div>
</div>
<div class="item">
this is an item
</div>
</div>
</div>
I got this to work by switching to height 100vh and also adding a overflow-y: scroll css attribute to the list and item classes.
http://plnkr.co/edit/R0QgLz8cjyRHYOLf4uJW
styles.css
html, body {
min-height: 100vh;
height: auto;
margin: 0;
}
app.component.css
.container {
height: 100vh;
background: black;
color: white;
list.component.css
.row {
display: flex;
flex-direction: row;
}
.list {
width: 33%;
height: 100vh;
flex-direction: column;
display: flex;
border-right: groove white 1px;
border-top: groove white 1px;
overflow-y: scroll;
}
.item {
width: auto;
height: 100vh;
flex-direction: column;
display: flex;
overflow-y: scroll;
}
list.component.html
<div class="contents">
<button (click)="updateDocuments()">Update Document</button>
<div class="row">
<div class="list">
<div *ngFor="let document of documents; let i = index;">
{{i + 1}}. {{document}}
</div>
</div>
<div class="item">
this is an item
</div>
</div>
</div>
try to write this css
.container{
min-height:100vh;
}
Had the same issue, and found that the best solution was:
html, body {
min-height:100vh;
height: auto;
}
and for the container:
.container{
min-height: 100vh;
}
Use position: fixed if that's acceptable:
.container {
position:fixed;
background: black;
color: white;
height: 100%;
}
Hi everyone who faced this problem
Just go to global css file, it has the comment
/* You can add global styles to this file, and also import other style files */
written in it. Add
*{margin:0; padding:0}
that's it
Somewhere in the Internet:
The reason for this issue is concealed in the way a browser interprets
the host element, which doesn’t know it’s an HTML element at all and
so the browser sets the default display value (inline) for the host
element.
So probably it's enough just to redefine again "display" property for "host" tag (add in your component code) :
host: {
display: flex; /*or whatever is fit your needs*/
}
try in your style.css
html, body {
height: 100%;
margin: 0;
}
Here's image displaying my problem
CSS for wrapper is
display: block;
text-align: center;
CSS for each DIV is
margin: 30px 10px;
display: inline-block;
height: 100%;
text-align: center;
width: 30%;
What could be causing this? I tried fiddling with flex but the outcome is the same.
You said you fiddled with flexbox. However to make use of it, you should not just fiddle with it, but study how it works.
To achieve what you want, use display: flex; on the wrapping div and remove height property from your contained divs.
Run this visual example to see how it works:
.parent {
padding: 20px;
background: red;
width: 400px;
height: 100px;
display: flex;
}
.child-1 {
background: yellow;
width: 100px;
}
.child-2 {
background: orange;
width: 100px;
}
<div class="parent">
<div class="child-1">
Hello
</div>
<div class="child-2">
Multi
<br>
Line
<br>
Content
</div>
</div>