HTML Buttons alignment?
Moin, hier eine kleine Seite die Nur 3 Knöpfe ausgibt. Habe jetzt leider das Problem, dass die Knöpfe nicht auf gleicher höhe sind, trotz des "vertical-align:top" bin noch sehr neu in html, hoffe ihr könnt helfen. LG
Nachtrag: Habe es mit Padding gelöst, vielleicht geht es trotzdem besser anders?
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
<style>
.subscribe-button
{
background-color: rgb(204, 0, 0);
color:white;
border:none;
border-radius:2px;
cursor:pointer;
margin-right:12px;
transition:opacity 0.2s;
padding-top:10px;
padding-bottom:10px;
padding-left:16px;
padding-right:16px;
vertical-align:top;
}
.subscribe-button:hover
{
opacity: 0.7;
}
.subscribe-button:active
{
opacity: 0.4;
}
.join-button:hover
{
background-color:
rgb(37, 25, 207);
color: white;
}
.join-button:active
{
opacity:0.7;
}
.join-button
{
background-color:white;
color:rgb(37, 25, 207);
border-color:rgb(37, 25, 207);
border-style:solid;
border-width:1px;
border-radius:2px;
cursor:pointer;
margin-right:8px;
transition:background-color 0.2s, color 0.2s, opacity 0.2s;
padding-left:5px;
padding-right:5px;
padding-top:4px;
padding-bottom:4px;
vertical-align:top;
}
.tweet-button
{
color:white;
background-color:rgb(67, 145, 235);
height:36px;
width:75px;
border:none;
border-radius:20px;
font-weight:bold;
font-size:15px;
cursor:pointer;
transition:box-shadow 0.15s;
transition:opacity 0.2s;
vertical-align:top;
}
.tweet-button:hover
{
box-shadow: 0px 5px 5px rgba(0,0,0,0.15);
}
.tweet-button:active
{
opacity:0.6;
}
</style>
<button class="subscribe-button">
SUBSCRIBE
</button>
<button class="join-button">
JOIN my channel
</button>
<button class="tweet-button">
Tweet
</button>
<btton
</body>
</head>
</html>
1 Antwort
Dein Markup beinhaltet zunächst einmal mehrere Fehler.
1) Der Doctype (erste Zeile) fehlt.
<!doctype html>
2) Dein Dokument hat keinen Titel. Der gehört in den head-Bereich.
<title>Some page title</title>
3) Das style-Element gehört in den head. Im body dürfen nur die Seiteninhalte stehen.
4) Vor dem schließenden body-Tag steht ein invalides Element (<bttn).
5) Das body-Element ist kein Kindelement des head. Die Struktur ist folgendermaßen:
html
- head
- body
Demzufolge sollte dein Dokument auch so aufgebaut sein:
<!doctype html>
<html>
<head>
<!-- document head meta data ... -->
</head>
<body>
<!-- document content ... -->
</body>
</html>
Zu deinem Problem:
Die oberen Kanten der Buttons befinden sich bereits auf gleicher vertikaler Linie. Du kannst zum Vergleich für das body-Element einen oberen Rahmen ziehen, dann siehst du es.
body { border-top: 1px solid }
hallo, die Fehler oben habe ich schon behoben, hab in den letzen paar stunden noch dazugelernt aber danke vielmals für die Antwort!