CSS Dersleri 49 - Buton Yapımı

CSS Dersleri 49 - Buton Yapımı


Merhaba değerli Kodlama Vakti takipçileri, bu dersimizde CSS'de Buton Yapımı Konusunu öğreneceğiz.

Aşağıdaki örnekte, HTML'de nasıl buton tanımlandığını ve biçimlendirmeyi görmektesiniz.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}
</style>
</head>
<body>

<h2>CSS Buton Yapımı</h2>

<button>Varsayılan Buton</button>
<a href="#" class="button">Link Buton</a>
<button class="button">Buton</button>
<input type="button" class="button" value="Input Buton">

</body>
</html>

Buton Renklendirme

Bir butonun arka plan rengini değiştirmek için background-color özelliğini kullanabiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button2 {background-color: #008CBA;} /* Mavi */
.button3 {background-color: #f44336;} /* Kırmızı */ 
.button4 {background-color: #e7e7e7; color: black;} /* Gri */ 
.button5 {background-color: #555555;} /* Siyah */
</style>
</head>
<body>

<h2>Renkli Butonlar</h2>

<button class="button">Yeşil</button>
<button class="button button2">Mavi</button>
<button class="button button3">Kırmızı</button>
<button class="button button4">Gri</button>
<button class="button button5">Siyah</button>

</body>
</html>

Buton Boyutlandırma

Bir butonun yazı tipi boyutunu değiştirmek için font-size özelliğini kullanabiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {font-size: 10px;}
.button2 {font-size: 12px;}
.button3 {font-size: 16px;}
.button4 {font-size: 20px;}
.button5 {font-size: 24px;}
</style>
</head>
<body>

<h2>Buton Boyutu</h2>

<button class="button button1">10px</button>
<button class="button button2">12px</button>
<button class="button button3">16px</button>
<button class="button button4">20px</button>
<button class="button button5">24px</button>

</body>
</html>

Bir butonun padding değerini değiştirerek boyutunu ayarlayabiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {padding: 10px 24px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px 16px;}
.button5 {padding: 16px;}
</style>
</head>
<body>

<h2>Buton Padding</h2>


<button class="button button1">10px 24px</button>
<button class="button button2">12px 28px</button>
<button class="button button3">14px 40px</button>
<button class="button button4">32px 16px</button>
<button class="button button5">16px</button>

</body>
</html>

Yuvarlak Buton Yapımı

Bir butona yuvarlatılmış köşeler eklemek için border-radius özelliğini kullanabiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {border-radius: 2px;}
.button2 {border-radius: 4px;}
.button3 {border-radius: 8px;}
.button4 {border-radius: 12px;}
.button5 {border-radius: 50%;}
</style>
</head>
<body>

<h2>Yuvarlak Butonlar</h2>

<button class="button button1">2px</button>
<button class="button button2">4px</button>
<button class="button button3">8px</button>
<button class="button button4">12px</button>
<button class="button button5">50%</button>

</body>
</html>

Butonun Kenarlarını Renklendirme

Bir butona renkli bir kenarlık eklemek için border özelliğini kullabiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {
  background-color: white; 
  color: black; 
  border: 2px solid #4CAF50;
}

.button2 {
  background-color: white; 
  color: black; 
  border: 2px solid #008CBA;
}

.button3 {
  background-color: white; 
  color: black; 
  border: 2px solid #f44336;
}

.button4 {
  background-color: white;
  color: black;
  border: 2px solid #e7e7e7;
}

.button5 {
  background-color: white;
  color: black;
  border: 2px solid #555555;
}
</style>
</head>
<body>

<h2>CSS Buton Yapımı</h2>

<button class="button button1">Yeşil</button>
<button class="button button2">Mavi</button>
<button class="button button3">Kırmızı</button>
<button class="button button4">Gri</button>
<button class="button button5">Siyah</button>

</body>
</html>

CSS'de Animasyonlu Buton Yapımı

CSS'de bir butonun üzerine fare ile geldiğinizde, düğmenin stilini değiştirmek için :hover seçicisini kullanırız.

İpucu: "Hover" efektinin hızını belirlemek için transition-duration özelliğini kullanabiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 16px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  transition-duration: 0.4s;
  cursor: pointer;
}

.button1 {
  background-color: white; 
  color: black; 
  border: 2px solid #4CAF50;
}

.button1:hover {
  background-color: #4CAF50;
  color: white;
}

.button2 {
  background-color: white; 
  color: black; 
  border: 2px solid #008CBA;
}

.button2:hover {
  background-color: #008CBA;
  color: white;
}

.button3 {
  background-color: white; 
  color: black; 
  border: 2px solid #f44336;
}

.button3:hover {
  background-color: #f44336;
  color: white;
}

.button4 {
  background-color: white;
  color: black;
  border: 2px solid #e7e7e7;
}

.button4:hover {background-color: #e7e7e7;}

.button5 {
  background-color: white;
  color: black;
  border: 2px solid #555555;
}

.button5:hover {
  background-color: #555555;
  color: white;
}
</style>
</head>
<body>

<h2>Animasyonlu Butonlar</h2>

<p>CSS'de bir butonun üzerine fare ile geldiğinizde, düğmenin stilini değiştirmek için :hover seçicisini kullanırız..</p>
<p><b>İpucu</b>: "Hover" efektinin hızını belirlemek için transition-duration özelliğini kullanabiliriz.
</p>

<button class="button button1">Yeşil</button>
<button class="button button2">Mavi</button>
<button class="button button3">Kırmızı</button>
<button class="button button4">Gri</button>
<button class="button button5">Siyah</button>

</body>
</html>

Buton Gölgelendirme

Bir butona gölge eklemek için box-shadow özelliğini kullanılır.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  -webkit-transition-duration: 0.4s; /* Safari */
  transition-duration: 0.4s;
}

.button1 {
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}

.button2:hover {
  box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
</head>
<body>

<h2>Buton Gölgelendirme</h2>

<p>Bir butona gölge eklemek için box-shadow özelliğini kullanılır.</p>

<button class="button button1">Gölgeli Buton</button>
<button class="button button2">Üzerine Gelindiği Zaman</button>

</body>
</html>

Butonu Pasif Yapmak

Bir butona saydamlık ekleyip pasife almak için opacity özelliğini kullanabiliriz. ("devre dışı" bir görünüm oluşturur).

İpucu: cursor özelliğini "not-allowed" değeri eklersek; fareyle düğmenin üzerine geldiğinizde tıklama işlemi gerçekleşmez.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
</style>
</head>
<body>

<h2>Pasif Buton Yapımı</h2>

<p>Bir butona saydamlık ekleyip pasife almak için opacity özelliğini kullanabiliriz. ("devre dışı" bir görünüm oluşturur).</p>

<button class="button">Normal Buton</button>
<button class="button disabled">Pasif Buton</button>

</body>
</html>

Buton Genişliği

Varsayılan olarak, bir butonun boyutu metin içeriğine göre belirlenir. Bir butonun genişliğini değiştirmek için width özelliğini kullanırız.

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {width: 250px;}
.button2 {width: 50%;}
.button3 {width: 100%;}
</style>
</head>
<body>

<h2>Buton Genişliği</h2>

<p>Varsayılan olarak, bir butonun boyutu metin içeriğine göre belirlenir. Bir butonun genişliğini değiştirmek için width özelliğini kullanırız.</p>

<button class="button button1">250px</button><br>
<button class="button button2">50%</button><br>
<button class="button button3">100%</button>


</body>
</html>

Butonları Gruplamak

Butonları yanyana grup haline getirmek için, margin değerlerini kaldırın ve her düğmeye float:left ekleyin:

<!DOCTYPE html>
<html>
<head>
<style>
.btn-group .button {
  background-color: #4CAF50; /* Yeşil */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  cursor: pointer;
  float: left;
}

.btn-group .button:hover {
  background-color: #3e8e41;
}
</style>
</head>
<body>

<h2>Buton Gruplamak</h2>

<p>Butonları yanyana grup haline getirmek için, margin değerlerini kaldırın ve her düğmeye float:left ekleyin:
</p>

<div class="btn-group">
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
</div>


</body>
</html>

Butonlara kenarlık ekleyerek daha güzel görüntüler elde edebiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.btn-group .button {
  background-color: #4CAF50; /* Yeşil */
  border: 1px solid green;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  cursor: pointer;
  float: left;
}

.btn-group .button:not(:last-child) {
  border-right: none; /* Çift border olmasını önle */
}

.btn-group .button:hover {
  background-color: #3e8e41;
}
</style>
</head>
<body>

<h2>Grup Butonlar</h2>

<div class="btn-group">
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
</div>



</body>
</html>

Butonları yan yana değilde alt alta gruplamak için float:left yerine display:block kullanabiliriz.

<!DOCTYPE html>
<html>
<head>
<style>
.btn-group .button {
  background-color: #4CAF50; /* Yeşil */
  border: 1px solid green;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
  width: 150px;
  display: block;
}

.btn-group .button:not(:last-child) {
  border-bottom: none;
}

.btn-group .button:hover {
  background-color: #3e8e41;
}
</style>
</head>
<body>

<h2>Yatay Buton Gruplama</h2>

<div class="btn-group">
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
</div>

</body>
</html>

Diğer Animasyonlu Buton Örnekleri

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  display: inline-block;
  border-radius: 4px;
  background-color: #f4511e;
  border: none;
  color: #FFFFFF;
  text-align: center;
  font-size: 28px;
  padding: 20px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.button:hover span {
  padding-right: 25px;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
}
</style>
</head>
<body>

<h2>Animasyon Buton Örnekleri</h2>

<button class="button" style="vertical-align:middle"><span>Hover </span></button>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.button {
  display: inline-block;
  padding: 15px 25px;
  font-size: 24px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  outline: none;
  color: #fff;
  background-color: #4CAF50;
  border: none;
  border-radius: 15px;
  box-shadow: 0 9px #999;
}

.button:hover {background-color: #3e8e41}

.button:active {
  background-color: #3e8e41;
  box-shadow: 0 5px #666;
  transform: translateY(4px);
}
</style>
</head>
<body>

<h2>Animasyonlu Butonlar</h2>

<button class="button">Bana Tıkla</button>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.button {
  background-color: #f4511e;
  border: none;
  color: white;
  padding: 16px 32px;
  text-align: center;
  font-size: 16px;
  margin: 4px 2px;
  opacity: 0.6;
  transition: 0.3s;
  display: inline-block;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {opacity: 1}
</style>
</head>
<body>

<h2>Animasyonu Butonlar</h2>

<button class="button">Üzerime Gel</button>

</body>
</html>

Bu içeriği beğendiyseniz paylaşarak destek olabilirsiniz!


Eğitim İçeriği

Eğitim CSS Dersleri
Kategori Web Programlama
Ders Adeti 52 Ders
Dil Türkçe
Güncelleme 10/2021
  • HTML Dersleri

    HTML Dersleri Sıfırdan İleri Seviyeye

    Kategori Web Programlama
    Ders Süresi 19 Ders
    Dil Türkçe
    Güncelleme 12/2020
    Derse Başla
  • Java Dersleri

    Java Dersleri ve Nesne Yönelimli Programlama

    Kategori Programlama Dili
    Ders Süresi 125 Ders
    Dil Türkçe
    Güncelleme 09/2020
    Derse Başla
  • CSS Dersleri

    CSS Dersleri Başlangıçtan İleri Seviyeye

    Kategori Web Programlama
    Ders Süresi 49 Ders
    Dil Türkçe
    Güncelleme 10/2021
    Derse Başla
  • Java Örnek Projeler

    Java Örnek Projeler

    Kategori Programlama Dili
    Ders Süresi 20 Ders
    Dil Türkçe
    Güncelleme 10/2022
    Derse Başla