I have a simple header in which I want to insert a profile image. However profile image doesn't fit the header and I'm not sure how to approach it in a responsive manner. I don't want to hardcore the width/height of the image in any manner, but rather I want it to always fit the height of the header, with some paddings.
My code is:
<div class="flex flex-wrap items-center justify-start
m-3 p-2 pl-6 ">
<span class="title-text light-text text-xl">Some Title</span>
<span class="pl-10">Some link</span>
<span class="pl-10">Some link</span>
<span class="pl-10">Some link</span>
<span class="pl-10">Some link</span>
<div class="rounded">
<img class= "relative rounded-full border
border-gray-100 shadow-sm
max-w-max h-full " src="../../assets/dog.jpeg" />
</div>
</div>
Without image it looks like this:
But with image it looks like this:
However I want it to look:
How do I achieve it, using Tailwind?
You can use object-fit:cover, note that you will have to set the with and the height of the img to 100%.
.rounded{
display: flex;
align-items: center;
justify-content: center;
}
.rounded img {
height: 100%;
width: 100%;
object-fit: cover;
}
here is the link for tailwind-css meaning you can use this class object-cover only
<div class="rounded">
<img class= "object-cover relative rounded-full border
border-gray-100 shadow-sm
max-w-max h-full " src="../../assets/dog.jpeg" />
</div>
Give the fixed height to the nav and the image container,
<div class="flex flex-wrap items-center justify-start px-4 bg-gray-800 text-white h-20">
<span class="title-text light-text text-xl">Some Title</span>
<span class="pl-10">Some link</span>
<span class="pl-10">Some link</span>
<span class="pl-10">Some link</span>
<span class="pl-10">Some link</span>
<div class="h-16 ml-auto">
<img class= "rounded-full border border-gray-100 shadow-sm h-full" src="../../assets/dog.jpeg" />
</div>
</div>
Kinda late but I've just been working on this and the solution for me was to set:
image height className=h-8 to control sizing
container margins to control positioning className=ml-auto.
I'm using tailwind in react, so full code is:
import GitHubLogo from '../media/GitHubLogo.svg';
const tools = [
'Transcribe',
'Reverse complement',
'Translate',
'Primer check',
'Primer design',
];
export const Navbar = () => (
<nav className="flex w-11/12 p-2 mx-auto rounded bg-coral-std">
<h1 className="text-4xl btn"> welcome</h1>
{tools.map((tool) => (
<a
href={`/#${tool}`}
className="inline-flex px-6 py-2 rounded hover:bg-slate-200/20"
key={tool}
>
{tool}
</a>
))}
<a href="https://github.com/ccozens/mol-bio-tools/" target='_' className="ml-auto">
<img
src={GitHubLogo}
alt="GitHub logo"
className="h-8 pr-1 mx-auto"
>
</img>
Source code</a>
</nav>
);
Note the mx-auto flag in the image class centres the image over the image label; this isn't impacting the right positioning.
Related
I am trying to align my button (JSX component) on the right-hand side, and have all the text on one line. I am using next.js and tailwindcss, and the button contains plain text and a react-icon. All of these components are contained within a card.
Currently, my output is this:
My code for the containing card is:
return (
<Fragment>
<div className=" bg-white rounded-md text-black overflow-hidden ">
<img className="object-cover w-full h-48" src={"/" + image}></img>
<div className=" flex-none" id="text">
<div>
<h1 className=" text-3xl font-semibold">{title}</h1>
</div>
<div>
<p className=" text-gray-700 font-bold">{humanReadableDate}</p>
<p className=" text-lg italic text-gray-500">{formattedAddress}</p>
</div>
<div className=" m-3">
<Button link={"/events/" + id}>
<span className="inline">Explore event</span>
<span className="inline"><AiOutlineArrowRight /></span>
</Button>
</div>
</div>
</div>
</Fragment>
);
And for the button:
return (
<Link href={props.link}>
<a className="inline-block text-right bg-emerald-500 text-white py-2 px-5 rounded-md">{props.children}</a>
</Link>
);
Check floats
https://tailwindcss.com/docs/float
Use float-right to float an element to the right of its container.
Check sizing
https://tailwindcss.com/docs/min-width
Utilities for setting the minimum width of an element (e.g. min-w-max)
I am trying to render a button group with 3 buttons, but I am getting a space in between these. Below is my code
<div className=" mt-2 flex items-center justify-center ">
<div
className="mt-1 inline-flex shadow-lg "
role="group"
>
{products.map((product) => {
return (
<div key={product.id}>
<button
type="button"
onClick={() => {
setPName(product.name);
setPId(product.id)
}}
className="prodButton float-left px-6 md:px-8 py-3 text-black text-xs font-pixeloid leading-tight inline-block focus:text-white transition duration-150 ease-in-out"
>{product.name.toUpperCase()}</button>
</div>
)
})}
</div>
</div>
CSS for the class
.prodButton
{
background-image: url('/assets/images/Buttons/ProdButton.png');
background-size: 100% 100%;
}
Below is how the group is looking
I cant seem to remove the white space in between. Please suggest
Thanks in advance!
I am trying to make the following happen:
On image hover, at the bottom it will show comments/reactions on the left and name on the right
I cannot get the 2 divs to space between at the bottom and I do not know why.
https://play.tailwindcss.com/jyBq62Ok90 is the working code
You need to set a width, e.g. w-full on the absolute positioned div. Otherwise the div will be as wide as the content and there will be no space between.
See this tailwind play
Hope this helps.
As far as I understood , you need to highlight the comment div below as you hover the image with a space between two divs
You can use group-hover utility with a div wrapper. Below code will help you much more
<script src="https://cdn.tailwindcss.com"></script>
<div class="group">
<div class="group mb-4 flex aspect-auto w-full overflow-visible duration-300 ease-in hover:scale-105 hover:rounded-lg">
<img src="https://imagesvc.meredithcorp.io/v3/mm/image?url=https%3A%2F%2Fstatic.onecms.io%2Fwp-content%2Fuploads%2Fsites%2F13%2F2015%2F04%2F05%2Ffeatured.jpg&q=60" class="h-full w-full bg-gray-900 object-cover hover:opacity-40" />
</div>
<div class="bottom-0 mx-4 mb-4 hidden bg-gray-700 px-3 duration-300 group-hover:block group-hover:transition group-hover:ease-in">
<div class="flex justify-between">
<div class="flex text-sm font-medium text-white">
<ChatAlt2Icon class="h-5 w-5 text-white" />
<span class="pl-1 text-white">12</span>
<HeartIcon class="ml-2 h-5 w-5 text-white" />
<span class="pl-1 text-white">12</span>
</div>
<div class="flex text-white">Added: Today</div>
</div>
</div>
</div>
My desired goal is that when I keyboard to the right outside of the flexbox, I want to push the other items to the left so I can see the terms in the overflow, like a scroll. I can currently keyboard to any item, but I want to make the CSS to where it pushes the first items to overflow left or something of that nature. Here is a screenshot. If I need to translate the tailwind to normal css let me know. thanks!
<section class="ml-8 border-2">
<slot />
<div class="m-auto uppercase border-2">
Popular Searches
</div>
<div class="popularSearchTerms">
{#each popularSearches as item, index}
<button
class="popularBtn"
class:popularSearchFocused={popularSearchesHasFocus &&
index === resultsPosition}
>
<div class="flex p-2">
<span class="w-4 h-4 mt-2">
<Search />
</span>
<span class="ml-2 mr-2">{item}</span>
</div>
</button>
{/each}
</div>
</section>
<style lang="postcss">
.popularSearchTerms{
#apply flex justify-between p-2 mt-6
overflow-hidden border-2
.popularBtn {
#apply bg-navBackground rounded-md mr-4;
}
.popularSearchFocused {
#apply transition-transform duration-300
ease-in-out transform scale-110 z-
10 bg-gray-100 border-4 border-
Orange rounded-md shadow-
vodTileFocus text-navBackground
text-shadow-none;
}
</style>
I am trying to float a button to the right of a card. I want it to appear in the bottom righthand corner.
When I use a float right. It appears outside the parent div, is there a way to position it correctly?
<div class="m-10">
<div>
<div class="bg-white shadow-lg border-grey w-1/3 ">
<div class="p-4 flex">
<div class="pt-3 text-center font-bold text-2xl w-16 h-16 bg-grey-lightest">
D
</div>
<div class="ml-4">
Team Name
</div>
</div>
<div class="float-right">
<a :href="'/company/' + team.id">
<button class="ml-2 bg-blue hover:bg-blue-dark text-white text-sm font-bold rounded p-2">
View
</button>
</a>
</div>
</div>
</div>
</div>
I have a running sandbox here with the code
https://codesandbox.io/s/tailwind-css-nl0ph
Instead of using the float-right class use text-right
You just need to apply float-right to the button element instead of the parent div
<div class="m-10">
<div>
<div class="bg-white shadow-lg border-gray-400 w-1/3">
<div class="p-4 flex">
<div class="pt-3 text-center font-bold text-2xl w-16 h-16 bg-gray-200">
D
</div>
<div class="ml-4">Team Name</div>
</div>
<div class="h-fit min-h-full flex justify-end">
<a href="'/company/' + team.id">
<button class="float-right ml-2 bg-blue-400 hover:bg-blue-600 text-white text-sm font-bold rounded px-2 py-1">
View
</button>
</a>
</div>
</div>
</div>
</div>
Add this new class to clear floating element
.clearfix::after {
content: "";
clear: both;
display: table;
}
and then apply that class to the containing div (parent div of the button)
source: https://www.w3schools.com/howto/howto_css_clearfix.asp