0

Its looking like this

I want the icon to be near the text inside the round box but its appearing down, here's my code.

HTML:

    <div className="RoundBox">
                               
        <div className="DashImages"><img src={PDF} alt="PDF"></img>
        <div className="IconText">PDF File</div>
                              
    </div>

CSS:

 img {
  width: 3vw;
  height: 3vw;
  margin-left: 1vw;
}

.IconText {
}

    .RoundBox {
  border-radius: 0.5vw;
  border: 1.5px solid grey;
  box-shadow: #e3eaf6;
  width: 20vw;
  height: 3vw;
  float: left;
}
disinfor
  • 10,865
  • 2
  • 33
  • 44
  • 2
    just add `display:flex` to the `.RoundBox`. divs are block items so they will always try to fill the whole horizontal space if the display or width properties are not changed or the parent item overrides that behaviour (eg. using FlexBox) – Cornel Raiu Sep 23 '21 at 16:02
  • Welcome to Stack Overflow! What have you tried? It doesn't look like you attempted to put the two elements next to each other. There are plenty ways to do this. Also, you have an error in your HTML since you don't close the DashImages div. https://stackoverflow.com/a/24292602/1172189 – disinfor Sep 23 '21 at 16:02
  • 1
    Does this answer your question? [How to place div side by side](https://stackoverflow.com/questions/2637696/how-to-place-div-side-by-side) – Cornel Raiu Sep 23 '21 at 16:03
  • 2
    also `` looks like a mistake and should be `` – K i Sep 23 '21 at 16:10
  • Yess, all your comments helped me it worked I'm still fairly new to web dev so thanksss. – Youssef Moussa Sep 23 '21 at 16:14

2 Answers2

0

This should do the trick.

Div elements are block items so they will always try to fill the whole horizontal space if the display or width properties are not changed or the parent item overrides that behavior (eg. using FlexBox)

HTML

<div className="RoundBox">
                           
    <div className="DashImages"><img src={PDF} alt="PDF" /></div>
    <div className="IconText">PDF File</div>
                          
</div>

CSS

img {
  width: 3vw;
  height: 3vw;
  margin-left: 1vw;
}

.IconText {
padding-left: 10px
}

.RoundBox {
  border-radius: 0.5vw;
  border: 1.5px solid grey;
  box-shadow: #e3eaf6;
  width: 20vw;
  height: 3vw;
  float: left;
  display: flex;
  align-items: center;
}
Cornel Raiu
  • 2,758
  • 3
  • 22
  • 31
0

Your html is invalid with the image tag and you're missing a div. You would want to fix that first.

<div className="DashImages"><img src={PDF} alt="PDF" /></div>

You then have a couple options. Here are a two examples:

  1. You can simply add float: left to the img css. I might recommend using a class rather than a selector which targets all img tags. Example
img {
  width: 3vw;
  height: 3vw;
  margin-left: 1vw;
  float: left;
}
  1. You can also explore using flexbox adding display: flex; to your .RoundBox class. Note there are different alignment attributes that you can use to position elements using flex.

.RoundBox {
  border-radius: 0.5vw;
  border: 1.5px solid grey;
  box-shadow: #e3eaf6;
  width: 20vw;
  height: 3vw;
  float: left;
  display: flex;
}
krchun
  • 994
  • 1
  • 9
  • 19