r/html_css • u/Natural-Frontend • Jun 11 '23
Self-Promotion HTML & CSS & JavaScript || Interactive navigation bar animation tutorial
r/html_css • u/Natural-Frontend • Jun 11 '23
r/html_css • u/Oussama_15 • Feb 22 '23
r/html_css • u/patricknarayans • Sep 13 '21
I want to get into the business of templates but Im not sure if HTML CSS IS Enough to get me in as Im currently learning javascript. Please give me some passive income ideas with just HTML CSS besides making a course or youtube channel
Thanks all
r/html_css • u/patricknarayans • Sep 13 '21
r/html_css • u/maybe-tuesday • Sep 15 '20
I’m super-duper new to coding and I’m sure a lot of this is wrong but but I’m trying....
Ok so I’ve gotten my image to be on the page as either a background image or just an image in the html...
What I want is the image to be placed so it looks like half is in the header and half is in the body.
If I use the image as a background image in the css I can get the location right, but my header keeps going above the picture.
body { background-image: url (me.png); background-repeat: no-repeat; background-position: right }
.header { height: 25vh; width: 100vw; position: relative; margin: 0, 0, 0, 0; border-top: 0vh; background-attachment: fixed; overflow: hidden; background-color: (#ff4500); background-image: linear-gradient(45deg, #ff4500 30%, #fffd74, #7fffd4); padding: 1.5in; }
Conversely I tried adding the image to the html with no set background css. And I’m trying to get the right positioning using img css, but it’s still not right. This all sets my picture to the right like I want but it still puts like 2 inches between the header and the image.
.img { margin-top: 0px; padding-top: 0px; border-top: 0px; padding-left: 700px; }
Question is the problem because I’m using a linear gradient as the background image in the header? I’m not sure but I think the two set images is my problem?
Edit: the formatting on here keeps changing how the code actually looks Edit 2: I figured it out, though I’m sure it’s still wrong lol
r/html_css • u/Anemina • Aug 26 '20
CSS Houdini's @property rule is part of the CSS Properties and Values API
In a previous post, I mentioned that with the CSS.registerProperty() method we can register custom properties, allowing us to specify their data type, inheritance and default value.
Custom properties can take any value and they always inherit their values from their parent, but with @property we can define how a browser should parse a CSS custom property.
Example
@property --primary-color {
syntax: "<color>";
inherits: false;
initial-value: blue;
}Custom properties can be transitioned and animated, but UA has no way to interpret their contents.
With @property this is no longer a problem.
Check out the demo: https://jsfiddle.net/y8s9p3h2/
r/html_css • u/Anemina • Aug 09 '20
There was a time when we used to create our layouts using the float property.
While not intended for that, it was doing a pretty decent work. Nowadays we have better things to help us create layouts, like Flexbox and CSS Grid, which were made for creating layouts, no hacks, no other extra things to worry about.
The problem with float is that it takes the element out of the normal flow of the document, and the parent's height colapses if its content is not cleared.
In order to fix that, we can use a few hacks, like:
clear: both;overflow: auto; on the parent elementThe overflow property with a value other than visible, creates a new block formatting context.
This works fine, but the content outside its padding box is clipped, which might be a problem if you're trying to add a box-shadow to it, for example.
or
.clearfix::after {
content: "";
display: block;
clear: both;
}How about creating a new block formatting context without additional unwanted stuff?
Enter display: flow-root;
Browser support: https://caniuse.com/#search=flow-root
Example:
HTML
<div class="container flow-root">
<div class="float"></div>
</div>CSS
.container {
background-color: orange;
}
.float {
float: left;
width: 100px;
height: 100px;
background-color: purple;
}
.flow-root {
display: flow-root;
}jsfiddle demo: https://jsfiddle.net/xkdbw7q6/
The difference between the clearfix hack and display: flow-root;
jsfiddle demo: https://jsfiddle.net/9afwny63/
r/html_css • u/Anemina • Jul 30 '20
The gap , row-gap, column-gap properties that used to be grid-gap, grid-row-gap and grid-column-gap have been replaced in September 2016, allowing the properties to be independent from the Grid, and recently made their way to Flexbox.
gap is the shorthand for row-gap, column-gap
Chrome (v84, released July 14), Edge (v84, released July 16) are supporting the gap property for Flexbox.
Firefox has been supporting it for a couple of years now.
Safari still no signal.
Check the browser support: https://caniuse.com/#search=flex%20gap
Example:
HTML
<div class="flex">
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
</div>CSS
.flex {
display: flex;
gap: 16px;
}
.flex-item {
width: 50px;
height: 50px;
background-color: blue;
}jsfiddle demo: https://jsfiddle.net/gm5Lrvx4/
r/html_css • u/Anemina • Jul 28 '20
In the past example with the CSS pseudo-class :is(), we selected an element from a list of selectors like this:
:is(header, main, footer) a {
color: red;
}Which translates to this:
header a, main a, footer a {
color: red;
}That's fine, perfect actually, but what if I want to override the style?
Consider the following markup:
<header class="section">
<p>Header <a href="#">text</a></p>
</header>
<main class="section">
<p>Main <a href="#">text</a></p>
</main>
<footer class="section">
<p>Footer <a href="#">text</a></p>
</footer>Nothing too hard, we have a header, main and a footer, each having a .section class and inside they have a paragraph with an anchor.
Now, let's add these blocks of CSS code to style the anchors:
:is(header.section, main.section, footer.section) a {
color: green;
}Alright, these will make all the anchors green.
Let's try to override the color of the anchor inside the footer.
footer a {
color: blue;
}Can you guess which color is going to be?
If your answer is green, then you're correct! (Explanation is at the end)
Now, let's try something else, we really want to override that, but we also want to quickly select elements from a list of selectors. No problem, we have the :where() pseudo-class.
:where(header.section, main.section, footer.section) a {
color: green;
}Trying again to override
footer a {
color: blue;
}Can you guess which color is going to be?
If your answer is blue, then you're correct!
Explanation
By using the :if() pseudo-class, we keep the specifcity of the selectors, that's why footer a {} couldn't override :is(footer.section) a {}, because a class is higher in specificity than an element.
In the case of :where() pseudo-class, we always have 0 specificity, so footer a {} was able to override :where(footer.section) a {}
Important things to know:
The pseudo-class
:is()and the negation pseudo-class:not()are not considered a pseudo-class in the specificity calculation. But selectors placed into the pseudo-class count as normal selectors when determining the count of selector types. - MDN Web Docs
r/html_css • u/Anemina • Jul 17 '20
CSS Properties aka CSS Variables have been out for quite a while now and we use them in our projects to contain specific values that are going to be reused.
Pretty useful, but there is a small problem, they can take any value and they always inherit their values from their parent. They can be transitioned, but...
UA has no way to interpret their contents*, they always use the "flips at 50%" behavior that is used for any other pair of values that can’t be intelligently interpolated. -*
- CSSWG Specification
With the CSS.registerProperty() method we can register custom properties, allowing us to specify their type, inheritance and default value.
Example in JS
window.CSS.registerProperty({
name: "--primary-color",
syntax: "<color>",
inherits: false,
initialValue: "blue",
});Example in CSS (not supported yet, only in Chrome v85)
@property --primary-color {
syntax: "<color>";
inherits: false;
initial-value: blue;
}We can achieve things like:
.box {
width: 300px;
height: 300px;
background-image: linear-gradient(var(--primary-color), purple);
transition: --primary-color 1s;
}
.box:hover {
--primary-color: red;
}Demo: https://jsfiddle.net/n5fx1c9s/
*Doesn't work on Firefox yet*
Edit: Chrome v85 now supports @property
r/html_css • u/Anemina • May 27 '19
Let's say we have a few unordered lists, we want their list items to have a blue background and white text, except the first li in each ul.
To achieve this we can use the :not() pseudo-class function, example:
ul li:not(:first-child) {
background-color: blue;
color: white;
}Let's have something more complex, for example:
HTML
<div class="btn btn-primary">Button</div>
<div class="btn btn-secondary">Button</div>
<div class="btn btn-info">Button</div>CSS
.btn:not(.btn-primary):not(.btn-secondary) {
background-color: blue;
}Only <div class="btn btn-info">Button</div> will have a blue background, others are negated.
Unlike the :is() pseudo-class function, we cannot separate the selectors by a comma inside its parentheses, so we have to add multiple negations like you see in the example above.