Trying to make it so chips can line up next to each other. Once all the chips' width becomes too large, then goes to next line.
Tried using display:flex but then div contents mysteriously overflow like this:
.container {
width: 900px;
margin: auto;
}
.contentcard {
width: 300px;
height: 200px;
padding: 10px;
float: left;
padding: 10px 0;
margin-top: -4px;
margin-right: 200px;
}
h1 {
fontsize: 30px;
font-weight: bold;
}
p.descriptionText {
fontsize: 20px;
font-weight: light;
}
.chipcontainer {
width: 200px;
display: flex;
}
.typechip {
display: inline-block;
padding: 0 25px;
height: 30px;
font-size: 14px;
line-height: 30px;
border-radius: 25px;
background-color: white;
/*#f1f1f1;*/
border-style: solid;
border-width: 1px;
margin: 5px;
}
.projectcard {
width: 400px;
height: 300px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1), 0 3px 10px 0 rgba(0, 0, 0, 0.09);
text-align: center;
float: left;
}
.projectcard:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<div class="container">
<div class="contentcard">
<h1>Project 1: ADFASASDF </h1>
<p class="descriptionText">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dui ut ornare lectus sit amet est placerat. Sed turpis tincidunt id aliquet risus feugiat.</p>
<div class="chipcontainer">
<div class="typechip">UX design</div>
<div class="typechip">AI Platform</div>
<div class="typechip">HTML / CSS</div>
</div>
</div>
<div class="projectcard"></div>
</div>
I will show you 5 solution, choose what solves the problem (also added the output of every solution)
the bug is happening because of line-height in .typechip,
because technically without that property, the text inside the chip is correctly within the container.
You also have an explicit height: 30px (this means that the text will overflow if is a lot bigger.
if you delete the height property then it will automatically work,
but it will have a big gap between wrapped text.
if you don't want a big gap,
then maybe change the line-height to a lower number (in my case 1 so it will be equal to font-size),
then try to add also more padding on the top/bottom of the chip
❌padding: 0 25px -> ✅padding: 10px 25px;
if you want that chip to not wrap at all,
use flex-wrap: wrap inside parent container .chipcontainer
200px
the problem is that 200px isn't enough, so they will wrap everytime,
but the text is displayed correctly without deleting any property
250px+
✅ preferred one is 4th solution for me, because is easy and doesn't have side effects (and is more flexible because don't waste space)
like you saw, if the space of container is bigger, then automatically wrap correctly!
if you don't want they will be wrapped,
but still be readable
one line text
then use grid with column direction.
the solution: (see code snippet below)
.chipcontainer now isn't flex anymore, but grid with grid-auto-flow: column;
.typechip now have a width of max-content so it will be always in the same line (and get the less space he can without wrapping the content text)
.container {
width: 900px;
margin: auto;
}
.contentcard {
width: 300px;
height: 200px;
padding: 10px;
float: left;
padding: 10px 0;
margin-top: -4px;
margin-right: 200px;
}
h1 {
font-size: 30px;
font-weight: bold;
}
p.descriptionText {
font-size: 20px;
font-weight: light;
}
.chipcontainer {
width: 200px;
display: grid;
grid-auto-flow: column;
}
.typechip {
display: inline-block;
padding: 0 25px;
height: 30px;
font-size: 14px;
line-height: 30px;
border-radius: 25px;
background-color: white;
/*#f1f1f1;*/
border-style: solid;
border-width: 1px;
margin: 5px;
width: max-content;
}
.projectcard {
width: 400px;
height: 300px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1), 0 3px 10px 0 rgba(0, 0, 0, 0.09);
text-align: center;
float: left;
}
.projectcard:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<div class="container">
<div class="contentcard">
<h1>Project 1: ADFASASDF </h1>
<p class="descriptionText">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dui ut ornare lectus sit amet est placerat. Sed turpis tincidunt id aliquet risus feugiat.</p>
<div class="chipcontainer">
<div class="typechip">UX design</div>
<div class="typechip">AI Platform</div>
<div class="typechip">HTML / CSS</div>
</div>
</div>
<div class="projectcard"></div>
</div>
Related
I am working on web application using Rect JS and I only have beginners knowledge in HTML and CSS.So can you please suggest me to achieve something like the following with a responsive UI that containing button,text and image.How can I write css styles to curve a div and place another one below it without any blank space.
Can someone please suggest any solution? Any help would be really appreciated.I have tried radial-gradient method like following.
<div className="background1">
....
</div>
<div className="background2">
.....
</div>
.background1 {
width: 100%;
background: radial-gradient(120% 800px at 50% -30px, red 75%,
transparent 75%) no-repeat;
z-index: 2;
position:relative;
margin-bottom: 0px;
}
.background2 {
background-color: #202492;
width: 100%;
background: radial-gradient(120% 800px at 50% -30px,blue 75%,
transparent 75%) no-repeat;
position: relative;
z-index: 1;
margin-top: -50px;
}
But I am getting this
Blockquote
I think you need something like this:
.btn1 {
background: #190b0b;
color: #fff;
padding: 1em 2.5em;
box-shadow: 1px 2px 7px -1px #190b0b;
}
.background1 {
width: 100%;
background: red;
z-index: 2;
position: relative;
margin-bottom: 0px;
padding: 6em 0;
border-radius: 0 0 10em 10em;
text-align: center;
}
.background2 {
background-color: #202492;
z-index: 1;
position: relative;
margin-bottom: 0px;
padding: 6em 0;
border-radius: 0 0 10em 10em;
text-align: left;
width: 100%;
top: -10em;
color: #fff;
}
.background3 {
background-color: blue;
z-index: 0;
position: relative;
margin-bottom: 0px;
padding: 6em 0;
border-radius: 0 0 10em 10em;
text-align: left;
width: 100%;
top: -20em;
color: #fff;
}
.text {
margin-top: 6em;
max-width: 50%;
padding: 0 6em;
}
<div class="background1">
<button class="btn1">Button</button>
</div>
<div class="background2">
<div class="text">
<h2> Text1 </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pellentesque, nibh sed tempus bibendum, lacus turpis dictum ipsum, nec consectetur diam nisi eget mauris. </p>
</div>
</div>
<div class="background3">
<div class="text">
<h2> Text2 </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pellentesque, nibh sed tempus bibendum, lacus turpis dictum ipsum, nec consectetur diam nisi eget mauris. </p>
</div>
</div>
Just change in border-radius and padding values to have the perfect curve that you want.
You can use border-bottom-left-radius and border-bottom-lright-radius or border-radius: 0px 0px xxxpx xxpx;
div {
height: 300px;
width: 300px;
border-bottom-right-radius: 200px;
border-bottom-left-radius: 200px;
background: black;
}
<div></div>
This question already has answers here:
How to apply padding to every line in multi-line text?
(5 answers)
Closed 3 months ago.
.wrapper {
display: flex;
flex-direction: column;
gap: 20px;
padding: 50px; }
.wide-container, .narrow-container {
flex: none;
background-color: #f7f7f7;
border-radius: 5px;
padding: 10px 20px;
box-shadow: 0 5px 35px rgba(0, 0, 0, 0.2);
border: 1px #c2c2c2 solid;
}
.wide-container {
width: 600px;
}
.narrow-container {
width: 300px;
}
.flex {
display: flex;
flex-wrap: wrap;
gap: 10px 0;
}
.text {
flex: none;
padding: 5px 2px;
background-color: salmon;
color: white;
}
<div class="wrapper">
<div class="wide-container">
<div class="flex"><span class="text">Lorem ipsum dolor sit amet consectetur, adipisicing elit. </span></div>
</div>
<div class="narrow-container">
<div class="flex"><span class="text">Lorem ipsum dolor sit amet consectetur, adipisicing elit. </span></div>
</div>
</div>
I need to apply some styles to piece of a text, and it should be inside of a flex box, because I need some of its features. The problem is that when there is not enough space, text will overflow:
So, I need to split text somehow, to keep the styling on a new line like this (did it manually here):
UPD:
Thanks for the answers, but the problem is a little bit more complex than it looks at first glance. Solution in answers (so far) leads to this result:
Which means that line breaks inside of a .text container. If you compare this result with the result I need (screenshot above), you will understand the issue.
use word-break:break-all; or word-break: break-word;
.wrapper {
display: flex;
flex-direction: column;
gap: 20px;
padding: 50px; }
.wide-container, .narrow-container {
flex: none;
background-color: #f7f7f7;
border-radius: 5px;
padding: 10px 20px;
box-shadow: 0 5px 35px rgba(0, 0, 0, 0.2);
border: 1px #c2c2c2 solid;
}
.wide-container {
width: 600px;
}
.narrow-container {
width: 300px;
}
.flex {
flex-wrap: wrap;
flex:none;
gap: 10px 0;
}
.text {
flex: none;
word-break: break-word;
padding: 5px 2px;
line-height:35px;
background-color: salmon;
color: white;
}
<div class="wrapper">
<div class="wide-container">
<div class="flex"><span class="text">Lorem ipsum dolor sit amet consectetur, adipisicing elit. </span></div>
</div>
<div class="narrow-container">
<div class="flex">
<span class="text">Lorem ipsum dolor sit amet consectetur, adipisicing elit. 3</span>
</div>
</div>
</div>
Remove flex from text class and it will work.
.text {
padding: 5px 2px;
background-color: salmon;
color: white;
}
https://codepen.io/IChoseTheRedPill/pen/zYaRjZb
Based on your description you are looking for the </br> HTML element. Just added a </br> in your example.
However, removing flex: none from your .text class is a much more elegant solution to your problem, as suggested in another answer.
In addition, to get the "highlight" effect that you want you can't apply a background-color to the whole .text class.
.wrapper {
display: flex;
flex-direction: column;
gap: 20px;
padding: 50px; }
.wide-container, .narrow-container {
flex: none;
background-color: #f7f7f7;
border-radius: 5px;
padding: 10px 20px;
box-shadow: 0 5px 35px rgba(0, 0, 0, 0.2);
border: 1px #c2c2c2 solid;
}
.wide-container {
width: 600px;
}
.narrow-container {
width: 300px;
}
.flex {
display: flex;
flex-wrap: wrap;
gap: 10px 0;
}
.text {
padding: 5px 2px;
line-height: 1.5;
color: white;
}
.highlight {
background-color: salmon;
}
<div class="wrapper">
<div class="wide-container">
<div class="flex"><span class="text"><span class="highlight">Lorem ipsum dolor sit amet consectetur, adipisicing elit. </span></span></div>
</div>
<div class="narrow-container">
<div class="flex"><span class="text"><span class="highlight">Lorem ipsum dolor sit amet consectetur, </span><span class="highlight">adipisicing elit.</span></span></div>
</div>
</div>
This worked correctly for me when flex was disabled
.text {
background-color: salmon;
color: white;
line-height: 2em!important;
padding: 3px 0px;
}
Not sure if flexbox is the correct way of going about this, but basically I am looking for a 2 column flexbox.
In the first part I want to put random text in and the width of this part will adapt and become the same size as the text (whatever the text is).
The second part is a dotted hr line, which I want it to basically take up whatever space is remaining on the right-hand side.
Then there'll be a 16px gap in between. Is this the correct way to go about it? Where am I going wrong?
Thanks for any help, much appreciated !
what i want to happen
Edit: Thanks to everyone who answered, they all worked great tbh, but the solution I chose allowed for some extra flexibility. Again, appreciate everyones time, I don't have enough 'reputation' to upvote everybody! =)
body {
font-family: Montserrat;
background-color: #f0f0f0;
color: #34363e;
}
.main {
height:100%;
width: 100%;
padding: 64px 0;
}
.container {
height:100%;
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.h2-container {
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
padding: 0 32px 16px;
margin: 0;
width: 1136px;
gap: 16px;
}
.h2-box {
width: 100%;
}
h2 {
text-align: left;
font-size: 27px;
margin: 0;
}
.hr-box {
width: 100%;
}
hr {
border: none;
border-top: 4px dotted #cccccc;
width: 100%;
height: fit-content;
}
p {
text-align: left;
font-size: 16px;
line-height: 24px;
padding: 0 32px;
margin: 16px 0;
}
<div class="main">
<div class="container">
<div class="h2-container">
<div class="h2-box"><h2 class="">This is a title sentance</h2></div>
<div class="hr-box"><hr></div>
</div>
<p class="">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo leo, interdum quis auctor at, congue a justo. Donec accumsan nulla id fringilla vulputate. Ut sed mauris pellentesque, venenatis dui quis, consectetur nisl.</p>
</div>
</div>
There are a couple of issue with the implementation. You are heading to the right direction but just need a little bit of a tweak
First of all, remove the width 100% on the h2-box and the dot box.
Add flex-grow: 1; to the dot box and you are good. This will force the element to span the rest of the remaining width.
I am not sure what is expected if your title is more than 1 line long but something to think about for you.
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
Not sure if you meant to set inline-flex, but display flex works just fine.
flex-direction defaults to row so this is not needed
flex-wrap defaults to nowrap so this is also not needed
I am also unsure where you want the dotted line with regards to the title on the left but you can align that vertically with ease using align-items. I have used this in the example below to align the dots to the bottom using align-items: flex-end;
body {
font-family: Montserrat;
background-color: #f0f0f0;
color: #34363e;
}
.main {
height:100%;
width: 100%;
padding: 64px 0;
}
.container {
height:100%;
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.h2-container {
display: flex;
padding: 0 32px 16px;
margin: 0;
width: 1136px;
gap: 16px;
align-items: flex-end;
}
h2 {
text-align: left;
font-size: 27px;
margin: 0;
}
.hr-box {
flex-grow: 1;
}
hr {
border: none;
border-top: 4px dotted #cccccc;
width: 100%;
height: fit-content;
}
p {
text-align: left;
font-size: 16px;
line-height: 24px;
padding: 0 32px;
margin: 16px 0;
}
<div class="main">
<div class="container">
<div class="h2-container">
<div class="h2-box"><h2 class="">This is a title sentance</h2></div>
<div class="hr-box"><hr></div>
</div>
<p class="">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo leo, interdum quis auctor at, congue a justo. Donec accumsan nulla id fringilla vulputate. Ut sed mauris pellentesque, venenatis dui quis, consectetur nisl.</p>
</div>
</div>
Remove width: 100%; on .h2-box and use either flex: none; or flex: 0 0 auto;.
body {
font-family: Montserrat;
background-color: #f0f0f0;
color: #34363e;
}
.main {
height:100%;
width: 100%;
padding: 64px 0;
}
.container {
height:100%;
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.h2-container {
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
padding: 0 32px 16px;
margin: 0;
width: 1136px;
gap: 16px;
align-items: center;
}
.h2-box {
flex: none;
/*flex: 0 0 auto;*/
}
h2 {
text-align: left;
font-size: 27px;
margin: 0;
}
.hr-box {
width: 100%;
}
hr {
border: none;
border-top: 4px dotted #cccccc;
width: 100%;
height: fit-content;
}
p {
text-align: left;
font-size: 16px;
line-height: 24px;
padding: 0 32px;
margin: 16px 0;
}
<div class="main">
<div class="container">
<div class="h2-container">
<div class="h2-box"><h2 class="">This is a title sentance</h2></div>
<div class="hr-box"><hr></div>
</div>
<p class="">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo leo, interdum quis auctor at, congue a justo. Donec accumsan nulla id fringilla vulputate. Ut sed mauris pellentesque, venenatis dui quis, consectetur nisl.</p>
</div>
</div>
I have another solution... Choose what is better!
You can remove the after your . You will have only the class .h2-box to make the style of your title.
After, you can use the styles for .h2-box :
flex-basis: content;
white-space: nowrap;
width:100%;
The CSS Flexbox property flex-basis lets you specify the desired initial size of a flex item before downsizing or redistributing the remaining space in their Flexbox container.
So you'll have :
body {
font-family: Montserrat;
background-color: #f0f0f0;
color: #34363e;
}
.main {
height:100%;
width: 100%;
padding: 64px 0;
}
.container {
height:100%;
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.h2-container {
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
padding: 0 32px 16px;
margin: 0;
width: 1136px;
gap: 16px;
}
.h2-box {
flex-basis: content;
white-space: nowrap;
width:100%;
}
h2 {
text-align: left;
font-size: 27px;
margin: 0;
}
.hr-box {
width: 100%;
}
hr {
border: none;
border-top: 4px dotted #cccccc;
width: 100%;
height: fit-content;
}
p {
text-align: left;
font-size: 16px;
line-height: 24px;
padding: 0 32px;
margin: 16px 0;
}
<div class="main">
<div class="container">
<div class="h2-container">
<h2 class="h2-box">This is a title sentance</h2>
<div class="hr-box"><hr></div>
</div>
<p class="">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo leo, interdum quis auctor at, congue a justo. Donec accumsan nulla id fringilla vulputate. Ut sed mauris pellentesque, venenatis dui quis, consectetur nisl.</p>
</div>
</div>
Don't set any widths from .h2-container down, display: flex; will take care of that. Control the size of the flexbox by setting widths, margins, and paddings on the parents, it will fill the parent width. You want the flexbox child that will fill the available space to have flex-grow: 1;.
body {
background-color: #f0f0f0;
color: #34363e;
}
.main {
height: 100%;
width: 100%;
padding: 64px 0;
}
.container {
height: 100%;
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.h2-container {
display: flex;
padding: 0 32px;
gap: 16px;
}
.h2-container .grow {
flex-grow: 1;
}
.h2-container h2 {
font-size: 27px;
}
.h2-container hr {
margin-top: 40px;
border: none;
border-top: 4px dotted #cccccc;
}
p {
text-align: left;
font-size: 16px;
line-height: 24px;
padding: 0 32px;
margin: 16px 0;
}
<div class="main">
<div class="container">
<div class="h2-container">
<div>
<h2>This is a title sentence</h2>
</div>
<div class="grow">
<hr>
</div>
</div>
<p class="">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo leo, interdum quis auctor at, congue a justo. Donec accumsan nulla id fringilla vulputate. Ut sed mauris pellentesque, venenatis dui quis, consectetur nisl.</p>
</div>
</div>
I need to make a border like
with html and css. I tried to do it with display table, with visibility hidden, but none of it worked!
<div id="border">
<div id="visible">
<p id="yellow">Просто выберите, что Вам нужно</p>
</div>
</div>
#yellow { color: #dbff12; }
#border { border: 30px solid black; visibility: hidden; }
#visible { position: relative; bottom: 50px; visibility: visible; }
upd: what I mean is that I need a two hollow places around yellow text like on a picture
In this case it's convenient to use fieldset element with associated legend:
fieldset {
border: 4px green solid;
}
fieldset legend {
padding: 0 10px;
}
<fieldset>
<legend>Просто выберите, что вам нужно</legend>
<div>
Оформить тендер и т.п.
</div>
</fieldset>
Try This:
fieldset {
width: 300px;
border:3px solid skyblue;
}
legend {
color: orange;
padding: 0 10px;
}
span {
border-bottom: 1px dashed;
margin-right: 50px;
}
<fieldset>
<legend>Просто выберите, что Вам нужно</legend>
<span>Other Text</span>
<span>Other Text</span>
</fieldset>
You could also use a real title, flex to draw the top borders and the other borders from the container itself....
html {
min-height: 100%;
background: linear-gradient(to top left, rgba(0, 0, 0, 0.3), rgba(0, 125, 255, 0.5)), url(http://lorempixel.com/800/600/people/9) top center / cover;
}
[data-fieldset] {
width: 600px;
font-size: 20px;
color: rgba(15, 215, 255, 0.9);
text-shadow: 1px 1px 1px black;
margin: 4em auto 1em;
padding: 1em;
/* prepare border */
border: solid 10px rgba(15, 215, 255, 0.4);
border-top: none;
}
[data-fieldset] h1 {
font-size: 40px;
height: 40px;
line-height: 40px;
/* reset in position title */
margin: -35px -20px 1em;
/* prepare the pseudo behavior */
display: flex;
align-items: center;
color: rgba(255, 215, 16, 0.7);
}
/* draw the tops border via pseudo flex children */
[data-fieldset] h1:before,
[data-fieldset] h1:after {
content: '';
flex: 1;
background: rgba(15, 215, 255, 0.4);
height: 10px;
}
/* give some space to text */
[data-fieldset] h1:before {
margin-right: 0.5em;
}
[data-fieldset] h1:after {
margin-left: 0.5em;
}
<div data-fieldset>
<h1>My example</h1>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p>
</div>
i made two buttons, with border: 2px solid #color, after I hover on them, the border vanishes and the button goes 2px down. I just made :hover margin2 px more than the normal one. Everything is okay, but the only problem is that when I hover one of my buttons, both goes these 2px down. What's wrong?
Cheers.
This is my html code:
<div class="slide-wrapper">
<h2>We are <span>cool</span> kids</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut porta, nulla sit amet rutrum finibus, ligula orci.</p>
Videos
Sign for a newsletter
</div>
And this is my css:
.btn {
padding: 16px 38px;
margin-right: 30px;
border-radius: 5px;
display: inline-block;*/
}
.btn:last-child {
margin-right: 0;
}
.btn-show {
background: #4183d7;
box-shadow: 0 2px #446cb3;
}
.btn-sign {
background-color: #87d37c;
box-shadow: 0 2px #7ebc74;
}
.btn-show:hover,
.btn-sign:hover,
.btn-newsletter:hover {
margin-top: 2px;
box-shadow: none;
}
The issue is display: inline-block defaults to the baseline. So when you push one button down 2px's the other one is going by default (since there is 2 more pixels of space). Set the vertical alignment to default to top:
.btn {
padding: 16px 38px;
margin-right: 30px;
border-radius: 5px;
display: inline-block;
vertical-align: top; //add
}
FIDDLE