हॉरिजॉन्टल (क्षैतिज) बटन ग्रुप बनाने के लिए बटन्स को एक कंटेनर में रखें और display: flex या float: left (पुराना तरीका) का उपयोग करें। मॉडर्न दृष्टिकोण Flexbox का उपयोग करता है।
उदाहरण: फ्लेक्सबॉक्स से हॉरिजॉन्टल बटन ग्रुप
<!DOCTYPE html>
<html>
<head>
<style>
.btn-group {
display: flex;
gap: 0; /* बटन्स के बीच कोई गैप नहीं */
border: 1px solid #ccc;
border-radius: 4px;
overflow: hidden;
}
.btn-group button {
flex: 1;
color: black;
background-color: orange;
border: none;
border-right: 1px solid #ccc;
text-align: center;
font-size: 15px;
padding: 12px 20px;
cursor: pointer;
transition: background-color 0.2s;
}
.btn-group button:last-child {
border-right: none;
}
.btn-group button:hover {
background-color: darkorange;
}
.btn-group button:active {
background-color: #cc7700;
}
</style>
</head>
<body>
<h2>परिणाम</h2>
<p>नीचे क्लिक करें:</p>
<div class="btn-group">
<button class="btn">रिज़ल्ट 1</button>
<button class="btn">रिज़ल्ट 2</button>
<button class="btn">रिज़ल्ट 3</button>
<button class="btn">रिज़ल्ट 4</button>
<button class="btn">रिज़ल्ट 5</button>
</div>
</body>
</html>
पुराना तरीका (float) - टालें
/* पुराना तरीका - मॉडर्न प्रोजेक्ट्स में उपयोग न करें */
.btn { float: left; }
.btn-group::after { content: ""; display: table; clear: both; }
वैरिएशन: आउटलाइन बटन ग्रुप
.btn-group-outline button {
background: transparent;
border: 1px solid orange;
color: orange;
}
.btn-group-outline button:hover {
background: orange;
color: white;
}
वैरिएशन: मिश्रित बटन ग्रुप
.btn-group .btn-primary { background: #007bff; color: white; }
.btn-group .btn-secondary { background: #6c757d; color: white; }
.btn-group .btn-danger { background: #dc3545; color: white; }