Hello, I'm building a simple page using the css grid for the first time, and when I wanted to place an image with :before, it didn't take me indicating the path where it is located: "images/icon.png"... I was seeing the bibliography on the subject and I can't find what it can be. I pass code to see if you can guide me
.contenedor #contacto {
display: grid;
grid-template-columns: repeat(4, 1fr);
text-align: center;
font-size: 0.65em;
}
.contenedor #contacto #maipu .sede {
border-bottom: 1px solid #48887b;
margin-bottom: 5px;
font-size: 1.5em;
}
/*elementos de cada sede*/
.contenedor #contacto #maipu .dir {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 5px;
margin-bottom: 5px;
text-align: left;
align-items: end;
justify-content: center;
}
/*datos de cada sede*/
.contenedor #contacto #maipu .dir h3 {
grid-column-start: 2;
grid-column-end: -1;
position: relative;
}
.contenedor #contacto #maipu .dir h3::before {
content: url(http://ibemo.es/wp-content/uploads/2017/04/ubi-300x268.png);
position: absolute;
top:-100px;
left:-200px;
height: 10px;
width: 10px;
}
.contenedor #contacto #maipu{
padding: 10px 10px;
grid-column-start: 1;
grid-column-end: 5;
}
<div class="contenedor">
<div id="contacto">
<div id="maipu">
<h3 class="sede">MAIPÚ</h3>
<div class="dir">
<h3>Ozamis 309</h3>
</div>
</div>
</div>
</div>
It's just a fraction of the code so you can see how I'm proposing it. I have two problems 1) it does not take the image from the folder but it does show it when it is an internet image (with path http://... .) 2) when it takes the image it lets me position it but not modify the measurements
Thanks in advance
You have several errors in the selectors.
The first is that in CSS you refer to an element with class
.contenedor
while in HTML the most similar element has class.contenedor2
.On the other hand, as you are putting it, you are indicating that it must act on an element with
id=contacto
within an element withclass=contenedor
, and it should be an element that contains said id and class.The selector should be both together:
#contacto.contenedor2
, with no spaces between them. In this way you are telling it that it is an element with said id and said class.Correcting this, you would have the following form and it would work perfectly:
Your problem is relative paths, and how they work.
On one side you have the label:
<img src="imagenes/ubicacion.png" alt="icono de ubicacion">
And on the other you have the CSS rule :
We will start with the case of the label. Your image attribute
src
uses the relative pathimagenes/ubicacion.png
, which means that the browser will locate the place where this path is called from (the location of your HTML file since the path is in a tag printed in it), it will look for an images folder and there inside it will look for the image called location.png .The corresponding absolute path to this would be:
https://timondigital.com/tests/images/location.png
Path that is perfectly found by the browser.
Now let us review the second case. We start from where this CSS is located and call route
imagenes/ubicacion.png
. But here's the problem, your CSS file is not in the same directory as your HTML , so if the starting point of the path changes, shouldn't the relative path to reach the destination change as well?The absolute path from your CSS looks like this:
https://timondigital.com/tests/css/images/location.png
And since this path does not exist in your directory system, it returns a 404 .
Solution:
What I would do is change your relative paths so that they start searching from the root and once there, the path you are interested in is already searched.
HTML
CSS
That way you can use the same route regardless of where it is called from within your directory system.