Cropped Full screen oval border with text inside with CSS text - css

I am struggling to imagine the best way to accomplish a layout I am trying to achieve which includes a static sized oval that is cropped for smaller screens and which contains text inside it that will respond based on the breakpoint.
The design is like this:
So far, I'm here:
I'm trying to achieve this by creating the Oval outside my container div then putting on negative margin on the text to give it the appearance it is inside the oval. I feel like this isn't the right approach.
Currently set up (using Tailwind):
<section id="reading">
<div class="mt-12 border border-black rounded-[50%] overflow-hidden w-[686px] h-72"></div>
<div class="flex flex-col mx-auto md:container">
<div class="self-center justify-center px-8 text-center uppercase -my-80 py-28 text-ts3 font-title-preset">Text Headline Goes Here</div>
</div>
</section>
In my head, for the oval, I would just do margin:auto; overflow:hidden, and width:100% on the div, but that isn't working.
Any pointers on how you would approach this from a better practice perspective?
Thanks!

The approach you're taking separates the oval from the content within. A better way would be to keep them together by wrapping them both in a relatively positioned div and making the oval absolutely positioned to the top and center (then using a transform to center again which is a common pattern) and adding overflow-hidden to the relatively positioned element.
Not sure what your text-ts3 class is meant to do since you did not share your config. But this example uses a few breakpoints with text size classes defined for each and some negative top margin on the text to make things look more vertically centered. Here is the example running on Tailwind Play https://play.tailwindcss.com/3zWymGzXPn
<head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<section id="reading" class="border border-transparent pt-12">
<div class="overflow-hidden relative mx-auto md:container h-72">
<div class="border border-black rounded-[50%] w-[686px] h-full absolute top-0 left-1/2 -translate-x-1/2"></div>
<div class="h-full flex items-center justify-center max-w-[686px] mx-auto">
<div class="text-center uppercase -mt-4 sm:-mt-6 md:-mt-8 text-5xl sm:text-6xl md:text-7xl max-w-xs sm:max-w-sm">Text Headline Goes Here</div>
</div>
</div>
</section>

You can set the width of the oval to 120% (or a fixed with per breakpoint) and the shrink to 0, so it does not shrink.
<section id="reading">
<div class="flex h-screen w-full justify-center overflow-hidden bg-yellow-100">
<div class="mt-12 flex h-56 w-[120%] shrink-0 items-center justify-center rounded-[50%] border border-slate-300">
<div class="font-semibold">text goes here.</div>
</div>
</div>
</section>
See example in tailwind play.

Related

How do I make it so two adjacent divs take up remaining space without pushing/squeezing the main div?

I have this layout:
This is the code for the image below:
<main>
<div className="flex justify-center max-w-xl mx-auto bg-purple-400">
...
</div>
</main>
What I want is to have two divs, one of the left and one on the right of this layout (in the white area) that take up the remaining space without affecting the width of the main content area. How can this be done?
I've experimented with this code, but I haven't figured it out yet:
<main className="flex">
<div className="">left white area</div>
<div className="flex justify-center max-w-xl mx-auto bg-purple-400">
...
</div>
<div className="">right white area</div>
</main>
UPDATE:
I was able to get the desired behaviour with media queries, even though I wanted to do this with native tailwind, this works as well:
--HTML--
<main className="flex">
<div id="left" className="hidden">left white area</div>
<div className="flex justify-center max-w-xl mx-auto bg-purple-400">
...
</div>
<div id="right" className="hidden">right white area</div>
</main>
--CSS--
#media screen and (min-width: 64rem) {
#left,
#right {
width: calc((100vw - 64rem) / 2);
display: block;
}
}
I'll leave this thread open for any possible other solutions. If it can be figured out with just tailwind that's even better.
Edited again to clean up the code a bit.
I think you want flex-1 or flex-grow in the middle one, and instead of media queries for the side ones try hidden md:block and possibly something like w-1/5

How to fill remaining empty space if element using translate-x using tailwind CSS

i have problem with filling empty space, if parent div using display flex, and children have translate-x class, here some example code
<div class="flex h-screen w-screen">
<div class="w-1/3 -translate-x-10 bg-red-200"></div>
<div class="w-full bg-red-400"></div>
</div>
it show like this
how do i fill the empty space with red if i change the translate-x value
First thing that comes to mind is you could try adding a background color to the parent div like assuming you want the darker red. There are probably other methods but if this one works for your use case it's pretty simple.
<div class="flex h-screen w-screen bg-red-400">
<div class="w-1/3 -translate-x-10 bg-red-200"></div>
<div class="w-full bg-red-400"></div>
</div>

TailwindCSS angled border

I have managed to create a border which is cut at an angle in the following way ->
https://play.tailwindcss.com/b9oILu69my
Basically, I have a big container, inside of it I have a smaller container where I'm placing the border and setting the color of the bottom/right borders to transparent, in this way achieving what I am looking for.
Now I am trying to do the same thing, however, I want the border to be placed on the bottom-right side instead of the top-left
I've tried hundreds of variations of the code shown in the playground, but to no avail.
To be even more precise in what exactly I am trying to achieve ->
Detailed example
Any help would be appreciated!
I would take a somewhat different approach, by using an absolute positioned rotated div, within a div with overflow-hidden. If you keep the main image (the yellow square) centered with m-auto, the border will be the same size on both sides. On the yellow div you need to set a z-index that is higher then the rotated div.
<div class="flex min-h-screen flex-col justify-center overflow-hidden bg-gray-50 py-6 sm:py-12">
<div class="relative flex m-auto h-40 w-40 overflow-hidden rounded-lg">
<div class="absolute top-8 left-8 m-auto h-96 w-96 bg-blue-200 rotate-45"></div>
<div class="top-3 z-30 right-3 m-auto rounded-lg h-32 w-32 bg-yellow-300"></div>
</div>
</div>
You can find my Tailwind playground example here
You can play with the height and width of the div’s using arbitrary values, like w-[48rem] and rotate-[60deg].
Edit: this example looks more like yours.
Hope this helps.

Tailwind grid dynamic sidebar/navbar width with main 100% width

I need a simple main div column 100% full.
Sometimes a sidebar can appear, with dynamic width.
REPL: https://codesandbox.io/s/tailwind-dynamic-sidebar-kw1ku
In this example you can see I'm not able to change sidebar width (which has every time a new width value) and I'm not able to "stretch" main div to 100% width.
How to do?
<div class="min-h-screen grid grid-cols-12">
<div class="bg-green-500">
<div style={`width: ${randomWidth}px !important;`}>
Sidebar. This has dynamic width.
</div>
</div>
<div class="bg-red-500">
Main. This has full width.
</div>
</div>
I would recommend a simple use of relative and absolute. Here's the codesandbox
<div class="min-h-screen w-full relative">
{#if sidebarVisible}
<div class="bg-green-500 h-full absolute left-0">
<div style={`width: ${randomWidth}px !important;`}>
Sidebar. This has dynamic width.
</div>
</div>
{/if}
<div class="bg-red-500 h-screen">
Main. This has full width.
</div>
</div>
For 100% width, you can use w-full and for full screen height h-screen

How to position an element to use the remaining space of the screen without overflowing it [TailwindCSS]

I'm using TailwindCSS -a utility class framework- to style my elements. Altough this is more a generic CSS question.
I can't manage to position the box so this gets the remaining space without overflowing it. This is my actual state:
<div class="flex flex-col h-screen mx-8 bg-white rounded p-4 mb-8">
<!-- SUBTITLE -->
<div>
<h2 class="text-lg font-bold text-gray-700 pb-4">Subtitle</h2>
</div>
<div class="relative self-auto mb-8">
<!-- ELEMENTS -->
<a href="#">
<img class="absolute z-10" style="top: 131px; left: 235px;"
src="{{ asset('some.svg') }}">
</a>
</div>
</div>
Output (omitting some of the inside elements):
As you can see, the scrollbar shows because the div is too big. In order to see the bothom of the box I have to scrolldown:
This is my desired output:
Thanks in advance.
Fiddle
Link.
The class .h-screen is 100vh. .mb-8 has an margin-bottom:2rem. So the height is 100vh + 2rem. You can use [calc][1] to subtract the margin from the height.
.h-screen{
height:calc(100vh - 2rem)!important;
}
https://jsfiddle.net/c28145au/
https://developer.mozilla.org/en-US/docs/Web/CSS/calc
This is the solution I found: w-[calc(100%_-_10px)]
you are using class h-screen which has height: 100vh; remove that class from the div.

Resources