CSS - background-size not changing

93 views Asked by At

I am trying to change the background width/height of these div elements but background-size: 1px 1px; doesn't even seem to be working. I am trying to achieve something like this, with "Cutter O.D." and "Min. Cutter Travel" having a small white background overlaying the measurement lines no matter the size of the other divs.

jsFiddle: https://jsfiddle.net/Kaevonz/fkbrpL54/37/

enter image description here

For the Cutter O.D. text label, I am using left: 15%; and right: 15%, but for larger inputs such as (50, 60, 2), there is too large of a gap as shown below due to the background size changing.

enter image description here

For the "Min. Cutter Travel" text label, when I add a background to it, the background is too big and cuts off the measurement lines. I am unable to use background-size either.

jQuery(document).ready(function($) {
  $(function() {

    $('.div3 span').hide();
    $('.div5').hide();
    $('.div5brother').hide();
    $('.div1brother').hide();

    function hideObjects($) {
      $('.div1').hide();
      $('.div2').hide();
      $('.div3').hide();
      $('.div5brother').hide();
      $('.div1brother').hide();
    }

    function hideErrors($) {
      $('#error').hide();
      $('#error2').hide();
      $('#error3').hide();
      $('#error4').hide();
      $('#error5').hide();
    }
    
    function errorStatements($){
    
    }

    $(document).on('change', '#field_2w269, #field_wg4s2, #field_d6hwp', function() {
      mainCode()
    })

    function mainCode() {

      //Declare Variables for User Inputs
      const $outer_diameter = parseFloat($("#field_wg4s2").val());
      const $wall_thickness = parseFloat($("#field_d6hwp").val());
      const $cutter_diameter = parseFloat($("#field_2w269").val());
      //Convert diameters to radii
      const $cutter_radius = ($cutter_diameter / 2);
      const $pipeOutsideRadius = ($outer_diameter / 2);
      const $pipeInsideRadius = ($pipeOutsideRadius - $wall_thickness);
      //Find Cutter Travel
      const $cutterTravel = ($pipeOutsideRadius - (Math.sqrt(Math.pow($pipeInsideRadius, 2) - Math.pow($cutter_radius, 2))));
      //Convert sizes for Visual Representation
      //const $multiplier = 7.5; //pixel sizing multiplier for user inputs
      const $multiplier = (750 / ($cutterTravel + $outer_diameter)); //pixel sizing multiplier for user inputs
      const $visualPipeOD = ($outer_diameter * $multiplier);
      const $visualWallThk = ($wall_thickness * $multiplier);
      const $visualPipeID = ($visualPipeOD - (2 * $visualWallThk));
      const $visualCutDia = ($cutter_diameter * $multiplier);
      const $visualCutTravel = ($cutterTravel * $multiplier);

      if ($cutter_diameter > $outer_diameter) {
        $('#error').text('Cutter cannot be larger than Pipe O.D.').show();
        hideObjects($);
        return false;
      }

      if ($cutter_diameter > ($outer_diameter - (2 * $wall_thickness))) {
        $('#error2').text('Cutter cannot be larger than Pipe I.D.').show();
        hideObjects($);
        return false;
      }

      if ($cutter_diameter < 0) {
        $('#error').text('Please input a positive value').show();
        hideObjects($);
        return false;
      }

      if ($wall_thickness >= 0.33 * $outer_diameter) {
        $('#error4').text('Wall Thickness is invalid').show();
        hideObjects($);
        return false;
      }
      $('#error4').hide();


      if ($wall_thickness < 0) {
        $('#error3').text('Please input a positive value').show();
        hideObjects($);
        return false;
      }

      if ($outer_diameter < 0) {
        $('#error').text('Please input a positive value').show();
        hideObjects($);
        return false;
      }
      if ($cutter_diameter > 72) {
        $('#error').text('Cutter is too big.').show();
        hideObjects($);
        return false;
      }

      if ($outer_diameter > 100) {
        $("#error").text($outer_diameter + " is too big").show();
        hideObjects($);
        return false;
      }

      $('.div1').css({
        height: ($visualCutTravel),
        width: ($visualCutDia)
      });
      $('.div1').fadeIn(300);

      $('.div1brother').css({
        width: ($visualCutDia)
      });
      $('.div1brother').fadeIn(300);

      $('.div2').css({
        height: ($visualPipeOD),
        width: ($visualPipeOD),

      });
      $('.div2').fadeIn(300);

      $('.div3').css({
        height: ($visualPipeID),
        width: ($visualPipeID),

      });
      $('.div3').fadeIn(300);

      $('.div5').css({
        height: ($visualCutTravel),
        width: ($visualCutDia)
      });

      $('.div5brother').css({
        height: ($visualCutTravel),
        right: (99.5 - $visualCutDia / 2 - 80),
      });

      $('.div5brother > span').css({
        lineHeight: `${$visualCutTravel}px`,
      });
      $('.div5brother').fadeIn(300);

      /*$('.div1brother > span').css({
        right: (99.5 - $visualCutDia / 2 - 80),
        left: (99.5 - $visualCutDia / 2 - 80),
      });*/

      hideErrors($);
    }

    $(document).on('change', '#field_2w269', function() {
      $('.div1 span').fadeIn(100);
    })

    $(document).on('change', '#field_wg4s2', function() {
      $('.div3 span').fadeIn(100);
    })

    $(document).on('change', '#field_2w269', function() {
      $('.div5').fadeIn(100);
    })

  });
});
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: start;
  height: 800px;
  border: 1px solid gray;
}

.elem {
  box-sizing: border-box;
}

/* Cutter O.D. Visual */
.div1 {
  border-top: 3px solid #0DA8AA;
  border-left: 1px solid #0DA8AA;
  border-right: 1px solid #0DA8AA;
  height: 0px;
  background: white;
}

/* Cutter O.D. Measurement Label */
.div1brother {
  position: relative;
  width: 172.5px;
  height: 25px;
  border-left: 0.01px solid black;
  border-right: 0.01px solid black;
  border-top: 0.01px solid black;
  margin-bottom: 3px;
}

/* Cutter O.D. Text */
.div1brother span {
  position: absolute;
  left: 15%;
  right: 15%;
  top: -3px;
  display: block;
  background-color: #FFF;
  padding-left: 0px;
  font-size: 9px;
  text-transform: uppercase;
  text-align: center;
}


/* Pipe O.D. Visual */
.div2 {
  border: 1px solid #0DA8AA;
  border-radius: 50%;
  width: 0px;
  height: 0px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Pipe I.D. Visual */
.div3 {
  border: 1px solid #0DA8AA;
  border-radius: 50%;
  width: 0px;
  height: 0px;
  background: white;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Pipe O.D. Text */
.div3 > span {
  transform: translate(-10%, -55%) rotate(-10deg);
  font-size: 10px;
  text-transform: uppercase;
}

/* Pipe O.D. Label */
.div4 {
  border-top: 0.5px dashed black;
  width: 100%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-10deg);
}

/* Min. Cutter Travel Label */
.div5 {
  border: 0.5px dashed black;
  width: 120px;
  height: 90px;
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  left: 50%;
}

/* Min. Cutter Travel Measurement Label */
.div5brother {
  position: absolute;
  top: 0;
  right: -80px;
  width: 80px;
  height: 50px;
  border-top: 0.5px solid black;
  border-bottom: 0.5px solid black;
  border-right: 0.5px solid black;
}

/* Min. Cutter Travel Measurement Label Text */
.div5brother > span {
  font-size: 9px;
  line-height: 50px;
  display: block;
  position: absolute;
  right: -35px;
  text-transform: uppercase;
}

.div5container {
  width: 205px;
  height: 50px;
  position: absolute;
  top: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<meta name="viewport" content="width=device-width, initial-scale=1">

<div class="container">
  <p id="error"></p>
  <p id="error2"></p>
  <p id="error3"></p>
  <p id="error4"></p>
  <p id="error5"></p>

  <div class="div1brother">
    <span>Cutter O.D.</span>
  </div>

  <div class="elem div1"></div>
  <div class="elem div2">
    <div class="elem div3"><span>Pipe O.D.</span>

      <div class="div5container">
        <div class="elem div5">
        </div>
        <div class="elem div5brother">
          <span>Min. Cutter Travel</span>
        </div>
      </div>

      <div class="elem div4">
      </div>
    </div>
  </div>
</div>

<input type="number" id="field_2w269" placeholder="Enter Cutter O.D."> <br>
<input type="number" id="field_wg4s2" placeholder="Enter Outer Diameter"> <br>
<input type="number" id="field_d6hwp" placeholder="Enter Thickness"> <br>
<input type="button" id="bttn" name="calculate" value="Calculate">
</body>

0

There are 0 answers