Hi @Kalyan A ,
In your code you have set the @bind directive, which is bound to the int num1, num2 etc. and because of that 0 is being displayed. So, to make the placeholder visible change the datatype from int to string.
You could try this code:
Parallelogram.razor:
@page "/parallelogram"
@inject NavigationManager Navigation
<div class="parallelogram-page">
<div class="parallelogram-wrapper">
<div class="parallelogram-container">
<div class="red-line"></div>
<input type="text" class="textbox textbox1" placeholder="Interior 1" @bind="@num1">
<input type="text" class="textbox textbox2" placeholder="Interior 2" @bind="@num2">
<input type="text" class="textbox textbox3" placeholder="Interior 3" @bind="@num3">
<input type="text" class="textbox textbox4" placeholder="Interior 4" @bind="@num4">
<input type="text" class="textbox textbox5" placeholder="Exterior 5" @bind="@num5">
</div>
<div class="btn-container">
<button class="btn btn-primary" @onclick="Submit">Submit</button>
<button class="btn btn-secondary" @onclick="Clear">Clear</button>
</div>
<p style="color: red;">@errorMessage</p>
</div>
</div>
<style>
.parallelogram-page {
width: 100%;
height: 100%;
}
.parallelogram-wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
.parallelogram-container {
position: relative;
width: 300px;
height: 200px;
background: lightblue;
transform: skew(-20deg);
overflow: hidden;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.red-line {
position: absolute;
width: 360px;
height: 3px;
background-color: red;
top: 0;
left: 40px;
}
input::placeholder {
color: brown; /* Placeholder text color */
font-style: italic; /* Optional styling */
opacity: 1; /* Ensure full visibility */
}
.textbox {
position: absolute;
width: 80px;
height: 30px;
padding: 5px;
border: 1px solid #000;
box-sizing: border-box;
text-align: center;
background-color: #fff;
font-size: 0.9rem;
}
.textbox1 {
top: 10px;
left: 10px;
}
.textbox2 {
top: 10px;
right: 10px;
}
.textbox3 {
bottom: 10px;
left: 10px;
}
.textbox4 {
bottom: 10px;
right: 10px;
}
.textbox5 {
position: absolute;
top: 50%; /* Adjusted to center vertically */
right: 10px; /* Adjusted to ensure visibility */
transform: translateY(-50%); /* Center alignment */
}
.btn-container {
margin-top: 20px;
}
button {
margin: 5px;
padding: 10px 15px;
font-size: 1rem;
cursor: pointer;
}
</style>
@code {
private string? num1;
private string? num2;
private string? num3;
private string? num4;
private string? num5;
private bool isDisabled = false;
private string errorMessage;
private void Submit()
{
errorMessage = string.Empty;
// Validation: Check if the values are valid integers and within the correct range
if (!int.TryParse(num1, out var num1Value) || num1Value <= 0 || num1Value >= 179)
{
errorMessage = "Enter a valid number between 1 and 178 for Interior 1.";
return;
}
isDisabled = true;
// Assign calculated values
num5 = num1Value.ToString();
num2 = (180 - num1Value).ToString();
num3 = num2;
num4 = num1Value.ToString();
}
private void Clear()
{
num1 = num2 = num3 = num4 = num5 = null;
isDisabled = false;
errorMessage = string.Empty;
}
}
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>Parallelogram Calculator</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div id="app">Loading...</div>
</body>
</html>
Best Regards,
Jalpa
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.