0

I need to center an img (the one with class=“key”, but floated elements prevent it. What technique should I use for centering it?

Thanks!

GitHub repo: https://github.com/CalogerN/beta-sign-up-split-layout

Live preview: https://calogern.github.io/beta-sign-up-split-layout/

body {
  margin: 0px;
  padding: 0px;
  font-size: 16px;
}

header {
  background-image: url(../img/bg-intro.svg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 643px;
}

.logo {
  float: left;
}

.wlogo {
  fill: white;
}

.key {
  height: 234px;
  position: relative;
  top: 200px;
}

.key-wrapper {
  display: block;
  margin: auto;
}
<section class="section-a">

  <header>

    <svg width="120" height="35" class="logo" *numbers* </svg>

    <div class="key-wrapper">

      <img src="img/illustration-main.svg" alt="a man with a key" class="key">

    </div>

  </header>

1 Answers1

0

Try it:

HTML Structure:

 <header>
    <div class="svg-wrap">
        <svg width="120" height="35" class="logo" *numbers*="" <="" svg=""></svg>
    </div>
    <div class="key-wrapper">
        <img src="img/illustration-main.svg" alt="a man with a key" class="key">
    </div>
</header>

CSS Structure :

  body {
  margin: 0px;
  padding: 0px;
  font-size: 16px;
}
header {
  background-image: url(../img/bg-intro.svg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 643px;
}
.wlogo {
  fill: white;
}
.svg-wrap {
  text-align: center;
  margin: 0 auto;
}
.key {
  height: 234px;
  position: relative;
  top: 200px;
}
.key-wrapper {
  display: block; 
  margin: auto;
}

Note: just wrap div of SVG tag that applied CSS that must be set center align.

HAPPY SINGH
  • 536
  • 4
  • 13
  • You didn't read well the question. I want to center the svg with "key" class not the other one with "logo" class. –  Aug 07 '19 at 05:44
  • okay dear @CalogeroNapoli please add this CSS .key-wrapper { text-align: center;} – HAPPY SINGH Aug 07 '19 at 05:48
  • I got it a point. please add in mobile view media query: .logo { float: none; margin: 0 auto; display: block; } and .logo { float: none; margin: 0 auto; display: block; } – HAPPY SINGH Aug 07 '19 at 05:55
  • The problem is that I need .logo to float: left. But I tried and the img is centered, The problem is that float it seems. –  Aug 07 '19 at 06:00