/r/css

Photograph via snooOG

A community for discussing about CSS (Cascading Style Sheets), Web Design and surrounding relevant topics. Feel free to discuss, ask questions, share projects and do other things related to CSS here.

About CSS
  • CSS, short for Cascading Style Sheets, is used almost universally across the web to affect the design and appearance of every website you visit. Here in /r/css, you've got a place on reddit to talk about CSS, whether you're new to CSS and want to learn, or a pro wanting to discuss the engineering and usability reasons that all modern browsers ignore

  • We welcome all CSS discussion here. If you need help with styling your website or your reddit, or want to share a neat trick you cooked up, it's welcome here!

Rules
  1. No spam. If you've developed a neat CSS trick that you want to share with others, make sure you share the trick, not your website. In other words, feel free to post something like "Isn't my 404 page neat?" with a link, but avoid posts like "Hey look how cool my site is!" that link to a storefront. This reddit is a place to learn and show off CSS, not sell your products. If your CSS helps sell your product, great, but make sure your post is about the CSS, not the product.
  2. Be nice. Not everyone is a fantastic designer. If someone posts their work here and you don't like it, give them objective feedback about ways to improve it, not "it's ugly." Likewise, CSS newbies often have the same questions as they grow and learn, so try not to be mean when they post a question we've seen a thousand times before. It might be old news to you, but they wouldn't ask if they hadn't already sought an answer, and there might be other people too afraid to ask for themselves.
  3. Don't use link shorteners (bit.ly for example), because they are automatically marked as spam.
  4. Try to use descriptive titles (not 'I have a question.'). I won't enforce this, but it'd be nice if you'd follow it.
Related subreddits
Useful Links
  • Inspire, a collection of all kinds of useful links.
  • /r/csshelp and /r/reddithax are the places to go for questions relating to Reddit's stylesheets. Techniques differ a lot between formal CSS development and subreddit stylesheets, so you'll often get better answers there.
  • Use Codepen or jsFiddle to provide working code samples.
  • Mozilla Developer Network is your one-stop shop for detailed information on CSS properties. Formal specifications for everything CSS can be found at W3.org. Don't go to W3Schools - it isn't a wiki maintained by real developers like MDN, so it's often out of date and prone to significant errors, and it has no relationship with the W3 so they have no special or insider knowledge.
  • CanIUse.com has 99% of the information you need on supporting different browsers.
  • Codecademy can get you started from 0 knowledge of web development in mere hours.
  • Learn Layout will teach you advanced techniques for designing modern sites.

Click here to message the mods.

/r/css

127,659 Subscribers

0

I've made a tutorial to animate Font Colors only using CSS

0 Comments
2024/12/04
13:49 UTC

19

My Chrome extension for TailwindCSS developers just reached 10000 users 🎉

13 Comments
2024/12/04
11:50 UTC

8

I just created a fun and simple web app called TypeTheAlphabet

TypeTheAlphabet.Online

I just created a fun and simple web app called TypeTheAlphabet! 🎉 The challenge is simple: type A to Z as fast as you can, record your best time, and see if your friends can beat it! 🕒🔥.

Give it a try and let me know your best time! 🖱️⌨️

Feedback are always welcome!🫡

P.S. App Idea Inspired from Matt Ramos

4 Comments
2024/12/04
08:50 UTC

2

Looking for CSS school in the Philippines

Hi everyone! I'm looking for a school that offers Grade 11 CSS. Currently enrolled in GJCSHS and their teacher for this subject SUCKS, so I'm looking for a school that is known for great teaching preferably public school. Thankyou!

3 Comments
2024/12/04
05:19 UTC

0

The text has moved to another section

Hello! I made a section of pictures and text in a column so that the picture was on top, but the text climbed onto another section, it should have just made an indent, possibly beyond the position, but it is necessary.

https://preview.redd.it/awk2gturqq4e1.png?width=1919&format=png&auto=webp&s=df0fd34dfdb7dd6600eeac7e5d1f5206cc4dae94

2 Comments
2024/12/04
02:14 UTC

0

Help me with code

but i want it so when i hover over a box the color doesnt dissapear and so that the left over space gets filled with background color of the box i hover over.

body {

margin: 0;

display: flex;

justify-content: center;

align-items: center;

height: 100vh;

background: #f4f4f4;

}

.container {

display: flex;

width: 1000px;

height: 300px;

position: relative;

}

.box {

flex: 1;

position: relative;

background: #ddd;

transition: all 0.3s ease;

height: 100%;

display: flex;

justify-content: center;

align-items: center;

color: white;

font-size: 24px;

font-weight: bold;

opacity: 1;

z-index: 0;

}

/* Box-specific colors */

.box1 { background: #3498db; }

.box2 { background: #2ecc71; }

.box3 { background: #e74c3c; }

.box4 { background: #f1c40f; }

.box5 { background: #8e44ad; }

/* Hover effect: The hovered box fills out the space */

.box:hover {

flex-grow: 3;

z-index: 1;

opacity: 1;

background-color: inherit;

}

/* The boxes before the hovered box will disappear */

.box:hover ~ .box,

.box:hover ~ .box ~ .box,

.box:hover ~ .box ~ .box ~ .box {

opacity: 0;

}

/* The boxes to the left of the hovered box disappear,

and the hovered box will show its background color */

.box:hover {

background-color: inherit;

color: white;

}

/* Add a small gap between the boxes */

.box + .box {

margin-left: -1px;

}

/* Dynamic behavior for the last box */

.container .box:last-child:hover {

opacity: 1;

}

5 Comments
2024/12/03
16:19 UTC

0

Can't increase width of tabs

At this purposely ugly website, we're using graphics for the vertical tabs which are 83px wide. However, the tabs are cutting out the bevel on the closed tabs. When a tab is open you can see the bevel. All graphics are background images except the 2nd home button/tab. Any ideas how to make the bevel show on all tabs regardless of open/close state?

Edit: JS Fiddle: https://jsfiddle.net/qut3b9ks/

1 Comment
2024/12/03
16:17 UTC

1

How to make overflowed container automatically scroll down when new content is added?

Hi!
I have a container element with overflow-y: auto that I continuously fill with message elements (like a log).
But currently user have to manually scroll down every time the new entry is added. How do you implement autoscroll to the bottom?

7 Comments
2024/12/03
16:06 UTC

1

Add a notch to a popup

I want to achieve the following:

https://preview.redd.it/7d14oplhtm4e1.png?width=524&format=png&auto=webp&s=8c754f13a7aa63f7f56d3f122bb4bb211a461989

I have a popup with information about a profile. In this popup, a banner graphic will appear at the top. This can be changed by the user, so different banners are displayed. Now I want this profile popup to have a notch at the top and ideally a part of the banner graphic can be seen in this notch or alternatively the notch at this point has a color that matches the color of the banner in the area. How can something like this be realized? Or is that not possible?

3 Comments
2024/12/03
13:04 UTC

1

How to align images in row using CSS

Hello, I am trying to create a page where I would like four images per row. When I try to create this it keeps bringing a single column of pictures that are quite large on the screen. This is my code below

html

<!-- Rest of the New Arrivals content --><div id="new-arrivals-content"><!-- Content for new arrivals -->
	<div class="item">

		<img src="../images/cb/cb0.avif" alt="Item 1"

	</div>

	<div class="item">

		<img src="../images/cb/cb1.avif" alt="Item 2"

	</div>

	<div class="item">

		<img src="../images/cb/cb2.avif" alt="Item 3"

	</div>

	<div class="item">

		<img src="../images/cb/cb3.avif" alt="Item 4"

	</div>

	<div class="item">

		<img src="../images/cb/cb4.avif" alt="Item 5"

	</div>

	<div class="item">

		<img src="../images/cb/cb5.avif" alt="Item 6"

	</div>

	<div class="item">

		<img src="../images/cb/cb6.avif" alt="Item 7"

	</div>

	<div class="item">

		<img src="../images/cb/cb7.avif" alt="Item 8"

	</div>
</div>

css

/* Flexbox Layout for New Arrivals Content */

#new-arrivals-content {

display: flex;

align-items: center;

gap: 10px;

justify-content: center;

padding: 20px;

margin-top: 120px;

}

.item img {

max-width: 100%;

height: auto;

box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

transition: transform 0.3s ease;

}

.item img:hover {

transform: scale(1.05);

transition: transform 0.3s ease;

}

/* Responsive Design */

u/media screen and (max-width: 768px) {

.item {

width: 100%; /* 2 items per row on medium-sized screens */

}

}

u/media (max-width: 480px) {

.item {

width: 48%; /* 1 item per row on smaller screens */

}

}

10 Comments
2024/12/03
12:18 UTC

1

Smooth colour change

so im trying to make an color wheel, but i seem to have issues with the smooth color change. the wheel consists of 5 72deg parts. i like how each part has a noticable "wall" between them, but i wish the rainbow and black-red one could transition smoothly between theire own distinct colours

was thinking of maybe using linear-gradient for rainbow and black-red one, but found out that u cant put linear within conic. i dont know what to do there. this is how it currently looks like, and its ugly.

https://preview.redd.it/6vsrpo3bqk4e1.png?width=277&format=png&auto=webp&s=32fdd95c97d3bfe1ccf2b38ff603df5966f83401

#color-wheel {
    width: 250px;
    height: 250px;
    background: conic-gradient(
        #f7a8b8 0deg 72deg,           /* Spirit Blossom Pink */

        /* Black and Red Gradient (72deg to 144deg) */
        #2f2f2f 72deg 80deg,          /* Black */
        #4b0082 80deg 90deg,          /* Voided Purple to ease the transition */
        #8b0000 90deg 144deg,         /* Deep Red */

        /* Rainbow Gradient (144deg to 216deg) */
        #4b0082 144deg 150deg,        /* Start of Rainbow: Voided Purple */
        #ff6347 150deg 160deg,        /* Rainbow Orange */
        #ffeb3b 160deg 170deg,        /* Rainbow Yellow */
        #32cd32 170deg 180deg,        /* Rainbow Green */
        #00bcd4 180deg 190deg,        /* Rainbow Blue */
        #ff6347 190deg 200deg,        /* Rainbow Orange transition */
        #ffeb3b 200deg 210deg,        /* Rainbow Yellow transition */
        #32cd32 210deg 216deg,        /* Rainbow Green transition */
        
        /* Normal Gradient (216deg to 360deg) */
        #d1e7f2 216deg 288deg,        /* Light Blue */
        #4b0082 288deg 360deg         /* Voided Purple */
    );
    border-radius: 50%;
    transition: transform 0.5s ease;
}
2 Comments
2024/12/03
06:01 UTC

1

keyframes speed not changing

im trying to make a simmple wave go from one corner of the screen to the other, and i wanted to add randomness to the keyframe speed, but no matter what i do, it just wont change its speed.

const randomSpeeds = [ 
    Math.random() * (18 - 4) + 4, 
    Math.random() * (18 - 4) + 4, 
    Math.random() * (18 - 4) + 4, 
    Math.random() * (18 - 4) + 4, 
    Math.random() * (18 - 4) + 4 
];

const keyframes = `
    keyframes wave-flow { 
        0% { background-position: 0% 0%; animation-duration: ${randomSpeeds[0]}s; } 
        25% { background-position: 100% 100%; animation-duration: ${randomSpeeds[1]}s; } 
        50% { background-position: 0% 100%; animation-duration: ${randomSpeeds[2]}s; } 
        75% { background-position: 100% 0%; animation-duration: ${randomSpeeds[3]}s; } 
        100% { background-position: 0% 0%; animation-duration: ${randomSpeeds[4]}s; } } 
`;
2 Comments
2024/12/03
03:21 UTC

1

rotated div problem

Hi all, I'm trying to make a sidebar on a variable height div with 2 elements inside that have rotated text in them, 1 at the top of the div and 1 at the bottom. Here's a fiddle of it almost working:

https://jsfiddle.net/subL9ed0/

The containers are all variable height so I just put some random heights inline to show when it works or not. I think the main issue is there doesn't seem to be a way to fill the .inner div to the height of the .container, if I do width:100%; it gets smaller than it is now so I just set it to a height that works for the first div, but not the second (I won't know the height of each box in css during run time anyway, so technically the first is wrong too). I was thinking of just adding javascript to set the width of the each .inner div to the height of the parent but it seems like a really bad solution. Does anyone know how to do this in css only?

3 Comments
2024/12/03
02:18 UTC

1

How do i make my image's opacity darken, but only after it has been hovered over?

heres what i have:

<img src="Bird1.jpg" onmousover="this.src='bird2.jpg' " onmouseout="this.src='bird1.jpg' ">

style

#div: hover img { transition: 0.50s; opacity: 0.3; }

#div img:hover { opacity: 1; }

HOWEVER i would like bird1 to be a lower opacity, but only after it has switched to bird2. Does that make sense? any help is appreciated <3

5 Comments
2024/12/02
23:16 UTC

1

Compact Mode breaks FireFox User Style Change

I'm trying to do a modification to FireFox although there is one issue; when I enable compact mode since my address bar is at the bottom of the browser it breaks ?

2 Comments
2024/12/02
20:08 UTC

1

Should I use components?

I am not a new dev but new to the field of web dev. So I was creating a new app and I started using primeVue ( vue js lib ) for components. Is this a good idea? Or should I create things like toast and dialogs from scratch? Do real world projects use all these?

Thanks for taking your time to reply

8 Comments
2024/12/02
15:20 UTC

3

scroll-driven animations.

scroll-driven animations. Similar to how time-based animations work on the platform, you can now use a scroller's scroll progress to start, pause, and reverse an animation. So as you scroll forward, you'll see that animation progress, and when scrolling backward it'll go the other way around. This

https://developer.chrome.com/blog/new-in-web-ui-io-2024#scroll-driven-animation-visual

0 Comments
2024/12/02
14:27 UTC

75

found this amazing pokemon card effect

11 Comments
2024/12/02
11:54 UTC

1

Cannot seem to grasp CSS pesudo-elements and how they interact with different browsers

I have a neocities I've been making for school (granted, I am not going to school for web dev and have very little experience in it), and it seems like the website works great on my singular instance of Brave Browser. The issue seems to be with literally any other browser, even a separate instance of Brave on my laptop doesn't display the same.

What I'm attempting to do is have a music player at the top of my screen that doesn't use the standard webkit or moz appearances--hence why I'm styling it with CSS. It looks great on my instance and is exactly what I want it to be, but it seems like every other instance is being replaced with "user agent stylesheet" because the ::webkit pseudo-elements aren't functioning properly. I will provide all the relevant code and screenshots if someone is willing to help out.

Here's what I've tried:
- Using a CSS reset
- Using a CSS normalize
- Using the !important tag to make sure it takes precedent
- Using specificity like body, html, and #musicplayer
- Overwriting the default stylings through developer tools
- Checked for overwritten lines using dev tools (which has shown very different results across browsers)

Please, I've hit a brick wall and I'm really not sure where to go with it.

Here is what it looks like when it's working properly, I know it's not the prettiest thing but I like it.

Here is what it looks like in all other instances. All the things requiring webkit don't work now (controls, range slider, range thumb).

6 Comments
2024/12/02
08:58 UTC

1

The application loading section is not centered

https://preview.redd.it/b5avvre1rc4e1.png?width=1914&format=png&auto=webp&s=3247f86e8be10d938ca8f9d08f4b87a7556539cb

https://preview.redd.it/t69m04d8rc4e1.png?width=643&format=png&auto=webp&s=0f970ba25549f9f0268aa37d144a9895a1ae3cd6

The application loading section is not centered, what I showed in blue for some reason is not the full width, I need the section to be centered on the screen, it is centered on the HTML file, but the HTML file does not take up the full width of the screen.

7 Comments
2024/12/02
03:14 UTC

1

Tutorial on how you can create animations using css (vanilla)

I have started a YT series on front end web development for beginners and i uploaded a video on how you can create animations using pure css (vanilla). For creating animations you basically use keyframes rule. Inside this keyframes rule you can again use from{}to{} or you can use % to select a particular slot of time and apply styling at that point of time. In the video I have created a simple loading animation where a circle will rotate endlessly. If you a beginner and just getting started in front-end maybe watch the video. The series will be helpful.
Here is the link for it (for the video):
https://youtu.be/tiX0J6OfNvY

2 Comments
2024/12/01
18:26 UTC

1

How to do a responsive flex box layout in width and height?

Hello folks,

I thought I'm trying something very easy, but I feel somehow stuck. My layout has 4 box elements header, nav, main, footer. My goal is to have header and main below each other and nav right besides header and nav and below the nav the footer. The nav box has to be bigger than the header and footer can take the rest space but should not be longer than main.

You can find my approach further blow. It looks okay but when the layout becomes smaller the text in the footer pushes itself out of the footer box. How could I make this layout better that the layout can be contained, but the height of each box is more responsive?

Cheers!

My HTML starts like this:

<div class="holder">
<header>
    <h1>Header1</h1>
</header>

<nav>
    <ul>
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a></li>
        <li><a href="#">Link 3</a></li>
    </ul>
</nav>

<main>
    <p>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nihil, minima repellat qui minus iure 
        accusamus delectus veniam eligendi cumque ea aperiam, doloribus, modi perspiciatis in?
    </p>

    <p>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Illum aperiam quos voluptate neque 
        molestias dolores!
    </p>
</main>

<footer>
<p>
    orem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur similique neque atque quisquam? 
    Inventore, tempore illo. Ratione eos incidunt, voluptatum fugiat quam accusantium quia soluta, quasi 
    aperiam nesciunt temporibus nam.
</p>
</footer>

</div>

My css approach:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: lightgray;

}

.holder {
    display: flex;
    flex-flow: column wrap;
    min-width: 20rem;
    max-width: 60rem;
    height: 22rem;

    
}

.holder > header, nav, main, footer{
   padding: 0.5rem;

}

header {
    order: 0;
    background-color: lightgreen;
    height: 15%;
    width: 75%;


}

nav {
    order: 2;
    background-color: lightblue;
    height: 35%;
    width: 25%;

}

nav ul {
    list-style-type: none;
}

nav a {
    text-decoration: none;
}

main {
    order: 1;
    background-color: lightgreen;
    height: 85%;
    width: 75%;

}

main p {
    padding-bottom: 0.8rem;
}

footer {
    order: 2;
    background-color: yellow;
    height: 65%;
    width: 25%;
}
4 Comments
2024/12/01
12:25 UTC

108

Flex CSS

I texted my friend abt learning flex and his reply made me chuckle

11 Comments
2024/12/01
03:54 UTC

1

Styling the details element when expanded

Hi. I'm trying to get my details element to have a different list icon when expanded, but it's not working, I still get the default icon.

Here's my code:

details[open] > summary {list-style-image:url('close-button.svg');}

What am I doing wrong? Thanks for your help.

UPDATE: So, after trying the above, I tried

details[open] > summary::marker {list-style-image: url("close.gif");}

& it still doesn't work. For reference, I'm using the safari browser on iPhone SE 2nd Gen in the latest version of iOS 18.

Can someone help me with this? Thank you

8 Comments
2024/11/30
23:36 UTC

0

how to do this border style

hey guys,

i want to know how to do this kind of card i have tried clip-path css but not what i wanted since i cant round the clip-path

edit : added an exemple ^^

https://preview.redd.it/bi9jwt7xy74e1.png?width=1486&format=png&auto=webp&s=ab38d64b124597a10f411a229daadcddf4d61e22

17 Comments
2024/11/30
22:46 UTC

0

non-intrusive CSS framework advice

Context: I'm making some tampermonkey userscripts for my personal use. (Nothing complicated, just a few helpers and hotkeys.) Today I wanted to add an overlay with some custom UI to the page (again, nothing complicated, just a few inputs and buttons for a few custom settings).

So I thought "hey, there should be some minimalist CSS framework out there, to give me some basic styling for inputs and switches and buttons out of the box, that I could load from a CDN". One important restriction though: it should not apply any global styles, and all its classes should have prefixes to avoid interfering with the page I'm trying to modify.

I thought I'll find something relatively quickly, but everything I've tried so far, even the most lightweight frameworks like Pico CSS, add some reset styles to the global namespace (using selectors like `*, ::after, ::before`). At this point I'm ready to give up - it's easier to just go without any styling for my controls. (I know I could probably customize Tailwind to do what I need, but honestly it's just too much effort for my purpose.)

But maybe somebody knows of a framework that does what I need?

4 Comments
2024/11/30
22:02 UTC

Back To Top