In addition to grouping common properties, you can eliminate unnecessary things such as:
ul#album-fotos li#foto05 { ... }
If a id
is unique on a page, you can go straight to id #foto05
, without having to write the huge path to it, already saving a lot of code and making it easier to read, thus getting:
#foto05{ ... }
This way, grouping all elements with common properties in the same rule, would look like this:
#foto01, #foto02, #foto03,
#foto04, #foto05, #foto06 {
background-position: 50% 50%;
background-size: 400px 400px;
background-color: #fff;
background-repeat: no-repeat;
}
The part of :hover
, also doesn’t make sense:
ul#album-fotos li#foto01:hover { ... }
ul#album-fotos li#foto02:hover { ... }
etc..
Well, if all the li
inside #album-fotos
suffer the same effect on :hover
, it makes no sense to separate using different id’s. A single rule would suffice:
#album-fotos li:hover{ ... }
This also works for other rules in your CSS, so overall:
#album-fotos {
width: 700px;
margin: 0 auto;
padding: 50px;
overflow: hidden;
list-style: none;
}
#album-fotos li {
float: left;
width: 200px;
height: 200px;
margin: 10px;
border: 5px solid #dddddd;
background-color: white;
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.4);
transition: all 0.3s ease-in;
}
#album-fotos li:hover {
background-position: 0 0;
background-size: 200px 200px;
transform: scale(1.5);
}
#foto01, #foto02, #foto03,
#foto04, #foto05, #foto06 {
background-position: 50% 50%;
background-size: 400px 400px;
background-color: #fff;
background-repeat: no-repeat;
}
#foto01 {
background-image: url('../imagens/galeria-01.jpg');
}
#foto02 {
background-image: url('../imagens/galeria-02.jpg');
}
#foto03 {
background-image: url('../imagens/galeria-03.jpg');
}
#foto04 {
background-image: url('../imagens/galeria-04.jpg');
}
#foto05 {
background-image: url('../imagens/galeria-05.jpg');
}
#foto06 {
background-image: url('../imagens/galeria-06.jpg');
}
#album-fotos li span {
opacity: 0;
color: white;
background-color: rgba(0, 0, 0, 0.3);
font-size: 11pt;
line-height: 370px;
padding: 5px;
}
#album-fotos li:hover span {
opacity: 1;
}
If all the <li>
in #album-fotos
are those that have id’s of 01
to 06
, nor would need it:
#foto01, #foto02, #foto03,
#foto04, #foto05, #foto06 {
background-position: 50% 50%;
background-size: 400px 400px;
background-color: #fff;
background-repeat: no-repeat;
}
Simply include the above properties within the style below:
#album-fotos li {
float: left;
width: 200px;
height: 200px;
margin: 10px;
border: 5px solid #dddddd;
background-color: white;
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.4);
transition: all 0.3s ease-in;
background-position: 50% 50%;
background-size: 400px 400px;
background-repeat: no-repeat;
}
Staying so now:
#album-fotos {
width: 700px;
margin: 0 auto;
padding: 50px;
overflow: hidden;
list-style: none;
}
#album-fotos li {
float: left;
width: 200px;
height: 200px;
margin: 10px;
border: 5px solid #dddddd;
background-color: white;
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.4);
transition: all 0.3s ease-in;
background-position: 50% 50%;
background-size: 400px 400px;
background-repeat: no-repeat;
}
#album-fotos li:hover {
background-position: 0 0;
background-size: 200px 200px;
transform: scale(1.5);
}
#foto01 {
background-image: url('../imagens/galeria-01.jpg');
}
#foto02 {
background-image: url('../imagens/galeria-02.jpg');
}
#foto03 {
background-image: url('../imagens/galeria-03.jpg');
}
#foto04 {
background-image: url('../imagens/galeria-04.jpg');
}
#foto05 {
background-image: url('../imagens/galeria-05.jpg');
}
#foto06 {
background-image: url('../imagens/galeria-06.jpg');
}
#album-fotos li span {
opacity: 0;
color: white;
background-color: rgba(0, 0, 0, 0.3);
font-size: 11pt;
line-height: 370px;
padding: 5px;
}
#album-fotos li:hover span {
opacity: 1;
}
Let’s see it working:
#album-fotos {
width: 700px;
margin: 0 auto;
padding: 50px;
overflow: hidden;
list-style: none;
}
#album-fotos li {
float: left;
width: 200px;
height: 200px;
margin: 10px;
border: 5px solid #dddddd;
background-color: white;
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.4);
transition: all 0.3s ease-in;
background-position: 50% 50%;
background-size: 400px 400px;
background-repeat: no-repeat;
}
#album-fotos li:hover {
background-position: 0 0;
background-size: 200px 200px;
transform: scale(1.5);
}
#foto01 {
background-image: url('https://http2.mlstatic.com/S_889901-MLB20440401736_102015-O.jpg');
}
#foto02 {
background-image: url('https://vignette.wikia.nocookie.net/monica/images/0/0a/Festa_turma_da_monica_painel_decorativo_anjinho_piffer.jpg/revision/latest?cb=20130930232726&path-prefix=pt-br');
}
#foto03 {
background-image: url('https://static1.squarespace.com/static/57a4a607f5e231c1eb1226ce/57aa06ef37c581879046603f/5b29055d758d460f539bbe74/1529415060473/JAr0-BQG_400x400.jpg');
}
#foto04 {
background-image: url('https://static1.squarespace.com/static/52557d46e4b0f3efcbd81dc8/t/5a395602085229099e52ea13/1527183612488/Final_HCD_Logo12072016_800X800.jpg');
}
#foto05 {
background-image: url('https://d2sg07zx6lm3f.cloudfront.net/s3fs-public/styles/square_cropped/public/instagram/46667487_739600606423067_5494384775873874429_n.jpg%3F_nc_ht%3Dscontent.cdninstagram.com?CccicumQOzt7CnJq0uLz0qlQ4mwzPe5D&itok=dOHlNMfU');
}
#foto06 {
background-image: url('https://static1.squarespace.com/static/5009914ee4b0779c48ca1d4a/578d75726a49637d20b62305/578d7572725e257ad6877c3e/1468889029160/About+%283%29.jpg');
}
#album-fotos li span {
opacity: 0;
color: white;
background-color: rgba(0, 0, 0, 0.3);
font-size: 11pt;
line-height: 370px;
padding: 5px;
}
#album-fotos li:hover span {
opacity: 1;
}
<ul id="album-fotos">
<li id="foto01">
<span>foto 1</span>
</li>
<li id="foto02">
<span>foto 2</span>
</li>
<li id="foto03">
<span>foto 3</span>
</li>
<li id="foto04">
<span>foto 4</span>
</li>
<li id="foto05">
<span>foto 5</span>
</li>
<li id="foto06">
<span>foto 6</span>
</li>
</ul>
Not even that big, rsrs, but there are ways to organize this better yes, creating variables for properties that you will use several times with the same value, or in the future you make bigger sites, a tip is to separate the CSS of each page into different files instead of leaving everything in the same CSS file
– Juliana Marques
https://codepen.io/valdeir2000/pen/qgoovQ?editors=1101
– Valdeir Psr
@Valdeirpsr liked the approach to the class name! It bothers you if I include in my reply, had not attacked me in this option :D
– hugocsl
@hugocsl May include.
– Valdeir Psr