How to maintain border-radius shape as height changes - html

I have assigned a border-radius of 50px to my div, to achieve the following results:
However, when the height of the div changes, the curvature of the border also changes
What I'm looking for is for the sides to remain straight and the corners to remain the same as the div expands, like so:
This is what my css currently looks like:
.card {
border-radius: 50px;
height: 100%;
}
I should also note, I have been searching for an answer to this question (I assume it's been asked before) but I haven't been able to find an answer. I think this probably has to do with my choice of words, but I'm not sure how else to ask this question. Apologies in advance if it is a duplicate.

In your first example you dont have border radius 50px as border radius cant be more than 50%
please see this answer for details.
Border-radius in percentage (%) and pixels (px) or em
so, to make it same for 2 boxes just use right border-radius values - 20px for example.
jsfiddle.net/xky4r539/

That's because 50px is too high a value for border-radius in the first place.
The reason why it works when it's small is because it gets capped at half the height of the side between them. So in your above example the actual (resulting) value is around 18px (half the height of the div).
When the div becomes taller, its small height no longer limits border-radius value and it goes up until specified 50px. You need to play with its size (or measure it) so it is correct for the tall box. I assure you it will also be correct for the short case as well.

50px border radius is too big here. you can use 20px.
.card {
margin-bottom:20px;
background: yellow;
padding: 10px;
width: 80%;
border-radius: 20px;
position: relative;
}
.avatar {
background: red;
height: 50px;
width:50px;
border-radius:50%;
position: absolute;
top: -2px;
right: -2px;
}
p {
width: calc(100% - 20px);
}
<div class="card">
<p>Lorem Ipsum is simply dummy text of the printing and typeset </p>
<div class="avatar"></div>
</div>
<div class="card">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
<div class="avatar"></div>
</div>
<div class="card">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
<div class="avatar"></div>
</div>

Related

Trying to get max-content of element's height plus some custom value

What i need is to add more height after max-content
I tried to use calc but its not working its not allowed to sum max-content with px or rem
here is my code
<p>Lorem Ipsum is simply dummy text of the printing and typesetting <br> industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer</p>
p{
// Here were i need some additional space after max-content
height: calc(max-content + 2rem)
}

Alignment of content vertically in adjacent flexbox containers

I have multiple items say cards. These cards need to stack horizontally and height needs to be the same. This is happening for me.
Each card has an image, text and a button. Image and text for each card should take what ever is the max height in any card, so that these align properly. This is not happening for me.
If the image and text align properly then the button will always be aligned in each card at the bottom.
I have been following this tutorial but I have multiple cards, putting three here only. Also the third card image height is being set via CSS.
.partner-cards * {
box-sizing: border-box;
}
.partner-cards {
display: flex;
flex-wrap: wrap;
}
.partner-card {
display: flex;
flex: 1 0 20%;
border-radius: 0;
text-align: center;
border: 3px solid blue;
padding: 5px;/*3rem;*/
margin-bottom: 3rem;
max-width: 20%;
margin: 5px;
}
.partner-card-content {
display: flex;
flex-direction: column;
}
/*
.card-content .image-container img {
margin: 0;
padding: 0;
}
*/
.partner-card-content .partner-image-container {
border: 1px solid green;
padding: 0;
margin: 0;
min-height: 11rem;
display: flex;
vertical-align: middle;
align-items: center;
justify-content: center;
max-width: 100%;
}
.partner-card-content p /*, .card-content .image-container*/
{
flex: 1 0 auto;
border: 1px solid red;
}
.partner-card-content img.third-image {
height: 5.5rem !important;
}
/*
p {
font-size: 16px;
line-height: 26px;
font-family: Averta-Regular,Arial,Helvetica,sans-serif;
margin-bottom: 2.5rem;
margin-top: 0;
}*/
<div class="partner-cards">
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/100x40" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
<a class="primary-button" href="#">View XXX XXX XXX Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/50x150" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s.</p>
<a class="primary-button" href="#">View YYY Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/120x100" class="third-image" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
<a class="primary-button" href="#">View ZZZ Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/50x100" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
<a class="primary-button" href="#">View ABC Offer</a>
</div>
</div>
</div>
How it should show:
The tutorial image on code pen, properly aligns the h2, text and link:
TL;DR
Alignment of flexbox items in adjacent flexboxes is not possible in CSS. You really need sub-grids to solve this problem with dynamic sizes of the sections in your card.
Flexbox Scenario
Anyway given that you have a min-height for the partner-image-container, so I guess you can have either a min-height set for the a or an ellipsis to keep it to a single line. See below solution that adds an ellipsis:
.partner-cards * {
box-sizing: border-box;
}
.partner-cards {
display: flex;
flex-wrap: wrap;
}
.partner-card {
display: flex;
flex: 1 0 20%;
border-radius: 0;
text-align: center;
border: 3px solid blue;
padding: 5px;/*3rem;*/
margin-bottom: 3rem;
max-width: 20%;
margin: 5px;
}
.partner-card-content {
display: flex;
flex-direction: column;
min-width: 0; /* ADDED */
}
/*
.card-content .image-container img {
margin: 0;
padding: 0;
}
*/
.partner-card-content .partner-image-container {
border: 1px solid green;
padding: 0;
margin: 0;
min-height: 11rem;
display: flex;
vertical-align: middle;
align-items: center;
justify-content: center;
max-width: 100%;
}
.partner-card-content p/*, .card-content .image-container*/ {
flex: 1 0 auto;
border: 1px solid red;
}
.partner-card-content img.third-image {
height: 5.5rem !important;
}
/*
p {
font-size: 16px;
line-height: 26px;
font-family: Averta-Regular,Arial,Helvetica,sans-serif;
margin-bottom: 2.5rem;
margin-top: 0;
}*/
.primary-button { /* ADDED */
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
<div class="partner-cards">
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/100x40" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
<a class="primary-button" href="#">View XXX XXX XXX Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/50x150" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s.</p>
<a class="primary-button" href="#">View YYY Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/120x100" class="third-image" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
<a class="primary-button" href="#">View ZZZ Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/50x100" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
<a class="primary-button" href="#">View ABC Offer</a>
</div>
</div>
</div>
Note that you'll have to add min-width: 0 to partner-card-content to override the default min-width: auto setting for a flexbox in the flex axis. You can see some examples of this behaviour below:
Flexbox affects overflow-wrap behavior
Flexbox resize and scrollable overflow
Why don't flex items shrink past content size?
CSS Grid Scenario
You can do this in a different way using CSS Grid Layout - as an example consider 3 cards laid out in a row. This works for dynamic heights of each of your card sections - see demo below:
.partner-cards * {
box-sizing: border-box;
}
.partner-cards {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto 1fr auto;
grid-auto-flow: column;
grid-column-gap: 10px;
}
.partner-card, .partner-card-content {
display: contents;
}
.partner-card-content .partner-image-container {
border: 1px solid green;
display: flex;
align-items: center;
justify-content: center;
max-width: 100%;
}
.partner-card-content p {
border: 1px solid red;
margin: 0;
}
.partner-card-content a {
border: 1px solid;
}
<div class="partner-cards">
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/100x40" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
<a class="primary-button" href="#">View XXX XXX XXX Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/50x150" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s.</p>
<a class="primary-button" href="#">View YYY Offer</a>
</div>
</div>
<div class="partner-card">
<div class="partner-card-content">
<div class="partner-image-container">
<img src="https://via.placeholder.com/120x100" class="third-image" alt="">
</div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
the industry's standard dummy text ever since the 1500s. Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
<a class="primary-button" href="#">View ZZZ Offer</a>
</div>
</div>
</div>
But again it has limitations because you are not able to control your layout - you don't have control over your cards but you are working on the contents of the cards here which is not very useful. Note that I have used display: contents for the partner-card and partner-card-content elements. When sub-grids are implemented, we will have a complete solution to layouts such as this - see the discussion below too:
Wrap CSS grid with auto placement

How do I apply border bottom to more than one line of text?

I'm using border-bottom for all the CATs on my website. Great when it a word or two. On trying to apply it to a CTA that's more than a sentence, the words break on mobile and the border-bottom only affects the last line of the sentence. How do I make the border-bottom affect the lines of text? I don't want to use underline for the sake of transition on hover, and the fact that underlines does not give my the 1px border I want.
See images for desktop, mobile and tab here
This seems to work for me!
.underline {
border-bottom: 1px solid black;
}
<span class="underline">Read more on research, empathy and personas on Medium</span>
That transition may be applied on the pseudo element ::before or ::after that is not underline for text.
div
{
text-decoration:underline;
}
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an</div>
underline for all words... hope this works
Try this!
div
{
display:inline;
border-bottom: solid 1px #000
}
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an
</div>

dynamic content ellipsis based on predefined proportion

I have the following template of a card: pen. It is comprised of two sections "one" and "two".
<div id="one">
<div id="two">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's...
</div>
<div id="three">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been...
</div>
</div>
Both of the sections have content that overflows their respective size. I would like to maximize #two div, so that it will take maximum (and ellipsis the rest) size and leave one line for the #three div.
If there is not enough content for #two then take its respective size and give all size left to #three.
Edit:
I would like to fix the width and allow the height to grow to a certain limit and then ellipsis

CSS center multiline text but with shortest line on top?

I have some html, css similar to this:
<div style="width: 40em; text-align: center;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy tex
</div>
which renders like this but i want that the shortest line to be on top, like this.
i am unable to figure out how to do this, any help would be appreciated!
Text is automatically displayed by web browser until the end of the block width. If you want something diferent you must use a break.
<div style="width: 40em; text-align: center;">
Lorem Ipsum is simply dummy text<br>
of the printing and typesetting industry. Lorem Ipsum has been the
industry's standard dummy tex
</div>