So, i decided to use scroll snapping in the website i am creating, but for some reason, even after following 5/6 tutorials on youtube, none of them worked for me, i tried to add scroll snapping to each home div but that didn't work, so i changed 3 or 4 times this code, tried putting the snap type in container, in body, but none of that worked. (that's not the full css code, but only the important ones)
If anyone can help, i would appreciate.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: "Montserrat", sans-serif;
scroll-behavior: smooth;
}
html {
scroll-snap-type: y mandatory;
overflow-y: auto;
}
.container {
position: relative;
width: 100%;
height: 100%;
}
.body .home-1 .home-2 .home-3 .home-4 .home-5 .home-6 .home-7 .home-8 .home-9 .home-10 {
scroll-snap-align: start;
}
.home-1 {
height: 100vh;
width: 100%;
background-color: #DBDBDB;
display: flex;
position: absolute;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/main.css" type="text/css">
<title>Portfolio</title>
</head>
<body>
<div class="container">
<div class="home-1">
<div class="menu">
<p>Menu</p>
</div>
<div class="top-links">
About Me
Works
</div>
<div class="right-buttons">
<li onclick="toggleLanguage('English')">En</li>
<li onclick="toggleLanguage('Portuguese')">Pt</li>
</div>
<div class="logo-holder">
<div class="title-center"><img src="assets/imgs/sample-logo.png"></div>
</div>
<div class="bottom-links">
Instagram
Behance
</div>
<div class="email">
<p>alo#scarrard.co</p>
</div>
</div>
<div class="home-2">
</div>
<div class="home-3">
<div class="row">
<div class="column">
<h1>My name is <br>
Sabrina Carrard,<br>
I’m a graphic designer <br>
and passionate <br>
about creating <br>
things and animals. <br>
</h1>
<hr class="solid">
<p>Before we say goodbye, you can get in <br>
touch through my email in Portuguese, <br>
English and French (I’m learning that, <br>
so please, be kind). <br>
</p>
</div>
<div class="column-2">
<p>My formal education was in UTFPR,
where I graduated in graphic design
as well. I started to work still I was in
college, and worked with brands like
ONU, Abril, Red Balloon, Wise up,
Porcelanosa, Medianeira, SEBRAE,
Prata e Arte, Bel Pesce, Universidade
do Intercâmbio e Casa Paraíso
Ecológico. Today I like to consider
myself as a brand and editorial
designer, things I really enjoy
while I’m working on.
</p>
<p>I started to care about art when
I was in school. At the time, I was
obsessed with movies and used to
watch four or five movies a day (but
I was a fine student, I swear). After
that I fell in love with art in
my college days, especially art
history. Today I’m very interested
in the discussion between gender
and art. Female artists, what they
did and their stories, really caught me.
</p>
</div>
<div class="column-3">
<p>
Besides animals, other thing that
is really important to know is that
I’m fascinated by books and
literature. I truly believed that
literature opened my eyes to
important questions such as
human rights and feminism.
So when I’m reading something,
usually they are novels related
to these subjects because it
is something that I care about
</p>
</div>
</div>
</div>
<div class="home-4">
</div>
<div class="home-5">
</div>
<div class="home-6">
<div class="gallery">
<figure class="gallery__item gallery__item--1 ">
<img src="assets/imgs/projetopessoal/Saba/saba/imghome/imghome.png" class="gallery__img " alt="Image 1 ">
</figure>
<figure class="gallery__item gallery__item--2 ">
<img src="assets/imgs/projetopessoal/Aurora/aurora/imghome/imghome.png" class="gallery__img " alt="Image 2 ">
</figure>
<figure class="gallery__item gallery__item--3 ">
<img src="assets/imgs/projetopessoal/Tempodachuva/tempodachuva/imghome/imghome.png" class="gallery__img " alt="Image 3 ">
</figure>
<figure class="gallery__item gallery__item--4 ">
<img src="assets/imgs/projetopessoal/Zinebrabas/zinebrabas/imghome/SCARRARD-Portfolio_imagem home_Zine.jpg" class="gallery__img " alt="Image 4 ">
</figure>
<figure class="gallery__item gallery__item--5 ">
<img src="assets/imgs/projetopessoal/Bunker/bunker/home/imghome.png" class="gallery__img " alt="Image 5 ">
</figure>
</div>
</div>
<div class="home-7">
</div>
<div class="home-8">
</div>
<div class="home-9">
<div class="gallery">
<figure class="gallery__item gallery__item--1 ">
<img src="assets/imgs/marcasB/PrataEArte/Prata/imghome/SCARRARD-Portfolio_imagem home_Prata e arte.png" class="gallery__img " alt="Image 1 ">
</figure>
<figure class="gallery__item gallery__item--2 ">
<img src="assets/imgs/marcasB/Oliveira/oliveira/imghome/SCARRARD-Portfolio_imagem home_Oliveira.png" class="gallery__img " alt="Image 2 ">
</figure>
<figure class="gallery__item gallery__item--3 ">
<img src="assets/imgs/marcasB/Transformando/transformando/imghome/SCARRARD-Portfolio_imagem home_Tranformando.jpg" class="gallery__img " alt="Image 3 ">
</figure>
<figure class="gallery__item gallery__item--4 ">
<img src="assets/imgs/marcasB/CarinaDiniz/Carina/imghome/SCARRARD-Portfolio_imagem home_Carina Diniz.png" class="gallery__img " alt="Image 4 ">
</figure>
</div>
</div>
<div class="home-10">
</div>
</div>
</body>
</html>
Problem
The following CSS ruleset is wrong:
.body .home-1 .home-2 .home-3 .home-4 .home-5 .home-6 .home-7 .home-8 .home-9 .home-10 {
scroll-snap-align: start;
}
There's no class="body" in the HTML.
The selector only targets .home-10. When you list more than one tag, class, etc., how each part is delimited is very important:
Selector
Target
Declaration
.A {space} .B
.B
Target each .B that is a descendant of an .A
.A , .B
.A OR .B
Target all .A and all .B
.A > .B
.B
Target each .B that is a direct descendant (child) of an .A
.A + .B
.B
Target each .B that is the very next sibling of an .A
.A ~ .B
.B
Target each .B that is a sibling that proceeds an .A
.A.B
.A AND .B
Target all tags that have class="A B"
So if your intention was to target each of those classes, you need to delimit them with a comma:
.home-1, .home-2, .home-3, .home-4, .home-5, .home-6, .home-7, .home-8, .home-9, .home-10 {
scroll-snap-align: start;
}
#import url('https://fonts.googleapis.com/css2?family=Montserrat&family=Oswald:wght#300&display=swap');
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font: 2ch/1.25 Oswald;
scroll-snap-type: y mandatory;
scroll-behavior: smooth;
overflow-y: auto;
}
body {
background: #DBDBDB;
}
h1,
h2,
h3,
h4,
legend,
.byline,
.title {
font-family: Montserrat;
}
.byline {
font-style: italic;
}
header,
section,
footer {
padding: 10px 12px;
background: #DBDBDB;
scroll-snap-align: start;
}
header {
margin: 0 0 20px 0;
border-bottom: 3px inset grey;
}
section {
min-height: 100vh;
}
footer {
margin: 20px 0 0 0;
border-top: 3px inset grey;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
menu {
display: flex;
justify-content: space-around;
width: max-content;
list-style: none;
margin-left: 0;
}
.left,
.right {
display: flex;
align-items: center;
}
li {
margin: 0 5px
}
p {
margin-bottom: 5px;
}
.logo {
max-width: 3rem;
}
.logo img {
display: block;
object-fit: contain;
max-width: 3rem;
}
h1 {
margin-bottom: 10px
}
h2 {
margin-bottom: 5px
}
article {
padding: 5px 8px 8px;
flex: 1;
}
article:first-of-type {
flex: 0.5;
}
.row {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: flex-start;
margin: 10px;
}
.title {
margin-bottom: 0;
}
.gallery {
scroll-snap-align: none;
}
.gallery figure {
align-self: center;
margin: 10px;
scroll-snap-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/css/main.css" rel="stylesheet">
<title>Portfolio</title>
</head>
<body>
<header>
<h1>Sabrina Carrard</h1>
<nav>
<div class='left'>
<p class='title'>Menu</p>
<menu>
<li>About Me</li>
<li>Works</li>
</menu>
</div>
<div class='right'>
<menu>
<li><a href="#" class='en lang'>En</a></li>
<li><a href='#' class='pt lang'>Pt</a></li>
</menu>
<figure class="logo">
<img src="https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png"></figure>
</div>
</nav>
</header>
<main>
<section class='page'>
<div class="row">
<article class='column'>
<h2>My name is <br>Sabrina Carrard, </h2>
<p class='byline'>I’m a graphic designer and passionate about creating things and animals.</p>
</article>
<article class="column">
<p>My formal education was in UTFPR, where I graduated in graphic design as well. I started to work still I was in college, and worked with brands like ONU, Abril, Red Balloon, Wise up, Porcelanosa, Medianeira, SEBRAE, Prata e Arte, Bel Pesce,
Universidade do Intercâmbio e Casa Paraíso Ecológico. Today I like to consider myself as a brand and editorial designer, things I really enjoy while I’m working on.</p>
<p>I started to care about art when I was in school. At the time, I was obsessed with movies and used to watch four or five movies a day (but I was a fine student, I swear). After that I fell in love with art in my college days, especially art
history.
</p>
</article>
<article class="column">
<p>Today I’m very interested in the discussion between gender and art. Female artists, what they did and their stories, really caught me.</p>
<p>Besides animals, other thing that is really important to know is that I’m fascinated by books and literature. I truly believed that literature opened my eyes to important questions such as human rights and feminism. So when I’m reading something,
usually they are novels related to these subjects because it is something that I care about.</p>
</article>
</div>
</section>
<section class="gallery">
<div class='row'>
<figure>
<img src='https://placem.at/people?w=320&h=180&random=1&txt=1&txtclr=fc0' alt="">
</figure>
<figure>
<img src="https://placem.at/places?w=320&h=180&random=1&txt=2&txtclr=fc0" alt="">
</figure>
</div>
<div class='row'>
<figure>
<img src="https://placem.at/things?w=160&h=90&random=1&txt=3&txtclr=fc0" alt="">
</figure>
<figure>
<img src="https://placem.at/things?w=160&h=90&random=1&txt=4&txtclr=fc0" alt="">
</figure>
<figure>
<img src="https://placem.at/people?w=160&h=90&random=1&txt=5&txtclr=fc0" alt="">
</figure>
</div>
</section>
<section>
<h3>Blank Section</h3>
</section>
<section class="gallery">
<div class='row'>
<figure>
<img src='https://placem.at/things?w=480&h=270&random=1&txt=6&txtclr=fc0' alt="">
</figure>
</div>
<div class='row'>
<figure>
<img src="https://placem.at/things?w=480&h=270&random=1&txt=7&txtclr=fc0" alt="">
</figure>
</div>
<div class='row'>
<figure>
<img src="https://placem.at/places?w=720&h=405&random=1&txt=8&txtclr=fc0" alt="">
</figure>
</div>
<div class='row'>
<figure>
<img src="https://placem.at/places?w=320&h=160&random=1&txt=10&txtclr=fc0
" alt="">
</figure>
<figure>
<img src="https://placem.at/places?w=320&h=180&random=1&txt=11&txtclr=fc0
" alt="">
</figure>
</div>
</section>
<section>
<h3>Blank Section</h3>
</section>
</main>
<footer>
<p>Before we say goodbye, you can get in touch through my <a href='emailto:alo#scarrard.co'>email</a> in Portuguese, English, and French (I’m learning that, so please, be kind).</p>
<address>
Street<br/>
City, Province/State<br/>
Phone
</address>
</footer>
<script>
/*Always put script right before the </body> end tag*/
</script>
</body>
</html>
What am I doing wrong here?
I am brand new to the web development world.
I want to center these two images, and am having no such luck:
<!-- WHITE SPACE LOGO AREA -->
<div style="background-color:white;color:white;padding:20px;">
<img src="/wp-content/uploads/2017/01/affiliate-color-logo.jpg" alt="American Welding Society Member" class="midImg">
<img src="/wp-content/uploads/2017/01/ASNT-corp_mem_logo_webrgb.jpg" alt="ASNT Corporate Partner" class="midImg">
</div>
You can use the text-align: center, see this example:
<div style="background-color:white;color:white;padding:20px;text-align: center;">
<img src="/wp-content/uploads/2017/01/affiliate-color-logo.jpg" alt="American Welding Society Member" class="midImg">
<img src="/wp-content/uploads/2017/01/ASNT-corp_mem_logo_webrgb.jpg" alt="ASNT Corporate Partner" class="midImg">
</div>
But it is a better practice not to use inline styling, see the following improved code using classes and CSS:
.images {
background-color:white;
color:white;
padding:20px;
text-align: center;
}
<div class="images">
<img src="/wp-content/uploads/2017/01/affiliate-color-logo.jpg" alt="American Welding Society Member" class="midImg">
<img src="/wp-content/uploads/2017/01/ASNT-corp_mem_logo_webrgb.jpg" alt="ASNT Corporate Partner" class="midImg">
</div>
I am trying to put various figures inside a division or a section which has a particular background color! I can not understand why the below code is not working! Please help!
<div style="algin:center;width:100%;height:auto;background-color:#212121">
<figure class="snip1197">
<figcaption>
<blockquote>Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.</blockquote>
<div class="arrow"></div>
</figcaption>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sq-sample10.jpg" alt="sq-sample10"/>
</figure>
</div>
I'm not sure what you mean but you can just add some more pictures or what you want.
* {
color:white;
algin:center;
}
.test{
algin:center;
width:100%;
height:auto;
background-color:#212121;
}
.arrow{
float:left;
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid green;
}
.test2{
algin:center;
width:100%;
height:auto;
background-color:red;
}
<div class="test">
<figure class="snip1197">
<figcaption>
<div class="arrow">
</div>
<blockquote>
Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.
</blockquote>
</figcaption>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sq-sample10.jpg" alt="sq-sample10"/>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sq-sample10.jpg" alt="sq-sample10"/>
</figure>
</div>
<!-- or with a figcaption for every picture and multiple figures in one div -->
<div class="test2">
<figure class="fig1">
<figcaption>
<div class="arrow">
</div>
<blockquote>
Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.
</blockquote>
</figcaption>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sq-sample10.jpg" alt="sq-sample10"/>
</figure>
<figure class="fig2">
<figcaption>
<div class="arrow">
</div>
<blockquote>
Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.
</blockquote>
</figcaption>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sq-sample10.jpg" alt="sq-sample10"/>
</figure>
</div>
i am guessing you want the image to blend on the background-color . you can use background-blend-mode for that. but you need to set background-color and background-image on the same element.
in the below example i used them on the div
see snippet or > jsfiddle
<div style="text-align:center;width:100%;height:auto;
background-color:#212121;background-blend-mode:multiply;
background-image:url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sq-sample10.jpg');
height:500px;
background-repeat:no-repeat;
background-position:center 100px">
<figure class="snip1197">
<figcaption>
<blockquote>Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.</blockquote>
<div class="arrow"></div>
</figcaption>
</figure>
</div>
P.S. 1) alignwas written wrong (algin ) and also align:center does not exist
P.S. 2) the above code is just an example. your question lacks a proper explanation on what you want to achieve
I have 3 icons that i want to align them in the center i tried different code but nothing is working so far, i tried putting a margin right to it, but the problem with that is that it's adding an unnecessary space between them, so i want them to be close to each other, is there a way to put margin-right to it and remove the space from there ?
i just want to align them below my paragraph but in the center of it.
heres my code so far.
#body a img {
width: 50px;
height: 50px;
margin-top: 50px;
margin-right: 200px;
}
<div id="body">
<p class="text">We are a group of friends that enjoy playing League Of Legends togather, feel free to follow us on our different website medias</p>
<div class="icons">
<a href="https://www.youtube.com/themunkiuke">
<img class="icon1" src="images/youtube.png">
</a>
<a href="http://www.twitch.tv/siminios">
<img class="icon2" src="images/twitch.png">
</a>
<a href="http://yinochi.deviantart.com/gallery/">
<img class="icon3" src="images/art.png">
</a>
</div>
Will it be a simple text-align missing ?
#body a img {
width: 50px;
height: 50px;
}
.icons {
text-align:center;
}
<div id="body">
<p class="text">We are a group of friends that enjoy playing League Of Legends togather, feel free to follow us on our different website medias</p>
<div class="icons">
<a href="https://www.youtube.com/themunkiuke">
<img class="icon1" src="images/youtube.png">
</a>
<a href="http://www.twitch.tv/siminios">
<img class="icon2" src="images/twitch.png">
</a>
<a href="http://yinochi.deviantart.com/gallery/">
<img class="icon3" src="images/art.png">
</a>
</div>
Here you are DEMO
#body a img {
width: 50px;
height: 50px;
}
.icons {
text-align: center;
}
<div id="body">
<p class="text">We are a group of friends that enjoy playing League Of Legends togather, feel free to follow us on our different website medias</p>
<div class="icons">
<a href="https://www.youtube.com/themunkiuke">
<img class="icon1" src="images/youtube.png">
</a>
<a href="http://www.twitch.tv/siminios">
<img class="icon2" src="images/twitch.png">
</a>
<a href="http://yinochi.deviantart.com/gallery/">
<img class="icon3" src="images/art.png">
</a>
</div>
Here's a demo https://jsfiddle.net/r4wwczao/
In HTML I added a container for each icon to give them a percent size (the border is just to see the solution better):
<div id="body">
<p class="text">We are a group of friends that enjoy playing League Of Legends togather, feel free to follow us on our different website medias </p>
<div class="icons">
<div class="icon_div">
<img class="icon1" src="images/youtube.png">
</div>
<div class="icon_div">
<img class="icon2" src="images/twitch.png">
</div>
<div class="icon_div">
<img class="icon3" src="images/art.png">
</div>
</div>
</div>
And CSS:
img{
width: 50px;
height: 50px;
}
.icon_div{
border:1px black solid;
display: inline-block;
text-align: center;
width:32%;
}
Hi HTML5 and CSS newbie here,
We had to create an interests page for our final project so I used 8 images stacked left to right contained in individual div containers with a caption that only appears when you hover over the photo. It looks fine in Chrome and Firefox, but in IE all the photos are everywhere. Any help would be appreciated:
HTML:
<section>
<div class="interests">
<img src="music.png" alt="Musician" id="musician">
<p class="caption" id="musicP">I love all genres of music.</p>
</div>
<div class="interests">
<img src="movies.png" alt="Popcorn" id="popcorn">
<p class="caption" id="movieP">Favorite romance comedy is Sleepless in Seattle</p>
</div>
<div class="interests">
<img src="reddit.png" alt="Reddit" id="reddit">
<p class="caption" id="redditP">I love Reddit. I spend way too much time there.</p>
</div>
<div class="interests">
<img src="reading.png" alt="Books" id="books">
<p class="caption">I only read fiction books.</p>
</div>
<div class="interests">
<img src="cooking.png" alt="Cooking" id="cooking">
<p class="caption" id="cookingP">Favorite food is sushi</p>
</div>
<div class="interests">
<img src="videogames.png" alt="Video Games" id="games">
<p class="caption">I'm playing Animal Crossing right now.</p>
</div>
<div class="interests">
<img src="football.png" alt="Football Game" id="football">
<p class="caption">My favorite player is Peyton Manning!</p>
</div>
<div class="interests">
<img src="travel.png" alt="Globe" id="travel">
<p class="caption">I'd like to visit Germany soon.</p>
</div>
</section>
CSS:
/*Styles for the Interests Page*/
/*Floats all the photos to the left*/
.interests {
float: left;
}
/*Styles for individual photos*/
#cooking{
height: 180px;
margin-left: 100px;
}
#books{
width: 240px;
height: 169px;
}
#games{
height: 180px;
}
/*Photo Caption Styles*/
.caption{
font-size: 70%;
visibility: hidden;
opacity: 0;
}
.interests:hover .caption{
visibility: visible;
opacity: 1;
}
#cookingP{
margin-left: 100px;
width:200px;
}
Thanks!
instead of
<img src="music.png" alt="Musician" id="musician">
close all your images to have a closing
<img src="music.png" alt="Musician" id="musician"/>
you are missing / in your image tags
Don't use floats. Use display:table on the <section> tag, display:table-cell on all the interest class divs, and wrap a div around the rows with the style display:table-row.
http://www.w3schools.com/cssref/pr_class_display.asp