Tailwind css - responsive padding order overring priority - tailwind-css

I have a logo header issue - where in mobile I want the padding to be 16px - but in desktop padding to be 128px.
<header className="p-sm md:px-xl">xxx</header>
but the desktop version is still showing the mobile padding?
I can see a file where the override looks correct called globals.css -- but then I see p-sm override in another location under <styles>
its the way that next/document is being used to integrate the head - something has created various inline styles that override the tailwinds css
update
so we have made a UI lib on its own repo with tailwindcss -- and recently replaced the UI components on another repo (also its tailwindcss defined) -- I think what's happened is when we swapped over to the UI lib components which is its own node module -- it replicated the tailwindcss twice -- there is an override happening that is knocking the styling off.

It looks like you're using the wrong syntax when defining your screens.
You shouldn't use md- or lg- when creating a responsive design but md: and lg:.
Here's the documentation: Link.
Your code should look like this:
<header className="p-sm md:px-xl">xxx</header>
If you don't have custom sizing, you can use this code instead:
<header className="p-[16px] md:px-[128px]">xxx</header>

Related

Some styles of Nativewind are not working on native (Android) but they do in the web

I am using Tailwind (Nativewind) with Solito (expo React Native).
I do have a styled component with some children.
The style is properly applied on the web, but in the native version only some are applied. The gap and text-center are not working, but the background color is.
The code is something like this:
<Custom className="gap-5 bg-orange-100 text-center">
<StyledText>TEST</StyledText>
<StyledTitleBig>Login Screen</StyledTitleBig>
<...>
</Custom>
This is how the native version (android) looks:
This is how the web looks (this is the objective):
I created a GitHub issue and there I got the answer that it is the expected behavior…
React Native “doesn't accept CSS inheritance”, so the only way of making it work is to add the “text-center” className for each of the text components.

How to use Antdesign with tailwindcss together in a React Project

I'm going to set up a new project and would like to have these two packages together, but not sure, so the question is that using Tailwindcss with antdesign Is a good practice?
Does anyone have any experiences?
Each package has its own theme manager for instance for colors, typography, dark mode and so on. How do you manage theme, with tailwinds or antd or both? And why?
Both packages have Grid support, which one would you prefer?
Let's have your insights?
After some research, I found these results
Some examples that uses both libs:
https://github.com/plamworapot/next-antd-tailwindcss
https://github.com/dospolov/react-redux-saga-antd-tailwind-boilerplate
https://github.com/cunhamuril/pocs
It recommended trying to commit to only one framework
Tailwind is pretty much a design system using utility classes to make writing css easier therefore it can be pretty much used with any other ui library just make sure to disable the default styling that Tailwind inject into your default styling by disabling the preflight option in config :
module.exports = {
corePlugins: {
preflight: false,
}
}
One slight issue with using both ant-design and tailwind-css is tailwind's some of default styles will break ant-design components...
I recently came a cross an issue where ant-design image preview was not functioning correctly and the image was not centered.
expected result
image one
vs what I got when using tailwind with ant-design
image two
turns out tailwind will change default image display property from "inline-block" to "block" and breaks tailwind image preview component
I resolved my issue by reseting display property on images
img {
display: unset !important;
}
apart from this little tweaks you will be good to go using both of them
There's no problem to use Tailwind CSS and Ant Design together.
Tailwind CSS could be used to custom styling on Ant Design components.
Check this link to see an example with Next, Ant Design and Tailwind CSS:
https://github.com/plamworapot/next-antd-tailwindcss
You can use Bootstrap with ant design right? Think Tailwind same as Bootstrap. Tailwind is a CSS library you can use it with any setup and framework there no extra configurations needed. Just pass the Tailwind class names.
When it comes to theming. It's a context. Ant design will grab it's context and tailwind grab it's. We don't need to think or worry about it
Well for me I needed to use tailwind to override the default ant design css styling so what I ended up doing was adding important:true to the tailwind config object (as per tailwind docs tailwind config docs for important config)
module.exports = {
....,
important:true,
};
I know some people frown at using important (as do I) but I think this is one of the uses it was created for.

How does one modify a twitter bootstrap component?

I know I can just have a custom stylesheet that overrides the bootstrap component I wish to customize (for example the jumbotron), but is the right way to go about this "problem"? I don't think this can be done with a bootstrap theme, although I haven't read a whole lot on this subject.
You can use your browsers DevTools to inspect an element that you want to change, and in the Rules/Styles section you can see which CSS elements is it using and then you can create your own css file and paste the CSS there and change it so it overrides bootstraps element. Here is how to get the devtools from Chrome https://developer.chrome.com/devtools#dom-and-styles and from Firefox https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Open_the_Inspector. Don't forget to import your CSS customised script under bootstraps so it overrides the CSS that you wish to change.
Use twitter-bootstrap customize on their website to customize it and download the customized files. Or just create a custom CSS file and edit classes like .jumbotron and other stuff
There are a few ways to modify the default bootstrap css and no one way is inherently more or less "right" than any other. It all depends on the coding style of you and/or your team. Here is a list of a few ways that I came up with off the top of my head:
Modify the css file you downloaded from Bootstrap
(My Choice) Override Bootstrap styles with your own CSS. Just be sure to follow the rules of CSS Specificity (External < Internal < Inline) and if you have trouble getting a certain rule to apply try reading this answer or force it with !important
NOTE: This is likely NOT a comprehensive list, just a starting point.

Change the default responsive navbar breakpoint

is there a way to change the breakpoint where Bootstrap menu becomes responsive and collapse? 979px is far too big for me and I would like the transformation taking place only on smaller sizes.
Yes, you can do it by redefining #navbarCollapseWidth variable in less/variables.less file. And recompiling css after that.
Compiling instructions can be found in Compiling Bootstrap with Less section of official documentation.
#nick-kugaevsky the 'compiling bootstrap with less' - link is broken.
BTW, for bootstrap 3 RC 1, you will want to modify the following property in less/variables.less
// Point at which the navbar stops collapsing
#grid-float-breakpoint: #screen-phone; // here i allready changed it
BTW: this only prohibits the responsive nav to collapse when width > #screen-phone for example. Here is some more info on compiling bootstrap with less: http://bootstrap.lesscss.ru/less.html
You have to download bootstrap, point your app or the node js util to the bootstrap directory containing the less files, modify less/variables and recompile the bootstrap.less file.
Argh, just found out it this is written in the bootstrap documentation:
http://getbootstrap.com/components/#navbar

css framework for an app with existing stylesheet

I am building a chrome extension that attaches a widget sort of thing to gmail message. It appears below every email (something like a gmail contextual gadget) when the user is on gmail.com site.
I looked at few css frameworks like twitter bootstrap to use in my app. When I used it in mywidget, it messed with the existing gmail styles because of css class name clash. Is there any other framework that I can use where there would be no name clash? I came across jquery-ui framework. All the classnames here start with .ui-* thereby causing no name clash. Are there any other css frameworks like this with unique class names?
Update 2: Here is a gist of v3.1.1 provided by #GFoley83
Update: The pastebin joined below is the Twitter Bootstrap version 2.0.4
You should definitively use the up-to-date version and compile it yourself.
Here is what I did with the bootstrap less files :
.tw-bs {
#import "less/bootstrap.less";
}
And this is the result : http://pastebin.com/vXgRNDSZ
Demo (jsfiddle)
If you don't like tw-bs you can easily do a find/replace, there shouldn't be any conflict.
I used #Sherbrow solution but had to add the responsive file too.
.my-bootstrap-container {
#import "less/bootstrap.less";
#import "less/responsive.less";
}
and then run
node_modules/less/bin/lessc demo.less -x > demo.css
If somebody needs the complete step by step tutorial how to compile bootstrap for your own namespaced container I made a blog post about it http://joomla.digital-peak.com/blog/151-how-to-add-bootstrap-to-your-joomla-2-5-extension
The last part is for Joomla but the beginning can be used globally. It has also a link to the latest compiled bootstrap version 2.3.2. Just make a search and replace for .dp-container.
2016 Update: A future way to mitigate this issue (rather than having to recompile bootstrap) is to take advantage of web components, specifically shadow DOM. This allows your app to be self contained (almost like an iFrame) without the web browser having to open a separate page / losing the ability to communicate between pages.
say your component is contained in <div id='plugin'>...</div>
You can move what's inside that div to a tag in your head, eg.
<template id="template"><!--Your Code Here--></template>
Your template can include all the bootstrap link tags and js you want. Then in your javascript/bookmarklet, you can write
var pluginRoot = document.querySelector('plugin').createShadowRoot();
var template = document.querySelector('#template');
var clone = document.importNode(template.content, true);
pluginRoot.appendChild(clone);
You can read a lot more about Web Components (along with Shadow DOM) here: http://webcomponents.org/articles/introduction-to-shadow-dom/
I started off using jquery ui - http://jqueryui.com/ because it has its own css classes which don't clash with gmail. YUI is another such framework that I found. But Sherbrow showed how I can use bootstrap css with our own unique css style names.
The currently accepted answer did not render forms correctly (using SASS and bootstrap 4 beta). The following works for me:
.bootstrap {
#import 'bootstrap-4.0.0-beta/scss/bootstrap.scss';
box-sizing: border-box;
}
The box-sizing is important, because, when compiling your SASS stylesheet, the following will be generated.
.bootstrap html {
box-sizing: border-box;
...
}
I.e. the box-sizing property will be placed on an html element inside an element with class="bootstrap" - which of course will not exist. There may be other styles on html and body that you may want to manually add to your styles.
And now you can place content styled using bootstrap inside a bootstrap class:
<div class="bootstrap">
<div class="container">
...
</div>
</div>

Resources