HTML label tag, CSS should be placed over the flag

It's a good day, I'm not good at CSS, and it's hard for me to put a flag label on top of the flag itself. could you help me? I want the label to also be formatted in the center, because I want to also dynamically change the text using jquery. If I checked it, the text “Fix” will become “Fixed”, and this text should remain centered at the top of the check box. Here is my JSFIDDLE ->> https://jsfiddle.net/koykoys/d2cb96xo/ .

** Note: Please do not modify the "html" part, only the "css" part.

Thank.

input[type="checkbox"]:not(:checked),
input[type="checkbox"]:checked {
  position: absolute;
  left: -9999px;
}
input[type="checkbox"]:not(:checked) + label,
input[type="checkbox"]:checked + label{
  position: relative;
  padding-left: 50px;
  cursor: pointer;
}


/* checkbox aspect */
input[type="checkbox"]:not(:checked) + label:before,
input[type="checkbox"]:checked + label:before {
  content: '';
  position: absolute;
  left:0; top: 2px;
  width: 40px; height: 40px;
  background: #f8f8f8;
  border-radius: 3px;
  border: 2px solid #aaa;
  -webkit-box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
  box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
}
/* checked mark aspect */
input[type="checkbox"]:not(:checked) + label:after,
input[type="checkbox"]:checked + label:after {
  content: '✔';
  position: absolute;
  top: 0; left: 5px;
  font-size: 34px;
  color: green;
  transition: all .2s;
  -webkit-transition: all .2s;
  -moz-transition: all .2s;
  -ms-transition: all .2s;
  -o-transition: all .2s;
}
/* checked mark aspect changes */
input[type="checkbox"]:not(:checked) + label:after {
  opacity: 0;
  transform: scale(0);
}
input[type="checkbox"]:checked + label:after {
  opacity: 1;
  transform: scale(1);
}
<div class="col-md-12">
   <input id="checkid"  type="checkbox">
   <label for="checkid">Fixed</label>
</div>
Run codeHide result
+4
6

"" ( input type="checkbox", , ).

input[type="checkbox"]:not(:checked),
input[type="checkbox"]:checked {
  position: absolute;
  left: -9999px;
}
input[type="checkbox"]:not(:checked) + label,
input[type="checkbox"]:checked + label{
  position: relative;
  cursor: pointer;
  display: inline-block;
  padding-bottom: 50px;
}


/* checkbox aspect */
input[type="checkbox"]:not(:checked) + label:before,
input[type="checkbox"]:checked + label:before {
  content: '';
  position: absolute;
  left:50%; top: 20px;
  width: 40px; height: 40px;
  background: #f8f8f8;
  border-radius: 3px;
  border: 2px solid #aaa;
  -webkit-box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
  box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}
/* checked mark aspect */
input[type="checkbox"]:not(:checked) + label:after,
input[type="checkbox"]:checked + label:after {
  content: '✔';
  position: absolute;
  top: 20px; left: 0;
  right: 0;
  font-size: 34px;
  color: green;
  transition: all .2s;
  -webkit-transition: all .2s;
  -moz-transition: all .2s;
  -ms-transition: all .2s;
  -o-transition: all .2s;
  text-align: center;
}
/* checked mark aspect changes */
input[type="checkbox"]:not(:checked) + label:after {
  opacity: 0;
  transform: scale(0);
}
input[type="checkbox"]:checked + label:after {
  opacity: 1;
  transform: scale(1);
}
<div class="col-md-12">
   <input id="checkid"  type="checkbox">
   <label for="checkid">Fixed</label>
</div>

<div class="col-md-12">
   <input id="checkid2"  type="checkbox">
   <label for="checkid2">Label can now vary in length</label>
</div>
Hide result
+3

input[type="checkbox"]:not(:checked), input[type="checkbox"]:checked {
	position: absolute;
	left: -9999px;
}
input[type="checkbox"]:not(:checked) + label, input[type="checkbox"]:checked + label {
	position: relative;
	cursor: pointer;
}
/* checkbox aspect */
input[type="checkbox"]:not(:checked) + label:before, input[type="checkbox"]:checked + label:before {
	content: '';
	position: absolute;
	left: 0;
	top: 22px;
	width: 40px;
	height: 40px;
	background: #f8f8f8;
	border-radius: 3px;
	border: 2px solid #aaa;
	-webkit-box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
	box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
}
/* checked mark aspect */
input[type="checkbox"]:not(:checked) + label:after, input[type="checkbox"]:checked + label:after {
	content: '✔';
	position: absolute;
	top: 16px;
	left: 10px;
	font-size: 34px;
	color: green;
	transition: all .2s;
	-webkit-transition: all .2s;
	-moz-transition: all .2s;
	-ms-transition: all .2s;
	-o-transition: all .2s;
}
/* checked mark aspect changes */
input[type="checkbox"]:not(:checked) + label:after {
	opacity: 0;
	transform: scale(0);
}
input[type="checkbox"]:checked + label:after {
	opacity: 1;
	transform: scale(1);
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

</head>

<body>
<div class="col-md-12">
  <input id="checkid"  type="checkbox">
  <label for="checkid">Fixed</label>
</div>
</body>
</html>
Hide result
+2

, , <label> (, ), , : - , top, 100% ( <label>), <label> margin ( ), <label> display .

input[type="checkbox"]:not(:checked),
input[type="checkbox"]:checked {
  position: absolute;
  left: -9999px;
}
input[type="checkbox"]:not(:checked) + label,
input[type="checkbox"]:checked + label{
  position: relative;
  margin-bottom: 50px;
  padding-bottom: 4px;
  cursor: pointer;
  display: block;
}


/* checkbox aspect */
input[type="checkbox"]:not(:checked) + label:before,
input[type="checkbox"]:checked + label:before {
  content: '';
  position: absolute;
  left:0; top: 100%;
  width: 40px; height: 40px;
  background: #f8f8f8;
  border-radius: 3px;
  border: 2px solid #aaa;
  -webkit-box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
  box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
}
/* checked mark aspect */
input[type="checkbox"]:not(:checked) + label:after,
input[type="checkbox"]:checked + label:after {
  content: '✔';
  position: absolute;
  top: 100%; left: 5px;
  font-size: 34px;
  color: green;
  transition: all .2s;
  -webkit-transition: all .2s;
  -moz-transition: all .2s;
  -ms-transition: all .2s;
  -o-transition: all .2s;
}
/* checked mark aspect changes */
input[type="checkbox"]:not(:checked) + label:after {
  opacity: 0;
  transform: scale(0);
}
input[type="checkbox"]:checked + label:after {
  opacity: 1;
  transform: scale(1);
}
<div class="col-md-12">
   <input id="checkid"  type="checkbox">
   <label for="checkid">Fixed</label>
</div>
Hide result
+1

I added margin-top: 50pxto close the window and give space for the label. Here is the full CSS, I am not editing your original code, I have added a few lines. I wrote comments on the lines I added.

input[type="checkbox"]:not(:checked),
input[type="checkbox"]:checked {
  position: absolute;
  left: -9999px;
  /* added */
  opacity: 0;
}
input[type="checkbox"]:not(:checked) + label,
input[type="checkbox"]:checked + label{
  position: relative;
  padding-left: 50px;
  cursor: pointer;
  /* added */
  text-align: center;
  padding-left: 4px;
}


/* checkbox aspect */
input[type="checkbox"]:not(:checked) + label:before,
input[type="checkbox"]:checked + label:before {
  content: '';
  position: absolute;
  left:0; top: 2px;
  width: 40px; height: 40px;
  background: #f8f8f8;
  border-radius: 3px;
  border: 2px solid #aaa;
  -webkit-box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
  box-shadow: groove 0 0 13px rgba(0, 0, 0, 0.5);
  /* added */
  margin-top: 20px;
}
/* checked mark aspect */
input[type="checkbox"]:not(:checked) + label:after,
input[type="checkbox"]:checked + label:after {
  content: '✔';
  position: absolute;
  top: 0; left: 5px;
  font-size: 34px;
  color: green;
  transition: all .2s;
  -webkit-transition: all .2s;
  -moz-transition: all .2s;
  -ms-transition: all .2s;
  -o-transition: all .2s;
  /* added */
  margin-top: 20px;
}
/* checked mark aspect changes */
input[type="checkbox"]:not(:checked) + label:after {
  opacity: 0;
  transform: scale(0);
}
input[type="checkbox"]:checked + label:after {
  opacity: 1;
  transform: scale(1);
}
+1
source

Why don't you try something just ....... Put your top labyrinth down and just add "br"

 <!DOCTYPE html>
    <html>
    <body>

     <form action="demo_form.asp" method="get"><lable>asdf</lable><br>
     <input type="checkbox" name="vehicle" value="Bike"><br>

     <input type="submit" value="Submit">
    </form>

    </body>
    </html>
0
source

Just add:

input[type="checkbox"]:not(:checked) + label,
input[type="checkbox"]:checked + label {
    padding-top: 11px;
}
-1
source

Source: https://habr.com/ru/post/1661820/


All Articles