Centering text inside rounded rectangle vertically and horizontally

user4515590

I want center text inside rounded rectangle (both vertically and horizontally), and also center this banner on page too, not sure how to make this correctly. The other elements need be centered too. Please advice how to make things correctly. Here is code:

#wrapper {
  position: relative;
  width: 80%;
  margin: auto;
  text-align: center;
  vertical-align: middle;
}

#rcorners {
  border-radius: 15px;
  border: 6px solid #ffffff;
  padding: 20px;
  width: 450px;
  height: 40px;
}

body {
  background-image: url(images/blaunew.png);
  background-color: #001b33;
  color: #ffffff;
  font-family: 'Roboto';
  font-size: 14px;
}

#rcorners {
  font-family: 'Roboto';
  font-size: 48px;
  font-weight: 700;
  font-style: normal;
  Helvetica,
  sans-serif;
}

p {
  font-family: 'Roboto';
  font-size: 32px;
  Helvetica,
  sans-serif;
}

.main {
  margin-top: 20%;
  //font-size: 35px;       
}

footer {
  font-size: 14px;
}
<head>
  <title>centered construction</title>
  <link href='https://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>

</head>

<body>
  <div id="wrapper">
    <div class="main">
      <h1 id="rcorners">Centered Text No1</h1>
      <p>LOREM IPSUM DOLOR </p>
    </div>

    <footer>
      <div>&copy; Lorem Ipsum Dolor </div>
    </footer>
  </div>

Itay Ganor

remove width: 450px; and height: 40px from #rcorners.

Otherwise, if you want to keep it 450px wide, you may add margin: auto to #rcorners. It will solve your problem.

@import url('https://fonts.googleapis.com/css?family=Roboto:400,700');

#wrapper {
    position: relative;
    width: 80%; 
    margin: auto;
    text-align: center;
    vertical-align: middle;
}

 #rcorners {
    border-radius: 15px;
    border: 6px solid #ffffff;
    padding: 20px; 
    /* width: 450px;
    height: 40px;     */
}
body {
    background-image: url(images/blaunew.png);
    background-color: #001b33;
    color: #ffffff;
    font-family: 'Roboto';font-size: 14px;
}
#rcorners {
    font-family: 'Roboto';font-size:48px;font-weight:700; font-style:normal; Helvetica, sans-serif;
}
p {
    font-family: 'Roboto'; font-size: 32px; Helvetica, sans-serif; 
}

.main { 
   margin-top: 20%;
//font-size: 35px;       
}

footer {
   font-size: 14px;
}
<div id="wrapper">
    <div class="main">
         <h1 id="rcorners">Centered Text No1</h1>
         <p>LOREM IPSUM DOLOR </p>
         </div>

    <footer>
        <div>&copy; Lorem Ipsum Dolor </div>
       </footer>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Centering text (horizontally and vertically) in nav

From Dev

Centering text (horizontally and vertically) in nav

From Dev

Centering text vertically and horizontally in a flex item

From Dev

Centering img horizontally and vertically

From Dev

Centering vertically and horizontally a div inside another div in html and css

From Dev

Vertically centering text inside flexbox item

From Dev

Vertically centering a piece of text inside a div

From Dev

Centering text vertically, inside inline-block

From Dev

Vertically centering a piece of text inside a div

From Dev

Centering text inside a canvas rectangle (button)

From Dev

Centering text inside a canvas rectangle (button)

From Dev

Centering text vertically and horizontally in TextBlock and PasswordBox in windows store app

From Dev

Centering text vertically and horizontally in TextBlock and PasswordBox in windows store app

From Dev

Text inside a div to align both vertically and horizontally

From Dev

Centering Bootstrap navbar horizontally and vertically

From Dev

Vertically and Horizontally centering buttons in a div

From Dev

Centering Bootstrap navbar horizontally and vertically

From Dev

Centering a span horizontally after centering it vertically

From Dev

Vertically centering overflowed text

From Dev

Vertically centering text in a div

From Dev

Centering div both vertically and horizontally inside of 100% width relatively positioned div

From Java

CSS center text (horizontally and vertically) inside a div block

From Dev

Having problems vertically and horizontally centering div

From Dev

Vertically & horizontally centering a div with an image of variable size

From Dev

Centering div horizontally and vertically without distorting content

From Dev

centering an image in the Bootstrap slider both horizontally and vertically

From Dev

Centering bootstrap panel with rows vertically and horizontally

From Dev

Vertically centering inside a div with vh

From Dev

Centering Vertically an UL inside a DIV

Related Related

  1. 1

    Centering text (horizontally and vertically) in nav

  2. 2

    Centering text (horizontally and vertically) in nav

  3. 3

    Centering text vertically and horizontally in a flex item

  4. 4

    Centering img horizontally and vertically

  5. 5

    Centering vertically and horizontally a div inside another div in html and css

  6. 6

    Vertically centering text inside flexbox item

  7. 7

    Vertically centering a piece of text inside a div

  8. 8

    Centering text vertically, inside inline-block

  9. 9

    Vertically centering a piece of text inside a div

  10. 10

    Centering text inside a canvas rectangle (button)

  11. 11

    Centering text inside a canvas rectangle (button)

  12. 12

    Centering text vertically and horizontally in TextBlock and PasswordBox in windows store app

  13. 13

    Centering text vertically and horizontally in TextBlock and PasswordBox in windows store app

  14. 14

    Text inside a div to align both vertically and horizontally

  15. 15

    Centering Bootstrap navbar horizontally and vertically

  16. 16

    Vertically and Horizontally centering buttons in a div

  17. 17

    Centering Bootstrap navbar horizontally and vertically

  18. 18

    Centering a span horizontally after centering it vertically

  19. 19

    Vertically centering overflowed text

  20. 20

    Vertically centering text in a div

  21. 21

    Centering div both vertically and horizontally inside of 100% width relatively positioned div

  22. 22

    CSS center text (horizontally and vertically) inside a div block

  23. 23

    Having problems vertically and horizontally centering div

  24. 24

    Vertically & horizontally centering a div with an image of variable size

  25. 25

    Centering div horizontally and vertically without distorting content

  26. 26

    centering an image in the Bootstrap slider both horizontally and vertically

  27. 27

    Centering bootstrap panel with rows vertically and horizontally

  28. 28

    Vertically centering inside a div with vh

  29. 29

    Centering Vertically an UL inside a DIV

HotTag

Archive