Increase div to one direction using css only - html

I have this code that I need the div to resize vertically as the text inside increases. The bottom should remain fixed as div increases upwards
<div class ="div-increase">commodo sit amet, posuere lobortis quam. Vestibulum d
</div>
How can I achieve this using css
.div-increase{
position: relative;
display: inline-block;
width: 210px;
height: 100px;
max-width: 210px;
max-height: 250px;
min-height: 1.5em;
border: 1px solid blue;
padding: 3px;
border-radius: 10px;
line-height: normal;
color: red;
}

you can achieve this using flexbox with flex-direction: column-reverse. I've also made the div editable, so you can try the snippet typing some extra text:
.div-increase {
position: relative;
display: flex;
flex-direction: column-reverse;
width: 210px;
height: 100px;
max-width: 210px;
max-height: 250px;
min-height: 1.5em;
border: 1px solid blue;
padding: 3px;
border-radius: 10px;
line-height: normal;
color: red;
}
<div class="div-increase" contenteditable="true">commodo sit amet, posuere lobortis quam. Vestibulum d
</div>
here is my favorite flexbox cheat-sheet, the official docs and browser support

Related

Button overflows flex container when aspect-ratio is used

Trying to place a button into flex container and make its height to be percentage of sibling's (.task) height. It works as expected except that button horizontally overflows parent (.task-buttons) and ancestor (.task). I have no idea why it happens.
I'd like .task-buttons to have the same width as its content and fit into .task, shrinkin .task-todo if needed. Exactly .task-todo as its parent (.task-info) may contain additional items that shouldn't be shrunk.
*,
::before,
::after {
box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 22px;
}
.container {
position: relative;
left: 30%;
top: 50px;
width: 40%;
padding: 8px 16px;
border-radius: 30px;
box-shadow: 0px 1px 4px #00000029;
}
.task {
display: flex;
justify-content: space-between;
width: 100%;
}
.task-info {
display: flex;
align-items: center;
white-space: nowrap;
overflow: hidden;
}
.task-todo {
overflow: hidden;
text-overflow: ellipsis;
}
.task-buttons {
display: flex;
align-items: center;
position: relative;
}
.task-inc-button {
font-size: 18px;
color: white;
height: 80%;
aspect-ratio: 1;
border: none;
border-radius: 50%;
background-color: #9BE0DB;
cursor: pointer;
}
<div class="container">
<div class="task">
<div class="task-info">
<div class="task-todo">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis magna a sem posuere vestibulum.</div>
</div>
<div class="task-buttons">
<button type="button" class="task-inc-button">+</button>
</div>
</div>
</div>
Replace aspect-ratio: 1; with width: 20px; in .task-inc-button CSS, I hope it'll help you out. Thank You
*,
::before,
::after {
box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 22px;
}
.container {
position: relative;
left: 30%;
top: 50px;
width: 40%;
padding: 8px 16px;
border-radius: 30px;
box-shadow: 0px 1px 4px #00000029;
}
.task {
display: flex;
justify-content: space-between;
width: 100%;
}
.task-info {
display: flex;
align-items: center;
white-space: nowrap;
overflow: hidden;
}
.task-todo {
overflow: hidden;
text-overflow: ellipsis;
}
.task-buttons {
display: flex;
align-items: center;
position: relative;
}
.task-inc-button {
font-size: 18px;
color: white;
height: 80%;
border: none;
border-radius: 50%;
background-color: #9BE0DB;
cursor: pointer;
width: 20px;
}
<div class="container">
<div class="task">
<div class="task-info">
<div class="task-todo">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis magna a sem posuere vestibulum.</div>
</div>
<div class="task-buttons">
<button type="button" class="task-inc-button">+</button>
</div>
</div>
</div>

Div inside a flex container wont shrink when inside a `media only screen and (max-width: 430px)` thing

I have been trying to make a website responsive but flex containers wont shrink. I have tried setting the width and height of the flex-box element but not all of them will change. This is what the flex-container looks normally. and this is what it looks like when the width of the screen is smaller that 430px The image witch is part of the flex-container will resize properly but not the div with the text witch is weird since i can resize it normally if i just change its width outside the #media only screen and (max-width: 430px)
HTML
<div id="flex-stuff">
<div class="pr_cont">
<img id="project_img" src="images/img04.png" alt="stuff">
<div class="project_div">
<p id="project_textA">Nascetur nunc varius commodo</p><br><br>
<p id="project_textB">Interdum amet accumsan placerat commodo ut amet aliquam blandit nunc tempor lobortis nunc non. Mi accumsan.</p><br><br>
View more
</div>
<div class="pr_cont">
...
</div>
<div class="pr_cont">
...
</div>
</div>
CSS
#flex-stuff {
display: flex;
justify-content:space-around;
flex-wrap: wrap;
}
.pr_cont {
margin: 1% 1%;
width: 98%;
border-radius: 10px;
width: 400px;
}
#project_img {
border-radius: 10px 10px 0 0;
}
.project_div {
background-color: #333;
height: 250px;
flex: 1;
width: 400px;
border-radius: 0 0 10px 10px;
}
#project_textA {
margin-top: -4px;
border-radius: 0 0 10px 10px;
color: white;
text-align:center;
padding-top: 30px;
font-size: 24px;
font-weight: 400;
}
#project_textB {
margin: 0;
font-size: 18px;
color: gray;
text-align: center;
}
#more_box {
text-decoration: none;
text-align: center;
color: white;
width: 10%;
margin: 0 5%;
background-color: #bd00ff;
padding: 20px 36%;
border-radius: 10px;
}
The problem is not that the I can't change the div to make it smaller. i can do that but not in #media only screen and (max-width: 420px) thing
The problem was that I was using a display: inline; in a flex container. And the solution was to specify the display: block; on the #media only screen and (max-width: 430px) stuff.

Div height differs to what is declared on the property in IE11 only

I am trying to create a webpage with a vertically and horizontally centred div, with defined height and width, split down the middle. Almost like an open book.
I have no problems with achieving this in Chrome/Firefox/Safari but cannot get this to reflect in IE11 as half of the 'book' has a greater height than the other half, which leads me to believe the 'height: 863px' property in .loginContainer is causing the issue as it looks marginally better once I move this.
Not totally sure but I think I need to specify an explicit height for the container to stop the content inside becoming squashed - simply removing this property allows the container to be too small so content looks cramped once I put text in there.
I have tried to remove the property and use padding on the content inside to create a bit of space but I don't feel this is the right approach and makes it appear totally different to the mock ups I'm following.
I have created a JSFiddle found here;
https://jsfiddle.net/e02cqdr6/2/
and think the issue lies at;
.loginContainer {
display: flex;
justify-content: flex-start;
flex-grow: 0;
flex-shrink: 1;
margin: 0 auto;
width: 1338px;
height: 863px;
border-radius: 15px;}
html,
body {
background-color: rgb(27, 27, 27);
height: 100%;
min-height: 100%;
/* for firefox */
}
.pageContainer {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
}
.loginContainer {
display: flex;
justify-content: flex-start;
flex-grow: 0;
flex-shrink: 1;
margin: 0 auto;
width: 1338px;
height: 863px;
border-radius: 15px;
}
.leftContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
text-align: center;
background-color: green;
width: 621px;
border-radius: 15px 0 0 15px;
}
.rightContainer {
display: flex;
flex-direction: column;
background-color: #ffffff;
align-items: center;
width: 717px;
border-radius: 0 15px 15px 0;
}
.titleContainer {
display: flex;
flex-direction: column;
width: 100%;
}
input {
height: 30px;
width: 220px;
padding: 0 10px 0 10px;
box-shadow: none !important;
border: 1px solid rgb(243, 241, 241);
border-radius: 15px;
background-color: rgb(243, 241, 241);
color: grey;
}
a {
font-size: 0.7rem;
color: orange;
text-decoration: none;
}
.nextBtn {
margin-top: 10px;
background-color: rgb(134, 200, 223);
color: #ffffff;
}
.assetContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
}
.descContainer {
display: flex;
flex-direction: column;
text-align: center;
width: 100%;
}
.descHeading {
margin: 0 auto;
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
font-style: normal;
font-weight: 100;
padding-bottom: 5px;
}
.productDesc {
margin: 0 auto;
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 17px;
font-style: normal;
font-weight: 100;
width: 440px;
}
.assetLogoBlack {
width: 100%;
height: 100%;
}
.logoContainer {
width: 100%;
}
.servicesLogo {
width: 30%;
}
<div class="pageContainer">
<div class="loginContainer">
<div class="leftContainer">
<div class="assetContainer">
<div class="logoContainer">
<img src="/assets/ilogo.svg" class="servicesLogo">
<img src="/assets/cslogo.svg" class="servicesLogo">
</div>
<div class="descContainer">
<p class="descHeading">Lorem ipsum dolor sit amet</p>
<p class="productDesc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi volutpat sodales arcu id tincidunt. Ut a laoreet risus. Suspendisse potenti. Curabitur in ultricies risus. Vivamus convallis non libero commodo malesuada. Cras eu neque vulputate
lectus sagittis ullamcorper sit amet vitae ante. Integer pellentesque neque eget molestie vehicula. </p>
</div>
</div>
</div>
<div class="rightContainer">
</div>
</div>
</div>
So I expect it to look like this: https://ibb.co/T2Cc59V
but instead it looks like this: https://ibb.co/M8zZ9rs
To reiterate, the problem only exists in IE11.
Nothing stands out as obvious and I have no errors thrown so am totally stumped as to how to resolve this.
Thank you for all the input, I have ended up stripping this back to bare bones to see what is causing the issue as it does work fine on the jsfiddle. It turns out it is the white space around the asset I need to use for the background makes it appear as though it doesn't fill the parent div.

how to manually position multiple divs within another div

I am trying to achieve this layout The black thin line shows the border of the outer div. Inside, there are two divs (red and blue). I would like to position them next to each other with a little space in between. Additionally, the top/bottom of the red div and the top/bottom of the blue div should be equal. The left and right should also be equal. This should be equal no matter the size of the browser.
I've tried playing around with the margins but I can't do it so that its exactly equal. Here's is the link for the full code of my attempt.
Here is a snippet of my code:
#about {
background-color: #D1C9BE;
border-style: solid;
border-color: black;
position: relative;
}
#aboutImage {
border-style: dotted;
border-color: white;
background-color: red;
height: 150px;
width: 150px;
margin-top: 200px;
}
#aboutInfo {
border-style: dotted;
border-color: white;
background-color: blue;
width: 300px;
height: 400px;
font-size: 35px;
text-align: right;
margin-left: 20px;
}
Also is there a way to automatically size a div based on how much text is in it? I've seen solutions for two divs of equal size just positioned side by side but how would I do so with two divs, different sizes?
Use flex-box. Plus don't mix flex box and traditional positioning styles.
You can accomplish what you need with display: flex and justify-content: space-evenly; and align-items: center;
body {
margin: 0;
}
html, body {
height:100%;
}
/* FULLPAGE */
.section {
height: 100vh;
display: flex;
justify-content: space-evenly;
align-items: center;
}
/* ABOUT */
#about {
background-color: #D1C9BE;
}
#aboutImage {
border-color: white;
background-color: red;
height: 150px;
width: 150px;
}
#aboutInfo {
border-color: white;
background-color: blue;
font-size: 35px;
}
#aboutInfo p {
font-size: 15px;
}
<html>
<body>
<section id="about" class="section">
<!-- Picture -->
<div id="aboutImage"></div>
<!-- Description -->
<div id = "aboutInfo">
Lorem Ipsum.
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br> Suspendisse malesuada lacus commodo enim varius, <br> non gravida ipsum faucibus. Vivamus pretium pulvinar <br> elementum. In vehicula ut elit vitae dapibus. Cras ipsum <br> neque, finibus id mattis vehicula, rhoncus in mauris. In <br> hendrerit vitae velit vel consequat. Duis eleifend dui vel <br> tempor maximus. Aliquam rutrum id dolor vel ullamcorper. <br> Nunc cursus sapien a ex porta dictum.
</p>
</div>
</section>
</body>
<html>
You can use flex.
For the parent container, type it
.container {
display: flex;
flex-direction:row;
align-items: center;
}
You can use flexbox for that. It will help you horizontally (justify-content) and vertically (align-items) center your elements with equal space around them (justify-content: space-evenly). In this case your child elements don't need any extra styling.
#about {
display: flex;
align-items: center;
justify-content: space-evenly;
padding: 20px;
background-color: #D1C9BE;
border-style: solid;
border-color: black;
}
#aboutImage {
border-style: dotted;
border-color: white;
background-color: red;
height: 150px;
width: 150px;
}
#aboutInfo {
border-style: dotted;
border-color: white;
background-color: blue;
width: 300px;
height: 400px;
font-size: 35px;
text-align: right;
}
As for your last question re automatically sized divs, this is actually the default if you omit the height property. The div will then be just as tall as your number of lines of text (assuming you keep the width set).

Bottom vertical align div in parent

Im having an issue with vertical aligning a button inside of its parent.
The button should be aligned to the bottom of the "info" div but I cannot get it to stick.
I cannot use "position: absolute" in this situation.
And i do not know the height of the main parent div beforehand.
HTML:
<div class="container">
<img src="http://placekitten.com/g/200/400" alt="" />
<div class="info">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloribus rem tenetur temporibus voluptas repellendus.</p>
<button>Button</button>
</div>
</div>
CSS:
* { box-sizing: border-box; }
.container {
width: 200px;
height: 700px; /* The height is variable!!! */
background: #ccc;
padding: 1em;
overflow: hidden;
}
a { display: block; height: 50%; }
a img { display: block; width: 100%; max-width: 100%; }
.info {
background: #fa0;
display: block;
height: calc(50% - 1em);
margin-top: 1em;
text-align: center;
}
.info p {
display: inline-block;
width: 100%;
vertical-align: top;
background: #a0f;
margin: 0;
}
.info button {
display: inline-block;
vertical-align: bottom;
}
As mentioned in some of the comments, position: absolute is the easiest way to do this. However, you said you're restricted on this factor, so here's an alternative using flexbox!
You need to see three properties on the parent element: display, flex-direction, and justify-content. Then put a margin on the child element to make sure its centered at the bottom. Here's an updated fiddle. No absolute position required : ) https://jsfiddle.net/jg8egtb1/
.info {
background: #fa0;
display: block;
height: calc(50% - 1em);
margin-top: 1em;
text-align: center;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.info button {
margin: 0 auto;
}