hi all i am new to html and css i got a simple question:
i wrote this html code
<div class="ourtlimg">
<div class="name1"><h1>Daniel Martin</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.<br>Libero aperiam commodi similique labore neque dicta.</p></div>
<div class="name2"><h1>Craig Nobel</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.<br>Libero aperiam commodi similique labore neque dicta.</p></div>
<div class="name3"><h1>Nicole Mark</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.<br>Libero aperiam commodi similique labore neque dicta.</p></div>
</div>
i made a grid-template-area for the class name1,name2,name3 in 6times 1fr repeat as{port1 port1 port2 port2 port3 port3}to display in one line and when i give each class one of three grid areas it display like the image below.I want to display them in one line with the grid system can you help please.I want them across the page instead of down the pageenter image description here
i added this css for the wrapper:
.wrapper{
display: grid;
grid-template-columns: repeat(6,1fr);
grid-template-areas:
'header header header header header header'
'navbar navbar navbar navbar navbar navbar'
'welsec welsec welsec welsec welsec welsec'
'tlinfo tlinfo tlinfo tlinfo tlinfo tlinfo'
'port1 port1 port2 port2 port3 port3'
;
}
and this for the classes in code:
.name1{
grid-area: port1;
float: left;
}
.name2{
grid-area: port2;
float: left;
}
.name3{
grid-area: port3;
float: left;
}
This css code will do all the work =)
.ourtlimg {
display: flex;
justify-content: flex-start;
display: -webkit-flex;
-webkit-justify-content: flex-start;
}
<div class="ourtlimg">
<div class="name1">
<h1>Daniel Martin</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.<br>Libero aperiam commodi similique labore neque dicta.</p>
</div>
<div class="name2">
<h1>Craig Nobel</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.<br>Libero aperiam commodi similique labore neque dicta.</p>
</div>
<div class="name3">
<h1>Nicole Mark</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.<br>Libero aperiam commodi similique labore neque dicta.</p>
</div>
</div>
Related
.mn2 {
display: grid;
grid-template-columns: 30vh 30vh;
grid-template-rows: 30vh 30vh;
grid-gap: 5px 5px;
height: 50vh;
border: 3px dashed red;
}
<div class="mn2">
<div class="box2">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consectetur doloremque labore corrupti atque.
</div>
<div class="box3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque error maiores asperiores! Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</div>
<div class="box4">
Lorem ipsum dolor sit amet consectetur adipisicing elit
</div>
<div class="box5">Lorem ipsum dolor, sit amet consectetur adipisicing elit. A sit quaerat error ad, ut nulla.</div>
</div>
You should let the content define box height & widths. By setting everything to auto..
you can set height of the boxes with grid-auto-rows: [first-row-height] [second-row-height]; for eg
grid-auto-rows: 200px 200px;
.mn2 {
display: grid;
grid-template-columns: auto auto;
grid-auto-rows: 200px 200px;
grid-gap: 5px 5px;
height: auto;
}
.mn2>div {
padding: 1rem;
background-color: gray;
}
<div class="mn2">
<div class="box2">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consectetur doloremque labore corrupti atque.
</div>
<div class="box3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque error maiores asperiores! Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</div>
<div class="box4">
Lorem ipsum dolor sit amet consectetur adipisicing elit
</div>
<div class="box5">Lorem ipsum dolor, sit amet consectetur adipisicing elit. A sit quaerat error ad, ut nulla.</div>
</div>
Try this:
.mn2 {
display: grid;
grid-template-columns: 24% 24% 24% 24%;
grid-gap: 5px 5px;
height: auto;
border: 3px dashed red;
}
<div class="mn2">
<div class="box2">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Consectetur doloremque labore corrupti atque.
</div>
<div class="box3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque error maiores asperiores! Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</div>
<div class="box4">
Lorem ipsum dolor sit amet consectetur adipisicing elit
</div>
<div class="box5">Lorem ipsum dolor, sit amet consectetur adipisicing elit. A sit quaerat error ad, ut nulla.</div>
</div>
A container with flex and centered horizontally and vertically
I create two divs which are placed column wise
Now I have a third div which is given a flex with a row and needs to be displayed space between but space between does not work
here is the code
<style>
.flex{
width: 100vw;
height: 100vh;
border: 1px solid black;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.flex1,.flex2{
width: 300px;
border: 1px solid black;
}
.flex3{
display: flex;
justify-content: space-between;
}
</style>
<body>
<div class="flex">
<div class="flex1">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Recusandae alias dolorum cum sunt necessitatibus facere eveniet corrupti fugit fuga excepturi.</div>
<div class="flex2">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Commodi vero iste voluptates, exercitationem voluptate cum id quo rem placeat nemo.</div>
<div class="flex3">
<div class="flex4">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Odio, cum.
</div>
<div class="flex5">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Porro, nostrum.
</div>
</div>
</div>
</body>
.flex {
width: 100vw;
height: 100vh;
border: 1px solid black;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.flex1,
.flex2 {
width: 300px;
border: 1px solid black;
}
.flex3 {
display: flex;
justify-content: space-between;
}
<body>
<div class="flex">
<div class="flex1">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Recusandae alias dolorum cum sunt necessitatibus facere eveniet corrupti fugit fuga excepturi.</div>
<div class="flex2">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Commodi vero iste voluptates, exercitationem voluptate cum id quo rem placeat nemo.</div>
<div class="flex3">
<div class="flex4">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Odio, cum.
</div>
<div class="flex5">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Porro, nostrum.
</div>
</div>
</div>
</body>
Flex items are only as wide as their content by default, if align-items is something other than the default stretch. You need to give flex3 a width, presumably 100%.
.flex {
width: 100vw;
height: 100vh;
border: 1px solid black;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.flex1,
.flex2 {
width: 300px;
border: 1px solid black;
}
.flex3 {
width: 100%; /* <=== */
display: flex;
justify-content: space-between;
}
<div class="flex">
<div class="flex1">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Recusandae alias dolorum cum sunt necessitatibus facere eveniet corrupti fugit fuga excepturi.
</div>
<div class="flex2">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Commodi vero iste voluptates, exercitationem voluptate cum id quo rem placeat nemo.
</div>
<div class="flex3">
<div class="flex4">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Odio, cum.
</div>
<div class="flex5">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Porro, nostrum.
</div>
</div>
</div>
I have to vertically align the elements of an unknown number of columns that contains of a headline, a description and a button.
Per default every element takes as much space as it's content uses
but the elements should all be aligned. So all headlines, descriptions and buttons should begin at the same height.
I have the feeling that flexbox might not help here but a CSS grid might or maybe using display: table and turn everything in such structures but sadly I cannot get it to work.
The current markup looks like this
<ul>
<li class="columns large-4 small-12 medium-4 s-pb-30">
<h3>Some headline</h3>
<div>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing
elit. Nostrum facilis praesentium quaerat,
laboriosam ratione eos. Lorem ipsum dolor sit amet
consectetur adipisicing elit. Nostrum facilis
praesentium quaerat, laboriosam ratione eos. Lorem
ipsum dolor sit amet consectetur adipisicing elit.
Nostrum facilis praesentium quaerat, laboriosam
ratione eos.
</p>
<a class="button btn-styled center-block--btn" href="/">Foo</a>
</div>
</li>
<li class="columns large-4 small-12 medium-4 s-pb-30">
<h3>Another headline</h3>
<div>
<p style="height: 360px;">
Lorem ipsum dolor sit amet consectetur adipisicing
elit. Nostrum facilis praesentium quaerat,
laboriosam ratione eos. Lorem ipsum dolor sit amet
consectetur adipisicing elit. Nostrum facilis
praesentium quaerat, laboriosam ratione eos.
</p>
<a class="button btn-styled center-block--btn" href="/">Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar
Bar Bar </a>
</div>
</li>
<li class="columns large-4 small-12 medium-4 s-pb-0">
<h3 class="title">Surprisingly here's a third headline that should be aligned with the other two</h3>
<div>
<p style="height: 360px;">
Lorem ipsum dolor sit amet consectetur adipisicing
elit. Nostrum facilis praesentium quaerat,
laboriosam ratione eos.
</p>
<a class="button btn-styled center-block--btn" href="/">Baz</a>
</div>
</li>
</ul>
You can define an implicit CSS grid and then simply use grid-auto-flow: column so that the grid fills itself up column-first (instead of row-first as per default behaviour).
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto 1fr auto;
grid-auto-flow: column;
Remember that 1fr is greedy while auto is not, so we allow the middle row (where your <p> tags are) to grow as much as possible.
This however requires you to "unpack" your individual <li> content so that all elements in the grid are siblings of each other, due to the lack of support for CSS subgrid in most browsers at the time of writing.
For the button, you can simply use fit-content for both width and height to ensure that it "shrink-wrap" its content, and use margin: 0 auto to center it horizontally inside the grid.
See proof-of-concept below:
.grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto 1fr auto;
grid-auto-flow: column;
text-align: center;
}
.grid a {
display: block;
background-color: steelblue;
color: #fff;
border-radius: 100vh;
width: fit-content;
height: fit-content;
margin: 0 auto;
padding: .5em 1em;
text-decoration: none;
}
<div class="grid">
<h3>Some headline</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos.
</p>
Foo
<h3>Another headline</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos.
</p>
Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar
<h3 class="title">Surprisingly here's a third headline that should be aligned with the other two</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos.
</p>
Baz
</div>
This question already has answers here:
CSS-only masonry layout
(4 answers)
Closed 7 months ago.
I don't Know , if there is a solution, using css-grid?,
i have tried giving a max width to note-card but i dont want to remove height:max-content; this is because what if note has more than 30 words. thanks
.flex-container{
justify-content: flex-start;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-content: flex-start;
}
here is my code
body{
background-color:black;
}
.flex-container div {
display: inline-block;
min-height: 1em;
height: max-content;
width: 12em;
padding: 5px;
border: 1px solid white;
border-radius: .5em;
margin: 4px;
color:white;
}
.flex-container{
justify-content: flex-start;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-content: flex-start;
}
<div class="flex-container">
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, enim?</div>
<div>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorem animi similique placeat voluptatibus
nihil cupiditate!</div>
<div>Lorem ipsum dolor sit amet consectetur, adipisicing elit. At quis odit tenetur adipisci?</div>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum, ab.</div>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Magnam distinctio dolores fuga sit culpa provident
modi ex ipsa aspernatur maiores?</div>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus doloribus exercitationem ex inventore
vel, quo natus esse quos veritatis deserunt hic commodi architecto suscipit ad, ipsa, nulla sapiente totam
dicta.</div>
<div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur dolorum similique dolores, est sequi
autem?</div>
</div>
So CSS has a columns property that let's you achieve this very simply, see solution below. Compatible with everything, even Internet Explorer. More info on MDN
:root { --gap: .5rem }
.columnLayout {
columns: 2;
column-gap: var(--gap);
padding: var(--gap) var(--gap) 0 var(--gap);
}
.columnLayout div {
display: inline-block;
margin-bottom: var(--gap);
}
/* BELOW STYLES FOR STYLING ONLY -- NOT RELEVANT TO ANSWER */
* { box-sizing: border-box } body{ background-color: black; color: white; font: 16px sans-serif; margin: 0 } .columnLayout div { border: 1px solid currentColor; border-radius: .5rem; padding: .5rem }
<div class="columnLayout">
<div>1. Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis, enim?</div>
<div>2. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorem animi similique placeat voluptatibus nihil cupiditate!</div>
<div>3. Lorem ipsum dolor sit amet consectetur, adipisicing elit. At quis odit tenetur adipisci?</div>
<div>4. Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum, ab.</div>
<div>5. Lorem ipsum dolor sit amet consectetur adipisicing elit. Magnam distinctio dolores fuga sit culpa provident modi ex ipsa aspernatur maiores?</div>
<div>6. Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus doloribus exercitationem ex inventore vel, quo natus esse quos veritatis deserunt hic commodi architecto suscipit ad, ipsa, nulla sapiente totam dicta.
</div>
<div>7. Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur dolorum similique dolores, est sequi autem?
</div>
</div>
Alternatively, if you want to keep the left-right flow then you will need JavaScript for a "masonry" layout, if you can't / don't want to write the JS yourself there is a widely used library for this called Masonry JS
I don't understand why 2nd div is not up of 1st div. I want they 2 div perfectly set as like my image direction. already i try display block but not working. i don't know why main problem. already i have many research, but all fail. so please help me to solution my problem. advanced thanks and love from my top heart.
`
.testimonial .content{
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.testimonial .content .testimonialBx{
max-width: calc(50% - 40px);
padding: 60px 40px;
margin: 20px;
background: #2196f3;
}
<section class="testimonial">
<div class="heading">
<h2>Testimonial</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure!</p>
</div>
<div class="content">
<div class="testimonialBx">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Suscipit necessitatibus culpa magnam ipsum illum provident nostrum id temporibus? Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat similique nostrum harum! Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime quos quo qui in.</p>
<h3>Someone Famous <br><span>Creative Designer</span></h3>
</div>
</div>
<div class="content">
<div class="testimonialBx">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Suscipit necessitatibus culpa magnam ipsum illum provident nostrum id temporibus? Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat similique nostrum harum! Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime quos quo qui in.</p>
<h3>Someone Famous <br><span>Creative Designer</span></h3>
</div>
</div>
</section>
`
Wrap those 2 divs in 1 div and make it as flex.
Updated Code
.testimonial .content {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.testimonial .content .testimonialBx {
max-width: calc(50% - 40px);
padding: 60px 40px;
margin: 20px;
background: #2196f3;
}
.container {
display: flex;
}
<!DOCTYPE html>
<html>
<head> </head>
<body>
<section class="testimonial">
<div class="heading">
<h2>Testimonial</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure!</p>
</div>
<div class="container">
<div class="content">
<div class="testimonialBx">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Suscipit necessitatibus culpa magnam ipsum illum provident nostrum id temporibus? Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat similique nostrum harum! Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime quos quo qui in.</p>
<h3>Someone Famous <br><span>Creative Designer</span></h3>
</div>
</div>
<div class="content">
<div class="testimonialBx">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Suscipit necessitatibus culpa magnam ipsum illum provident nostrum id temporibus? Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat similique nostrum harum! Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime quos quo qui in.</p>
<h3>Someone Famous <br><span>Creative Designer</span></h3>
</div>
</div>
</div>
</section>
</body>
</html>
Answer from #nagendraNag is ideal. I would just remove the max-width
max-width: calc(50% - 40px);