I'm building a new website (with React TypeScript an Tailwind) for my agency, and we have a list of articles (News) which looks like this:
As you can see, we have 3 different sizes of cards to display.
My API request returns "small" / "medium" / "large" in the object of the article to say which kind of card the specific article need.
My question is:
how can I deal this ?
How can I say to my browser to not render with the order of objects received, and to fill the page "properly" ?
By properly, I mean not letting "holes" in the page.
Here is an try with grids :
<div className="col-span-2 bg-white flex items-center justify-center">
<div className="relative w-5/12">
<img src="./assets/images_mock/GoogleMyBusiness.png" alt="" />
<span className="absolute top-2 left-2 rounded-md bg-purple-800 text-white text-xs p-1 uppercase">TEST</span>
</div>
<div className="w-7/12">
<h3 className="font-NexaBlack text-xl">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</h3>
<p className="text-gray-800 text-sm mt-2">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
<button className="rounded-full mt-4 px-4 py-2 border border-gray-300 text-gray-500">
<Link to={'#'}>read article</Link>
</button>
</div>
</div>
<div className="col-span-4 bg-white flex items-center justify-center">
<div className="relative w-1/2">
<img src={RectangleNews} alt="" />
<span className="absolute top-2 left-2 rounded-md bg-purple-800 text-white text-xs p-1 uppercase">TEST</span>
</div>
<div className="w-1/2">
<h3 className="font-NexaBlack text-xl">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</h3>
<p className="text-gray-800 text-sm mt-2">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
<button className="rounded-full mt-4 px-4 py-2 border border-gray-300 text-gray-500">
<Link to={'#'}>read article</Link>
</button>
</div>
</div>
<div className="col-span-2 bg-white flex items-center justify-center">
<div className="relative w-5/12">
<img src="./assets/images_mock/InterkabNews.png" alt="" />
<span className="absolute top-2 left-2 rounded-md bg-teal-500 text-white text-xs p-1 uppercase">Interkab</span>
</div>
<div className="w-7/12">
<h3 className="font-NexaBlack text-xl">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</h3>
<p className="text-gray-800 text-sm mt-2">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
<button className="rounded-full mt-4 px-4 py-2 border border-gray-300 text-gray-500">
<Link to={'#'}>read article</Link>
</button>
</div>
</div>
but this code does not re-arrange the divs to fit the width of the screen.
I tried to be as clear as possible.
Hope someone have a solution.
Thank you mates !
Related
I hope YOU guys are doing good
I have just started learning Flexbox from CSS Tricks and some YT channels.
But when I used justify-content:space-around | space-between | space-evenly. None of them seems to work out.
And I could not find out the problem.
I would really appreciate if anyone can help me out.
.container-1 {
display: flex;
flex-direction: row-reverse;
// flex-wrap: wrap;
justify-content:space-between;
}
<html>
<body>
<div class="container-1">
<div class="item-1">
<h1>
Box One
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="item-2">
<h1>
Box Second
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="Item-3">
<h1>
Box Third
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
</div>
</body>
</html>
I want to make a responsive grid of columns just like in this picture. That's what I want it to look like in desktop mode.
In the mobile mode, I want it to shrink and stack on top of each other when I resize the browser.
How do I do this?
Here's my code:
.help-icons {
height: 10rem;
width: 10rem;
}
.icon-one,
.icon-two,
.icon-three,
.icon-four,
.icon-five,
.icon-six {
border: 1px solid $color-silver;
}
.dark-text {
font-size: 0.7rem;
}
.light-text {
color: $color-boulder;
font-size: 0.5rem;
}
.help-icons
.icon-one
span.wfs-pie-chart
p.dark-text Some Text
p.light-text Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
.icon-two
span.wfs-user
p.dark-text Some Text
p.light-text Imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque.
.icon-three
span.wfs-git-branch
p.dark-text Some Text
p.light-text Mauris nunc congue nisi vitae suscipit tellus mauris a diam.
.icon-four
span.wfs-database
p.dark-text Some Text
p.light-text Fringilla urna porttitor rhoncus dolor purus non enim praesent elementum.
.icon-five
span.wfs-trending-up
p.dark-text Some Text
p.light-text Egestas sed sed risus pretium quam vulputate dignissim suspendisse in.
.icon-six
span.wfs-cloud
p.dark-text Some Text
p.light-text Proin fermentum leo vel orci porta non pulvinar neque laoreet.
Thanks!
EDIT: I have media queries for the mobile, tablet, and desktop already:
//- Mobile
#media screen and (min-width: 15rem){
}
// Tablet
#media (min-width: 768px) {
}
// Desktop
#media (min-width: 1280px) {
}
hope this would be useful.
.help-icons {
width: 100%;
}
.help-icons > div {
width: 10rem;
float: left;
margin-left: 10px;
}
.icon-one,
.icon-two,
.icon-three,
.icon-four,
.icon-five,
.icon-six {
border: 1px solid $color-silver;
}
.dark-text {
font-size: 0.7rem;
}
.light-text {
color: $color-boulder;
font-size: 0.5rem;
}
<div class="help-icons">
<div class="icon-one">
<span class="wfs-pie-chart"></span>
<p class="dark-text"> Some Text</p>
<p class="light-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
</div>
<div class="icon-two">
<span class="wfs-user"></span>
<p class="dark-text"> Some Text</p>
<p class="light-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
</div>
<div class="icon-three">
<span class="wfs-git-branch"></span>
<p class="dark-text"> Some Text</p>
<p class="light-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
</div>
<div class="icon-four">
<span class="wfs-database"></span>
<p class="dark-text"> Some Text</p>
<p class="light-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
</div>
<div class="icon-five">
<span class="wfs-trending-up"></span>
<p class="dark-text"> Some Text</p>
<p class="light-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
</div>
<div class="icon-six">
<span class="wfs-cloud"></span>
<p class="dark-text"> Some Text</p>
<p class="light-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
</div>
</div>
You can make use of Bootstrap's row and column classes. This way it is not necessary for any media queries as Bootstrap does it all for you. Just make sure you have Bootstrap installed in your project, then you can make use of the following code in your html:
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="row">
</div>
<div class="row">
</div>
</div>
<div class="col-sm-4">
<div class="row">
</div>
<div class="row">
</div>
</div>
<div class="col-sm-4">
<div class="row">
</div>
<div class="row">
</div>
</div>
</div>
</div>
You can check out Bootstrap's documentation for different screen size breakpoints: https://getbootstrap.com/docs/4.1/layout/grid/. You can also change the width and height of rows and columns to your liking, by targeting the Bootstrap classes or adding custom classes to the Bootstrap classes.
I'm using Bootstrap 4 and trying to have columns which are the same height (which I thought Bootstrap did by default).
This is my markup:
<div class="row">
<div class="col-md-4">
<div class="table-heading">
Lorem ipsum dolor sit amet
</div>
<div class="table-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
</div>
</div>
<div class="col-md-4">
<div class="table-heading">
Lorem ipsum dolor sit amet, consectetur adipiscing
</div>
<div class="table-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore Lorem ipsum dolor sit amet, consectetur
</div>
</div>
<div class="col-md-4">
<div class="table-heading">
Lorem ipsum dolor
</div>
<div class="table-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
</div>
</div>
</div>
And the result is this:
I'd like the purple headings to align, as well as the columns themselves.
Here is the CSS I'm using:
.table-heading {
text-align: center;
font-weight: bold;
vertical-align: middle;
color:white;
background-color: #7b2265;
padding:10px;
}
.table-text {
padding:10px;
background-color: white !important;
}
Here's a Pen: https://codepen.io/anon/pen/ZxeLpO
Edit:
Since you want both, the titles AND the body text parts to be the same height while also making sure that they are responsive, you can use the re-ordering classes in combination with the h-100 class (height:100%) to achieve the desired effect:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.table-heading {
text-align: center;
font-weight: bold;
vertical-align: middle;
color:white;
background-color: #7b2265;
padding:10px;
}
</style>
<div class="container bg-light p-3">
<div class="row">
<div class="col-md-4">
<div class="table-heading h-100">
Title1 Lorem ipsum dolor sit amet
</div>
</div>
<div class="col-md-4 order-md-1">
<div class="bg-white h-100 px-3">
Body1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
</div>
</div>
<div class="col-md-4">
<div class="table-heading h-100">
Title2 Long, long, veeery long! Lorem ipsum dolor sit amet
</div>
</div>
<div class="col-md-4 order-md-2">
<div class="bg-white h-100 px-3">
Body2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore. Body2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore.
</div>
</div>
<div class="col-md-4">
<div class="table-heading h-100">
Title3 Short Lorem
</div>
</div>
<div class="col-md-4 order-md-3">
<div class="bg-white h-100 px-3">
Body3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
</div>
</div>
</div>
</div>
The classes like order-md-1 etc. only kick in on screens that are medium (md) or larger. In this case here, it has the effect of the body part columns being pushed what looks like the next row. While on smaller screens, no re-ordering happens and therefore, on smaller screens, the columns appear in the same order as they are in the HTML.
If you add h-100 as a class to the divs with col-md-4 as a class then it will behave as you expect.
h-100 is the bootstrap4 utility class to set the height to 100%, which will make all the columns have a height equal to the row they all reside in.
<div class="col-md-4 h-100">
...
</div>
Update, you can add height: 100% to the css class .table-text to fill the empty space.
I'm making a row with 2 equal width columns. First one contains text and the second one an image. On lg/md/sm screen text will go left and the image in right as below code:
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="text-block">
<h1>WordPress Theme Development</h1>
<h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</h3>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="img-block text-center">
<img src="assets/pics/wordpress.png" alt="WordPress">
</div>
</div>
</div>
But on xs screen, I want the image top and text at the bottom. That's why I tried this below code which I followed from here but it's not working
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-push-12">
<div class="text-block">
<h1>WordPress Theme Development</h1>
<h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</h3>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-pull-12">
<div class="img-block text-center">
<img src="assets/pics/wordpress.png" alt="WordPress">
</div>
</div>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-md-push-6">
<div class="img-block text-center">
<img src="https://dummyimage.com/500x200/000/fff" alt="WordPress">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-md-pull-6">
<div class="text-block">
<h1>WordPress Theme Development</h1>
<h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</h3>
</div>
</div>
</div>
Im having trouble getting my page aligned properly. It seems no matter what i do none of the rows align the way i would like them to. either the images are off misaligned from the main img or captions below those images don't line up properly.
I would like the arrows to line up at the same level as the services/faq/contact and the paragraphs below those to be aligned to the left. But it seems i cant achieve this without playing with margins in 10 different places.
http://www.bootply.com/bilUlNXdnE
http://i.imgur.com/vnE3N3U.jpg
Well, this is not just an answer but I just want to guide you through the right direction..
I see you created separate div for Headers, arrows and descriptions. I don't think that is the right way to do it. Rather, you can make one div for columns (including header, image, arrows and description)..
Your Code :
<div class="row " id="icons">
<div class="col-md-4">
<img src="img/bottle.gif" class="image-responsive " id="spray" width="300" alt="" height="240">
</div><!--/#Spray-->
<div class="col-md-4">
<img src="img/vacuum.gif" class="image-responsive " id="vacuum" width="300" alt="" height="240">
</div><!--/#Vacuum-->
<div class="col-md-4">
<img src="img/mop.gif" class="image-responsive " id="mop" alt="" width="300" height="240">
</div><!--/#Mop-->
</div>
<div class="row" id="captions">
<div class="col-md-4">
<h3>Services</h3>
</div>
<div class="col-md-4">
<h3>FAQ</h3>
</div>
<div class="col-md-4">
<h3>Contact</h3>
</div>
</div>
<div class="row" id="arrows">
<div class="col-md-4">
<img src="img/arrow8.gif" class="image-responsive" id="arrow1" alt="" width="18" height="18">
</div>
<div class="col-md-4">
<img src="img/arrow8.gif" class="image-responsive" id="arrow2" alt="" width="18" height="18">
</div>
<div class="col-md-4">
<img src="img/arrow8.gif" class="image-responsive" id="arrow3" alt="" width="18" height="18">
</div>
</div>
<div class="row" id="blurbs">
<div class="col-md-4" id="blurb1">
<div class="services"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p></div>
</div><!--/#Spray-->
<div class="col-md-4" id="blurb2">
<div class="FAQ"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p></div>
</div><!--/#Vacuum-->
<div class="col-md-4" id="blurb3">
<div class="contact"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p></div>
</div><!--/#Mop-->
</div>
This is a loose coupling between elements that are in same context (e.g. Header, Image, description etc.).
I would recommend you to code something like this -
<div class="col-md-4">
<img src="img/bottle.gif" class="image-responsive " id="spray" width="300" alt="" height="240">
<div class="row">
<div class="col-md-8">
<h3>FAQ</h3>
</div>
<div class="col-md-4"><img src="img/arrow8.gif" class="image-responsive" id="arrow1" alt="" width="18" height="18"> </div>
</div>
<div class="services">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</div>
</div>
<!--/#Column1-->
<div class="col-md-4">
<img src="img/vacuum.gif" class="image-responsive " id="spray" width="300" alt="" height="240">
<div class="row">
<div class="col-md-8">
<h3>FAQ</h3>
</div>
<div class="col-md-4"><img src="img/arrow8.gif" class="image-responsive" id="arrow1" alt="" width="18" height="18"> </div>
</div>
<div class="FAQ">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</div>
</div>
<!--/#Column2-->
<div class="col-md-4">
<img src="img/mop.gif" class="image-responsive " id="spray" width="300" alt="" height="240">
<div class="row">
<div class="col-md-8">
<h3>FAQ</h3>
</div>
<div class="col-md-4"><img src="img/arrow8.gif" class="image-responsive" id="arrow1" alt="" width="18" height="18"> </div>
</div>
<div class="contact">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</div>
</div>
<!--/#Column3-->
This way, you don't have to play much with margin and stuff..
Edited example : http://www.bootply.com/ZnylDYHd6x