+1 vote
28 views
by (163k points)

I attempted to center my <apex:commandButton> with <div align="center"> but it places it sort of between the center and the right side instead. Why might this be?

enter image description here

VF Markup snippet

          <!--Submit button-->
      <!--PageBlock starts-->
      <apex:pageBlock>
      <apex:pageBlockButtons location="top">
      <div align="center">
            <apex:commandButton action="{!save}" value="Submit Referral"/>
             </div>
      </apex:pageBlockButtons>
          <br/>
          <br/>
      <div style="text-align:center">
      <p>By clicking this button, you are agreeing to start the registration process.</p>
      </div>
    </apex:pageBlock>
    <!--PageBlock ends-->
  </apex:form>
</apex:page>

1 Answer

+1 vote
by (163k points)
 
Best answer

The default apex:pageBlock header includes a "title", even if you don't include a title. Thus, the buttons are centered, but with space for a title. To get it absolutely centered, you need to override the entire header:

<apex:pageBlock>
 <apex:facet name="header">
  <div class="text-align: center">
   <apex:commandButton value="Whatever" action="{!whatever}" />
  </div>
 </apex:facet>
 ...
</apex:pageBlock>
Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
...