user3117275
user3117275

Reputation: 367

CSS center a div within a div

Stupid question, but I can't seem to figure this out.

I want the button that says: Get More Clients (underneath the computer on the right-hand side), to be centered underneath the computer. I'm not sure what I'm doing wrong. Thanks.

Here's the URL: http://www.sanfranciscocriminaldefenseattorney.net/

Js Fiddle Demo

Here's the HTML:

<div class="c2">
<div class="sidebar sidebar-primary theme-info-sidebar">
<div class="text_box">
<div class="gsb">
<div class="get_started">
<a class="button3" target="_blank" href="https://www.facebook.com/sharer/sharer.php?s=100&p[url]=http://themedy.com/themes/grind/&p[title]=Grind - A child theme for Thesis and Genesis&p[images][0]=http://themedy.com/wp-content/uploads/2012/09/grind-demo-header.jpg&p[summary]=">Get More Clients</a>
</div>
</div>
</div>
</div>

Here's the CSS:

columns > .c2 {
    box-sizing: border-box;
}
.sidebar {
    display: inline;
    line-height: 1.5;
}
.gsb {
    margin: 0 auto;
    width: 100%;
}
.get_started {
    margin: 0 auto;
    width: 100%;
}
.get_started .button3:before {
    display: inline-block;
    padding-right: 7px;
    vertical-align: middle;
}
.get_started .button3 {
    background: none repeat scroll 0 0 #2d609b;
    font-size: 18px;
    text-align: center;
    text-transform: none;
    width: 80%;
}
.button3 {
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    background-color: #cd3333;
    border-color: rgba(0, 0, 0, 0.15);
    border-image: none;
    border-style: solid;
    border-width: 0 0 4px;
    color: #fff;
    cursor: pointer;
    display: inline-block;
    font-size: 1.25rem;
    font-weight: bold;
    line-height: 28px;
    padding: 1rem 2.25rem 0.8125rem;
    text-decoration: none;
    text-transform: uppercase;
    width: auto;
}

Upvotes: 1

Views: 118

Answers (4)

Timothy
Timothy

Reputation: 1158

You can apply this CSS to a inner div:

#inner {
    margin: 0 auto;
}

demo

Upvotes: 1

Varinder
Varinder

Reputation: 2664

There seem be an 80% width on button .get_started .button3

Below should do the job:

.get_started {
    margin: 0 auto;
    width: 100%;
    text-align:center;
}
... some more styles ...
.get_started .button3 {
    background: none repeat scroll 0 0 #2d609b;
    font-size: 18px;
    text-align: center;
    text-transform: none;
    /*width: 80%;*/
    width:auto;
}

Upvotes: 3

cfx
cfx

Reputation: 3444

It seems like you want the button center aligned at lower screen widths because on a desktop it looks fine; it only appears skewed at lower breakpoints. The best way to do that is:

.get_started {
  text-align: center;
}

Upvotes: 3

Devin
Devin

Reputation: 7720

.get_started{width: 100%;
margin: 0px auto;
text-align: center;}
.get_started .button3{background: none repeat scroll 0px 0px #2D609B;
font-size: 18px;
text-align: center;
text-transform: none;
width: 40%;
margin: 0px auto;}

this code allows you to use any width you want, at the time I checked you had 40%, so you can change depending on your needs

Upvotes: 0

Related Questions