bootstrap v4 cards fixed with - responsive-design

I would like to set a grid with a set of 3 w-50 cards in each row on desktop devices, and one card per row on smaller devices.
But, if a user responsively makes the browser window smaller, I would like the cards to stay the same width on the desktop, and have the space between them get smaller, rather than the cards themselves get narrower.
Also, is it possible to have the cards be w-50 on desktop, but w-75 on smaller devices.
Sample code:
<div class="row">
<div class="col-sm-12 col-lg-4 " >
<div class="card w-50 ">
<div class="card-header">
Featured
</div>
<div class="card-body ">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-sm-12 col-lg-4">
<div class="card w-50">
<div class="card-header">
Featured
</div>
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
</div>
<div class="col-sm-12 col-lg-4 ">
<div class="card w-50">
<div class="card-header">
Featured
</div>
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
Go somewhere
</div>
</div>
</div>
</div>

Simple answer: No
If you want the cards to stay the same when user resizes the window, I don't think it's possible with .w-*, because that's relative percentage width of the whole row being 100%. The cards will shrink as user resizes the windows, unless you allow overflow on the row.
For the same reason I don't know why/how you come up with a thought that you can have 3 w-50 cards in a row on desktop devices. The maximum numbers of w-50 cards you can have in a row is just 2: 100% / 50% = 2.
To have the cards stay the same width as long as they can, you might have to use absolute units such aspx or rem.
<div class="cards">
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</div>
One card per row on smaller devices
There is noting you need to do here as by default <div> is set to 100% width. You might just add margins to each card to make them look nice:
.cards .card {
margin-bottom: 1rem;
}
3 cards per row on larger devices
I take larger devices as 576px and large. You can setup media breakpoints there and have .cards displayed as flexbox. And set a fixed with for the cards inside.
#media (min-width: 576px) {
.cards {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
.cards .card {
width: 13rem;
}
}
https://jsfiddle.net/davidliang2008/woxsv4nm/24/
How to come up a right width?
Setting the right width of the cards is tricky though. My 2 cents: you might want to setup a right width of the cards for different breakpoints so that there won't be too much space in between cards.
What if you allow overflow?
To force the width of cards to be 50% and have 3 of them in a row, the row must be overflowed. By default, the flexbox children will shrink if there is not enough space. To enforce 50% width, you have to turn that off by setting flex-shrink: 0;:
#media (min-width: 576px) {
.cards {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}
.cards .card {
width: 50%;
flex-shrink: 0;
}
}
https://jsfiddle.net/davidliang2008/woxsv4nm/26/
But in this case, there is no way you still have gaps between cards.

Related

Display hidden button in card when hovering

I would like to display the hidden button content in my card when hovering over it. I am currently attempting to use the adjacent sibling selector to do this, by connecting a hover element (the card) to another element (the hidden button) to achieve this. The code is is as follows
<div class="container">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-3">
<div class="card-white">
<div class="secret-button">
<img src="images/approve.svg" id="i">Hidden button
</div>
<img src="images/chococake2.jpg"
style="width: 245px; height: 191px;"
/>
<h3>Recipe</h3>
<h4>German Chocolate Cake</h4>
<p>5/5</p>
<p>reviews</p>
<p>make it again</p>
</div>
</div>
My hidden button is currently set as display none on my css purposely, but I would like to then make it visible by doing the below
.card-white:hover{
background-color: #8C8C8C;
border: 5px solid green;
text-decoration: none;
}
.secret-button{
display: none;
}
.card-white:hover + .secret-button{
display: block;
}
The issue is that despite my attempt above, this is not changing my html page. The plus button appears as orange on my sublime text, which suggests to me it does not like or recognize the selector as valid css code for some reason.
I think the main problem is that I may need to restructure the html/css as these two elements may not be proper siblings, but just want to know how best to go about this.

tailwind how to make nav tabs always show scroll bar?

I have a nav with tabs.
But because it has a lot of tabs the user needs to scroll right to see them all.
The issue is on first load the user might not know this and think what is shown is all the tabs.
So I want to show a scrollbar on it all the time.
<nav
className="-mb-px flex space-x-8 overflow-x-auto"
aria-label="Tabs"
>
I have tried:
<nav
className="-mb-px flex space-x-8 overflow-x-scroll"
aria-label="Tabs"
>
But it did nothing.
I would also like to style the scrollbar with a smaller height and a different main and background color for it if possible.
The nav itself exists inside:
<div className=" pb-3 lg:fixed z-10 bg-white grid grid-cols-1 mr-16 ">
Thank you
For the scrollabar to show all the time,Use overflow-x-scrollAnd Make sure you add the fixed width to the parent element.
For styling scrollbar ,Tailwind CSS doesn't provide a built-in way . However, you can use the various ::-webkit-scrollbar pseudo-elements to style it.
so add the following in your main index.css file
#layer components {
.scrollbar::-webkit-scrollbar {
width: 15px;
height: 15px;
}
.scrollbar::-webkit-scrollbar-track {
border-radius: 100vh;
background: #f7f4ed;
}
.scrollbar::-webkit-scrollbar-thumb {
background: #e0cbcb;
border-radius: 100vh;
border: 3px solid #f6f7ed;
}
.scrollbar::-webkit-scrollbar-thumb:hover {
background: #c0a0b9;
}
}
So the final code goes like:
<div className=" pb-3 lg:fixed z-10 grid grid-cols-1 mr-16 w-64 ">
<nav
className="-mb-px flex text-green-400 space-x-8 overflow-x-scroll scrollbar"
aria-label="Tabs"
>
<div className="mx-4">Item</div>
<div className="mx-4">Item</div>
<div className="mx-4">Item</div>
<div className="mx-4">Item</div>
<div className="mx-4">Item</div>
</nav>
</div>
Final output (with custom styling of the scrollbar)

Angularjs/Bootstrap 3 CSS text goes beyond background image

This is the ng-view area powered by angular.
You can see the text extends beyond the background image.
How can i adjust the background image size pls ?
<div class="col-xs-12 col-sm-9 col-lg-9" ng-style="{'background-image':'url(images/blue3.jpg)', 'background-repeat': 'no-repeat', 'height':'800px', 'background-size':'contain' }">
<h1> {{message}} </h1>
<div ng-view></div>
</div>
Either let it grow to it's content with height: auto; or make the overflow scroll with overflow-y: scroll;

Layout structure - card layout and toolbar with angularjs md

How can I with use of AngularJS Material Design lib achieve page structure such as described in the official Layout structure guideline and exemplified in the screenshot below? I want to have centralised card breaking the edges of the page toolbar. Codepen example would be highly appreciated.
Edit: related thread: Angular Material Design layout
I figured I'd post this to help others trying to do the same thing with Materialize CSS. You can change the height of the nav-bar, and the size/placement of card.
Demo
HTML
<nav>
<div class="nav-wrapper">
<i class="material-icons">list</i>
</div>
<div class="nav-wrapper">
</div>
</nav>
<
<<div class="row" id="card-placement"> <!-- id added here -->
<div class="col s12 m8 offset-m2">
<div class="card grey lighten-5">
<div class="card-content grey-text text-darken-1">
<h5 class="head">Title</h5> <!-- class added here -->
<div class="divider"></div>
<p>Stuff goes here</p>
</div>
</div>
</div>
</div>
CSS
/* Moves card up into navbar */
#card-placement{
margin-top:-60px
}
/* Moves Title position up to be level with nav bottom */
.head {
margin-top: -2px;
}
nav {
color: #fff;
background-color: #ee6e73;
width: 100%;
height: 112px;
line-height: 56px;
}
.nav-wrapper {
margin-left: 20px;
}
You can easily do this with a little CSS
.card_position{
margin-top:-70px
}
Add this class to the card element.

Zurb responsive image size doesn't work

I use zurb and I have 1 row and 4 columns and I have 4 images inside those 4 columns.
Images are not all of the same size, so in prior to get pictures 100% sharpness, I have to give them width and height for each.
I would like to ask which class do I have to use and how, that would make my images responsive(ratio) while I am decreasing the size of my browser window, and with that, size of columns, which are responsive?
This is my code:
<div class="row">
<div class="three columns">
<img src="something.jpg" style="width:220px; height:200px;" />
</div>
<div class="three columns">
<img src="something.jpg" style="width:223px; height:190px;" />
</div>
<div class="three columns">
<img src="something.jpg" style="width:210px; height:150px;" />
</div>
<div class="three columns">
<img src="something.jpg" style="width:210px; height:195px;" />
</div>
</div>
I don't use inline CSS, it's just an example for width and height.
Thank you.
I somehow had this part commented inside .css:
/* line 45, ../../../../../../../../Library/Ruby/Gems/1.8/gems/zurb-foundation-3.0.4/stylesheets/foundation/grid.scss */
img, object, embed {
max-width: 100%;
height: auto;
}
With this my images are responsive.

Resources