[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HTML5 - How to center a simple button

Posted on 2014-07-16
5
Medium Priority
?
271 Views
Last Modified: 2014-07-16
How can I center a simple button

This does nothing

  <button class="button dhCenter">

.button.dhCenter {
    height:20px;  
    display: inline-block;
    text-align:center;
    border: 1px solid #639ecd;
      background-image: none;
      background-color: #639ecd;
    color: #fff;
    width:120px;
}
0
Comment
Question by:JElster
5 Comments
 
LVL 20

Expert Comment

by:n2fc
ID: 40199307
Try putting the buttons inside a div with the style

text-align:center;
margin:auto;

Open in new window

0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40199311
To start with, your button element is not well declared:
<button class="button dhCenter">My button</button>

Open in new window

Here's a working demo of your code: http://jsfiddle.net/AlexCode/mE25c/

What exactly isn't working?
0
 
LVL 16

Accepted Solution

by:
rbudj earned 1780 total points
ID: 40199335
This will center the button on the page:

<!doctype html>
<head>
<title></title>
<style type="text/css">
.button.dhCenter {
     height:20px;   
     display: inline-block;
     text-align:center;
     border: 1px solid #639ecd;
       background-image: none;
       background-color: #639ecd;
     color: #fff;
     width:120px;
 } 
 .wrapper {
 	width:120px;
 	margin:auto;
 }
</style>
<head>
<body>
<div class="wrapper">
<button class="button dhCenter">My button</button>
</div>
</body>
</html>

Open in new window

0
 
LVL 20

Expert Comment

by:n2fc
ID: 40199350
Updated his fiddle as example here:   http://jsfiddle.net/mE25c/4/

<div class=wrapper>
    <button class="button dhCenter">My button</button> 
</div>

Open in new window


.button.dhCenter {
    height:20px;
    display: inline-block;
    text-align:center;
    border: 1px solid #639ecd;
    background-image: none;
    background-color: #639ecd;
    color: #fff;
    width:120px;
}
.wrapper {
 text-align:center;
margin:auto;   
}

Open in new window

0
 
LVL 1

Author Comment

by:JElster
ID: 40199356
thanks!!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question