Place button side by side

Asked

Viewed 27,524 times

6

Hello wanted to have a back button and another to go to analysis, when I go to see the site they always appear on one the bottom and the other on top.

My code is:

 <a href="guardadorrebanhos.html">
      <p align="center"><input type="button" name="botao-voltar" value="Voltar">
 </a>

 <a href="guardadorrebanhos.html">
      <p align="center"><input type="button" name="botao-analise" value="Análise">
 </a>

And I can’t stand side by side.

  • Okay I already realized what had wrong. Had on the first button start the paragraph and end on the second.

  • 1

    Remove the tag <p> because it breaks into paragraphs, or uses css to format the paragraph width, but it’s not ideal. You can change the input for button.

  • And where PHP enters the story?

  • @Catarina Silvestre, you already solved the problem?

  • @Lucas yes I have. Thanks anyway.

3 answers

5

You have some problems with your current code:

Elements within the link tag:

The element <button/> cannot be inside the element <a/> what can be read in the documentation in: HTML5 Spec Document from W3C:

Content model: Transparent, but there must be no Interactive content Descendant.

The a element may be Wrapped Around entire paragraphs, lists, Tables, and so Forth, Even entire sections, so long as there is no Interactive content Within (e.g. Buttons or other links).

That translated:

Content template: transparent, but there should be no interactive content descending.

The element can be wrapped around whole paragraphs, lists, tables, and so on, even whole sections, as long as there is no interactive content within it (e.g., buttons or other links).

Closing of tags

The elements <p/> are not closed, which is why your code does not generate HTML as intended.

Solution

You can place both links inside a paragraph and format with CSS to get the desired look:

a{
    display:inline-block;
    text-decoration:none;
    padding:6px 4px;
    border:1px solid #ccc;
    background-color:#f2f2f2;
    color:#333;
    font:15px arial, sans-serif;
}
a:hover{
    border-color:#aaa;
}
<p>
    <a href="guardadorrebanhos.html">
        voltar
    </a>
    <a href="guardadorrebanhos.html">
        análise
    </a>
</p>

3

A tag does not apply <input> within a tag <a> and in this case it is only necessary to put the buttons in a table:

<table border="1">
   <tr>
     <td>
        <input type="button" name="botao-voltar" value="Voltar">
     </td>
     <td>
       <input type="button" name="botao-analise" value="Análise">
     </td>
   </tr>
  </table>
  • 3

    who voted against, give a better tip, tbm want to learn.. I would do so

  • 2

    A tip (I didn’t vote), use the tableless concept. Use table for data only.

0

Use the bootstrap

Just add your css and its classes to your components.

<html>
  <head>
    <meta charset="utf-8">
    <title>JS Bin</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
  </head>
  <body>
    <a class="btn btn-primary" href="guardadorrebanhos.html">Voltar</a>
    <a class="btn btn-primary" href="guardadorrebanhos.html">Análise</a>  
  </body>
</html>

Live demo

  • I believe that it is not the best option to add more than 100kb of CSS just to solve this problem

  • The bootstrap has numerous features that can be used throughout your web site, if you only want the button as in the example above, you can customize only for what you need. Including only the button component will have only 12kb more. Customize my bootstrap

Browser other questions tagged

You are not signed in. Login or sign up in order to post.