Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS A CSS "box" that needs to have a variable width

jPaulB

Coder
Hi Everybody,
I have another issue to figure out.

I have a "box" that will contain a pair of randomly generated numbers ($firstnumb) + ($secondnumb). A visitor will be asked to figure out what the answer is, and enter that in a second box.
My intention is to have the box that displays ($firstnumb) + ($secondnumb) have a variable width, plus a couple of characters to the left and right. Then centre the statement box in a column that has already been defined.
As you can see in the Example.css code, I have no idea whatsoever to manage how wide this wee box will be.
How can I manage how wide this box will be?

Example.html
PHP:
<div class="box">
    <?php
        print "<SPAN style='color: #0000FF'><B>$firstnumb + $secondnumb</B></SPAN>";
    ?>
</div>

Example.css
CSS:
.box {
    width: 40%;
    height: 30px;
    border-style: double;
    border: 2px solid green;
    border-radius: 20px;
    background-color: #B3FFB2;
    text-align: center;
    color: #FF0000;
}

Many Thanks,
Paul
 
Solution
Just give a padding to your box and it will adjust the size according to its content -
CSS:
.box {
    width: fit-content;
    padding: 0.5rem 1.5rem;
    border-style: double;
    border: 2px solid green;
    border-radius: 20px;
    background-color: #B3FFB2;
    color: #FF0000;
}
Just give a padding to your box and it will adjust the size according to its content -
CSS:
.box {
    width: fit-content;
    padding: 0.5rem 1.5rem;
    border-style: double;
    border: 2px solid green;
    border-radius: 20px;
    background-color: #B3FFB2;
    color: #FF0000;
}
 
Solution

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom