I need to achieve the following grid(this is for desktop version):
So far I have listed the images, added the separator after each of them and tried to apply this plugin: https://github.com/brunjo/rowGrid.js to the container.
The separator is a pic too, it has to be responsive, on desktop I would need 4 in a row, but on tablet 6. Here my html so far:
<div id="competences">
{% for competence in competences %}
<div class="item-c">
<a href="">
<img src="/uploads/competence/{{ competence.logo }}" alt="{{ competence.name }}">
</a>
<img src="{{ asset('bundles/aeliusfront/images/competencies_separator.png') }}" class="cross_separator">
</div>
{% endfor %}
</div>
Any help, idea would be appreciated, Thanks.
PS. The tablet version has to be full-width, and has to contain 6 images on one row, with the same style(separator)
I had a quick look at rowGrid.js, it looks like its a nice plugin to fit images into a given width, but I don't think you can constrain how many are in each row.
I've written a plugin myself: here. With it you can specify an exact layout in rows and columns which changes at given width breakpoints of the container. This will solve the basic layout grid issue. You might find some other plugins that will also do that, I imagine it would be possible with media queries too, you could for instance set the images at 25% width for the 4 across layout, and at 16.66% width for the 6 across.
The separator just needs some CSS to work properly. My plugin script creates container divs to hold each row. In this case you can do something like this:
.cross-separator:first-child { display: none }
.hs-row-container:first-child .cross-separator { display: none}
You'd need to use css to position the cross separator to the top left corner of the image.
Hope this is clear enough.
Related
I'm creating a page where I have a parent div which encapsulates multiple child divs from different components in a NextJs project.
I have a preview option where my customers can preview their changes in mobile and desktop view.
I'm able to switch to mobile view using iframe. I want to achieve this without using an iframe.
Even though I change the parent div max width, because the rest of components have sm md lg xl which are taking the values from the view port instead of the parent div I'm unable to solve it.
What should be the approach to solve this?
The simplest way to access children in Tailwindcss is to class [&>] to the parent div. For example, let's say you have 5 child divs. If you want to give an attribute to the last of them [&>div:last-child]:bg-blue-500 , if you want to make it responsive, max-md:[&>div:last-child]:bg-blue-500 you have to express. I have prepared a demo for you to make it more meaningful, you can check it from the link below. If you expand the preview screen on the right a little, you will see that the colors have disappeared. I hope it can solve your problem.
Demo Code
Not sure what you meant complelty
<div class="max-w-full sm:max-w-full md:max-w-3xl lg:max-w-4xl xl:max-w-5xl">
<div class="text-sm sm:text-base md:text-lg lg:text-xl xl:text-2xl">
For small screen sizes
</div>
<div class="flex-sm-row sm:flex-row md:flex-col lg:flex-col xl:flex-col">
<div class="w-sm sm:w-1/2 md:w-1/3 lg:w-1/4 xl:w-1/5">
This for 50% width
</div>
<div class="w-sm sm:w-1/2 md:w-1/3 lg:w-1/4 xl:w-1/5">
This for 50% width
</div>
</div>
<div class="hidden sm:hidden md:block lg:block xl:block">
For large and extra-large screen sizes.
</div>
</div>
Media breakpoints allows you to change content appearance based on viewport size. Tailwind's media variants like md:, lg: etc based on them. In order to change content based on parent's size you should use CSS Container Queries. Be aware - they are not production ready - about 75% browser support (actual at December 2022)
Container queries allow us to look at a container size and apply styles to the contents based on the size of their container rather than the viewport or other device characteristics.
Tailwind has official plugin which may help you with it. Install it configure within tailwind.config.js
module.exports = {
plugins: [
require('#tailwindcss/container-queries'),
],
}
You need to add #container class to a parent container and use size modifiers on element you need like #md:bg-blue-500.
<div class="#container max-w-full resize-x overflow-auto">
<div class="p-16 #md:bg-blue-500 bg-amber-400">
Resize me
</div>
</div>
This way element should be yellow unless container size is bigger than 28rem and it will become blue no matter viewport size
Produced CSS is
#container (min-width: 28rem) {
.\#md\:bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
}
}
Check other modifiers here. Please note md:flex and #md:flex are different sizes which may confuse at first
#containers supports labels so you can name containers and specify different CSS for them. Let's say you have reusable component (common situation) you include within loop
<div class="#4xl/aside:bg-red-500 #3xl/primary:bg-yellow-500">
</div>
So within #container/aside element your card will be red after #4xl (56rem) size, while within #container/primary - yellow after #3xl (48rem).
<div class="#container/aside">
<div class="#4xl/aside:bg-red-500 #3xl/primary:bg-yellow-500">
YELLOW
</div>
</div>
<div class="#container/aside">
<div class="#4xl/aside:bg-red-500 #3xl/primary:bg-yellow-500">
RED
</div>
</div>
As I said it's not production ready. The way you want to handle unsupported browsers is up to you. First one - use polyfill. Just add
<script src="https://cdn.jsdelivr.net/npm/container-query-polyfill#1/dist/container-query-polyfill.modern.js"></script>
and it should be enough. However read full docs to improve user experience. I didn't fully tested it myself so cannot guarantee it is 100% solution
Second way is to check does browser supports container queries or not. You can check it via JS
if (!("container" in document.documentElement.style)) {
console.log('No support')
// Do something in that case
}
Another way - via CSS #supports rule
#supports (container-type:inline-size) {
/** Container queries supported */
}
Tailwind has supports: variant for that needs so something like this would work
<div class="supports-[container-type:inline-size]:hidden">
Your browser does not support container queries
Maybe show iframe element as backup (?)
</div>
<div class="supports-[container-type:inline-size]:block hidden">
Here is my cool feature which will be hidden if browser does not supports container queries
</div>
I've created this demo playground without polyfill to check different cases depends on container and window size plus different types of container and browser support
A solution to this can be adding a w-screen to parent div.
Use w-screen to make an element span the entire width of the viewport.
Documentation
It seems that in Bootstrap 4, the display/hidden classes like "d-md-none" and "d-none d-sm-block" will insert a linebreak and mess up with the look of my site. How is it possible to prevent this?
For instance, the footer is supposed to hide "2014-" on smaller screens, only show ©2019. The below HTML code is used:
©<span class="d-none d-sm-block">2014-</span>2019
However, it appears that the footer is messed up and the part "©", "2014-" and "2019" are split into three lines. How can I fix this behavior and remove the linebreak effect of Bootstrap 4's display/hidden class? Please help...
You need to use inline not block
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" >
©<span class="d-none d-sm-inline">2014-</span>2019
more details: https://getbootstrap.com/docs/4.3/utilities/display/#notation
hope to help:
The classes make the span elements have display as block, so they render as blocks below each other. Can you use :
©<span class="d-none d-sm-inline">2014-</span>2019
The inline class instead of block. Or is that of no use for you?
On large screens I want to have |A| |B|, on mobile I want
|B|
|A|
I saw here that this is possible via Bootstrap. However I use shopify's liquid. I saw in the theme.scss that there are -push classes - tried the following
<div class="grid__item medium-up--one-half section-header__item">
<h1 class="section-header__title">
{{ collection.title }}
</h1>
<div class="section-header__subtext rte">
{{ collection.description }}
</div>
</div>
<div class="section-header text-center medium-up--push-one-quarter">
<img src="{{collection.image | img_url: '235x235' }}">
</div>
However having the medium-up--push-one-quarter doesn't seem to make any difference (I am new to these css grid magic). I didn't see anything about pull in the theme.scss (which is used in the bootstrap solution from the link above).
Is what I want achievable and if yes, how?
Thanks :)
You can keep current markup and on mobile just change order of blocks using flexbox and rule order:1; for block B, don't forget display: flex; for the container of this 2 blocks
I have a rendered form in my view which I need to shape regarding the mock-up.
and this is the mock up I shall follow (this is on a mobile device)
this is the actual layout I have in my view
and this is the code in my view so far
<section class="restaurant__nav col-xs-offset-1 col-xs-10 col-md-offset-0 col-md-3 well">
<div class="container">
{{ form_start(form) }}
{{ form_widget(form) }}
{% if app.user %}
<input type="submit" value="{{ 'buy.field' |trans |upper }}">
{% else %}
{{ 'not_connected.text' |trans }}
{% endif %}
{{ form_end(form) }}
</div>
</section>
So I'm really not good with sass (as i'm using it) and css either. But I tried to margin each element but I find it struggling a little.
Any good advice or method to actually do like my mockup without using too much pixels or avoiding that kind of things -> margin-left: 20px?
(just ignore the RÉSERVER I really try to put my form in the middle and element to equal sizing)
thank you
So first of all, if you didn't notice you are using Bootstrap.
It means that to align in left side and in the middle your two main block, you can use class like : "col-md-*". It's the grid concept of bootstrap, basic.
Here is a reference : w3schools
Once block are correctly placed, you have to make the button and input together. Commonly called "input-group". You can implement this by many way, here is a reference : getbootstrap.com
Then for your button, you have some good examples again on w3schools
Once that's done, you may'd like to know that you can center element with :
display: block; // if element isn't natively block
margin: auto;
To know what html element is considered by css as Block or Inline elements, again another reference : w3schools
To end this, you'd probably like to fix the width of the label and input as the same value.
I made you more than an example, my bad, but here it is :
JsFiddle
This may seem like a dumb question, but is there an official bootstrap class reference? I looked on the website and was unable to find one.
I'm looking though some of the examples and I'll see stuff like:
<div class="container-fluid">
How am I supposed to figure out what all the contain-fluid tag does? Am I expected to dig through the css for every class to look at the rules and then divine how it will affect my page? That seems like a quick way to make assumptions and run into problems later.
Is there an official reference somewhere that I'm missing? I've seen some class lists compiled by third parties, but it seems like those are always going to lag behind new changes and may contain assumptions of intensions.
Not official but current as of 2/2016 https://bootstrapcreative.com/resources/bootstrap-3-css-classes-index/
Printable pdf and a sortable table with descriptions to help sort through the list of classes.
http://www.tutorialspoint.com/bootstrap/bootstrap_quick_guide.htm contains a very good reference for many of the bootstrap layout and css components.
Bootstrap 3 moved to a "mobile first" approach. .container is really only there in instances where you need/want a boxy layout. but, if you exempt the div.container-fluid entirely, you're left with a fluid layout by default.
for example, to have a two-column fluid layout, simply use:
<body>
<header>...</header>
<div style="padding:0 15px;"><!-- offset row negative padding -->
<div class="row">
<div class="col-md-6">50%</div>
<div class="col-md-6">50%</div>
</div>
</div>
<footer>...</footer>
</body>
The 2.x .container-fluid was replaced by .container in Bootstrap 3.x (http://getbootstrap.com/getting-started/#migration), so the .container is fluid, but it's not full width.
You can use the row as a fluid container, but you must tweak it a little to avoid a horizontal scroll bar. Excerpt from the docs (http://getbootstrap.com/css/#grid)..
"Folks looking to create fully fluid layouts (meaning your site stretches the entire width of the viewport) must wrap their grid content in a containing element with padding: 0 15px; to offset the margin: 0 -15px; used on .rows."
More on changes in 3.x: http://bootply.com/bootstrap-3-migration-guide
Demo: http://bootply.com/91948
UPDATE for Bootstrap 3.1
container-fluid has returned again in Bootstrap 3.1. Now container-fluid can be used to create a full width layout: http://www.bootply.com/116382