Skip to content

alaeddinejebali/Five-star-rating-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Five star ratings component

alt text

Using only CSS to build the component

body {
	color: #000;
	background: #eaebef;
	font: 700 16px/1.5 Verdana;
}

#section-result{
    border-bottom: 1px solid #999;
    margin-bottom: 50px;
}

#section-rating, h1{
	text-align: center;
}

.set {
	display: inline-block;
	font-size: 3rem;
	border: none;
}

.set:after {
	content: "";
	display: table;
	clear: both;
}

.star {
	float: right;
	padding-left: 15px;
	cursor: pointer;
	color: #FFB300;
}

.star:last-child {
	padding-left: 0;
}

.star:hover:before, .star:hover~.star:before, .rd:checked~.star:before {
	content: "\f005";
}

.rd {
	display: none;
}

.rating {
	font-size: 0;
}

Using JavaScript to get the selected value

function showresult(res){
	document.getElementById('result').innerText = "You selected the value: " + res;;
}

document.getElementById('rd1').addEventListener('click', function(){
	showresult(1);
});

document.getElementById('rd2').addEventListener('click', function(){
	showresult(2);
});

document.getElementById('rd3').addEventListener('click', function(){
	showresult(3);
});

document.getElementById('rd4').addEventListener('click', function(){
	showresult(4);
});

document.getElementById('rd5').addEventListener('click', function(){
	showresult(5);
});

About

Using CSS for the layout and JavaScript to get the result

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published