Help with HTML and CSS

Hi,

I was wondering - how would I achieve something like this with HTML and CSS, any support would be greatly appreciated!

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://www.freecodecamp.org/learn.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / repl.it / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

2 Likes

That’s not a problem thank you for helping me understand how these forums work. Yes, so I’ve attempted to create this (to the best of my ability). Basically I was wondering rather than setting the left value to a fixed value (-26px or so in this case), is there any way to center the span element dynamically on the center of the border line?

https://codepen.io/mt1635/pen/pojewEq

<div class="container">
  <div class="information-box">
    <span class="icon"><span>#</span></span>
    <p>This is some example information.</p>
  </div>
</div>
@import url('https://fonts.googleapis.com/css?family=Montserrat:900|Open+Sans:300&display=swap');

body { margin-top: 5rem; font-family: 'Open Sans', sans-serif; }

.container
{
  @media screen and (min-width: 767px)
  {
    padding-left: 5rem;
    padding-right: 5rem;
  }
}

.information-box {
  
  position: relative;
  padding: 2rem;
  border: 2px solid #939CF2;
  
  .icon
  {
    
    position: absolute;
    display: block;
    width: 50px;
    height: 50px;
    background-color: #939CF2;
    border-radius: 100%;
    left: -26px;
    top: 50%;
    transform: translate(0, -50%);
    
    span {
      position: absolute;
      display: block;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-family: 'Montserrat', sans-serif;
      color: #ffffff;
      font-size: 1.5rem;
    }
    
  }
  
}

It should be as easy as calculating it:

:root {
  --pad: 2rem;
}
...
.information-box {
  padding: var(--pad);
}
.icon {
  left: -var(--pad);
}

Something like that. But, perhaps including the width of .information-box.

Hope this helps

1 Like