Leave image next to text

Asked

Viewed 272 times

1

I need to leave an image side by side with a text for a college job, I can only do using CSS, I’ll leave the image of how it has to be and the codes to help, I’ve tried everything but I can’t, in the case of classes they may have different name no problem.

That’s what I got so far

body {
    font-family: cursive;
}

p,
h1,
h2,
h3,
h4,
h5,
h6,
.rating {
    padding-left: 10px;
}

figure {
    width: 350px;
    margin: auto auto;
    border: 1px solid;
    border-radius: 30px 30px 30px 30px;
    box-shadow: 10px 10px 20px #000;

}

.cafe {
    width: 100%;
    border-radius: 30px 30px 0 0;
}

.rating {
    width: 90px;
    margin-top: 10px;
    display: inline;
}

.titulo {
    display: inline;
}

.distancia {
    display: inline;
    margin-left: 100px;
}

hr {
    width: 90%;
    height: 2px;
    background-color: #6f6f6f;
}

.dias {
    text-align: center;
}

.reservar {
    text-align: center;
    color: #61e1ff;
    font-size: 28px;
    margin-bottom: 15px;
}

.hora div{
    display: contents;
}

.relogio {
    display: inline;
}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Café</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <figure>
        <figcaption>
            <img src="imagens/cafe.jpg" class="cafe">
            <h2 class="titulo">Café Java</h2>
            <div class="distancia">
                <img src="imagens/marker.PNG">
                12km</div>
            <img src="imagens/5-star-rating.png" class="rating"> 4.8 (23)
            <h3>$$$ Café brasileiro</h3>

            <p>Experimente o melhor café da região, temos diversas opções de sabores</p>

            <hr />

            <h3 class="dias">Sexta a Domingo</h3>
            <img src="imagens/clock.PNG" class="relogio">
            <div class="hora">
                <div>5:30PM</div>
                <div>7:30PM</div>
                <div>9:30PM</div>
            </div>
            <div class="reservar">Reservar</div>
        </figcaption>
    </figure>

</body></html>

Como está

Como tem que ficar

4 answers

0

Bruno, all right? In this case, flexbox is the easiest way to help you with this problem. I added a div to wrap the image and the times.

<div class="alinhar">
   <img src="imagens/clock.PNG" class="relogio">
      <div class="hora">
         <div>5:30PM</div>
         <div>7:30PM</div>
         <div>9:30PM</div>
      </div>
 </div>

 .alinhar {
    display: flex;
    justify-content: center;
}

0

This code does what you need, just use this css and html.

When you want to align elements, use Flexbox, from a read on it here

.texto{
  display: inline;
}
.box {
   display: flex;
   align-items:center;
}
   

<div class="hora box">
  <img align="left" width="300" height="150" src='http://i.stack.imgur.com/dioLI.png'>
  <div class="texto">5:30PM</div>
  <div class="texto">7:30PM</div>
  <div class="texto">9:30PM</div>
</div>

  • It didn’t work, man, it has to be centered on the image I left there

  • put your complete code that you did, it has pq not not work

  • I edited the post, all right

0


I am posting a code below that I tested, I wrapped the classes in another so that there are no problems of one block overlapping the other, and added some adjustments in the codes already posted, follows:

.block {
    overflow: hidden;
    display: block;
    width: 100%;
}

.relogio {
    display: inline;
    float: left;
    margin-left: 15px;
    margin-right: 10px;
}

.hora {
    float: left;
}

<div class="block">
    <img src="https://www.heartofbiking.org.nz/assets/Uploads/HOB-Icon-Attract-25px.png" class="relogio">

    <div class="hora">
        <div>5:30PM</div>
        <div>7:30PM</div>
        <div>9:30PM</div>
    </div>
</div>

0

Opa Bruno, then, vi q vc used the display: inline; this is correct, however you need to use also the float: left; in all elements of the DIV, ok?

body {
    font-family: cursive;
}

p,
h1,
h2,
h3,
h4,
h5,
h6,
.rating {
    padding-left: 10px;
}

figure {
    width: 350px;
    margin: auto auto;
    border: 1px solid;
    border-radius: 30px 30px 30px 30px;
    box-shadow: 10px 10px 20px #000;

}

.cafe {
    width: 100%;
    border-radius: 30px 30px 0 0;
}

.rating {
    width: 90px;
    margin-top: 10px;
    display: inline;
}

.titulo {
    display: inline;
}

.distancia {
    display: inline;
    margin-left: 100px;
}

hr {
    width: 90%;
    height: 2px;
    background-color: #6f6f6f;
}

.dias {
    text-align: center;
}

.reservar {
    text-align: center;
    color: #61e1ff;
    font-size: 28px;
    margin-bottom: 15px;
}

.hora div{
    display: contents;
}

.relogio {
    display: inline;
}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Café</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <figure>
        <figcaption>
            <img src="imagens/cafe.jpg" class="cafe">
            <h2 class="titulo">Café Java</h2>
            <div class="distancia">
                <img src="imagens/marker.PNG">
                12km</div>
            <img src="imagens/5-star-rating.png" class="rating"> 4.8 (23)
            <h3>$$$ Café brasileiro</h3>

            <p>Experimente o melhor café da região, temos diversas opções de sabores</p>

            <hr />

            <h3 class="dias">Sexta a Domingo</h3>
            <img src="imagens/clock.PNG" class="relogio">
            <div class="hora">
                <div>5:30PM</div>
                <div>7:30PM</div>
                <div>9:30PM</div>
            </div>
            <div class="reservar">Reservar</div>
        </figcaption>
    </figure>

</body></html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.