This question already has answers here:
Font scaling based on size of container
(41 answers)
Closed 9 months ago.
I want to scale the font of the text in the circle if it overflows.
If it is overflowed I want the text to resized until it fits inside the circle. I'll eventually be coding in dynamic text, so I need to find a solution that is able to check overflow every time it's re-rendered.
I've been trying to do this with Javascript and React.js, however I'm having a hard time finding a solution. My current idea is to create a function called changeFontSize and do a conditional where I check if the text width is greater than the circle width. Then keep decreasing the size until the text fits.
I'm still quite new to Javascript, so I'm unsure how to execute this.
I want to be able to do this without calling in a package to handle it for me.
.circle {
justify-content: center;
width: 100px;
height: 100px;
border-radius: 50%;
border: 2px solid red;
line-height:50px;
text-align:center;
}
<div class="circle">circleCIRCLEcircle</div>
There's a great npm package called fitty that will fit the text to the size of the container automatically:
<div id="my-element">Hello World</div>
<script src="fitty.min.js"></script>
<script>
fitty('#my-element');
</script>
.circle {
border-radius: 50%;
width:100px;
height: 100px;
padding: 10px;
background: #fff;
border: 3px solid #000;
color: #000;
text-align: center;
font: 32px Arial, sans-serif;
word-break: break-word;
white-space: break-spaces;
<div class="circle">circleCirlcecircle</div>
Related
This question already has answers here:
CSS Rounded corners
(8 answers)
Border-radius in percentage (%) and pixels (px) or em
(3 answers)
Closed 2 years ago.
I am trying to create a button shaped like the below image, and I can't find any easy way to do it, nor does any of the libraries I have searched offers something like this, which is frankly surprising, as I would think that this is a rather common shape. Can anyone teach me how do I do this?
All you need is CSS using border-radius.
input[type="button"] {
padding: 10px 20px;
border-radius: 20px;
border: 1px solid red;
color: red;
background: transparent;
}
<input type="button" value="Previous" />
The black outline you might be seeing (when you click the button) is a Chrome feature which can be disabled. This is not something that (to my knowledge) can be fixed with outline-style: none;. Read more about it here.
The CSS property you are looking for is border-radius
button {
border: 1px solid black;
border-radius: 15px;
padding: 10px 50px;
}
<button>Previous</button>
This question already has answers here:
Font scaling based on size of container
(41 answers)
JavaScript Font Metrics
(1 answer)
Closed 3 years ago.
I would like to display words or unicode glyphs so they are proportional to the viewable area (container size). That is, if the word is just a single character or we have just a unicode glyph, it is larger so it fills up space with at least let's say 10% padding on all sides. But if it's a longer word let's say "hello" or "consequentially" it shrinks the size of the word down to maintain that padding around the edges. If you resize the browser window, it will automatically responsively resize the text to fill the area, using only CSS.
This first snippet shows the simple/standard way you'd implement this. It shows how the font-size is static, the single letter doesn't fill up valuable space, and the larger word doesn't fit the container.
#a, #b, #c {
font-size: 16px;
width: 50px;
height: 50px;
text-align: center;
padding: 10px;
margin: 10px;
background: yellow;
}
<div id='a'>a</div>
<div id='b'>hello</div>
<div id='c'>consequentially</div>
What I would like to do instead is somehow -- dynamically -- make it look like this (which I statically hardcoded to demonstrate how it should visually look).
div {
width: 50px;
height: 50px;
background: yellow;
text-align: center;
margin: 10px;
}
#a {
font-size: 36px;
}
#c {
font-size: 5px;
}
<div id='a'>a</div>
<div id='b'>hello</div>
<div id='c'>consequentially</div>
The question is how to make the font dynamically adjust size based on the size it will take up based on how long the word/characters are.
I would like to know if there's a pure CSS way to do it, but if not, then how to do it in plain JavaScript.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I love how the textarea can be resized by placing the mouse on the slanted lines in the lower right hand corner and dragging the mouse. I am wanting to add css styles to text and this cannot be achieved with a textarea. Does anyone know a way to emulate the textarea resizing using another DOM element? This way, I can add my CSS styles to the text and whatever else i place inside. Thanks in advance.
I think you will find that you can apply css to a text-area just like you can with any other element. Theres only two elements which are funny with css, thats file uploader and select.
For example, see http://codepen.io/cshaw/pen/YyVxRE for an example of a text-area styled with basic css.
<style>
textarea {
border: 1px solid black;
background: green;
color: white;
padding: 10px;
width: 500px;
height: 300px;
}
</style>
<textarea name="youtextarea">
SOME CONTENT
</textarea>
Or if it must me a re sizable div see http://codepen.io/cshaw/pen/zvwdbB
<style>
div {
resize: both;
border: 1px solid #222;
width: 500px;
height: 200px;
overflow: auto;
background: #222;
color: #999;
padding: 10px;
}
</style>
<div>Resizable Div</div>
Or pop over to https://www.chris-shaw.com for more.
did you try the css resize property ??
div {
border: 2px solid;
padding: 20px;
width: 300px;
resize: both;
overflow: auto;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p><b>Note:</b> Internet Explorer does not support the resize property.</p>
<div>Let the user resize both the height and the width of this div element.</div>
</body>
</html>
This question already has answers here:
Stopping fixed position scrolling at a certain point?
(13 answers)
Closed 7 years ago.
I am building the following layout which can be viewed here:
http://www.freemicsnyc.com/Other%20Versions%20&%20Backup/FreemicsNJ/new_template.html
You will notice the one div with the days of the week (mon, tues, wed, ..) does not scroll with the rest of the page since it is styled with the following css:
.column_headings{
...not important stuff
position: absolute;
margin: 416px auto 0 auto;
left:0;
right:0;
}
This behavior is not what Im looking for.
What I would like, is for that div to scroll along with the rest of the page like normal until it gets to the very top of the viewport, at which point it would stay there like a sticky header as the remainder of the content scrolls beneath it.
Would I need parallax scrolling for this? JQuery? Is there a way to do it with just CSS?
Any help would be much appreciated!
You can use a jQuery plugin such as: http://stickyjs.com/ for now as the full css implementation of this, position: sticky has very low browser support as of the moment.
Replace your CSS code with below and see if it helps:
CSS
width: 970px;
height: 60px;
background: lime;
text-align: center;
white-space: nowrap;
position: relative;
margin: 0 auto 0 auto;
left: 0;
right: 0;
border-top: 1px solid black;
border-bottom: 1px solid black;
display: block;
I need to know how to create an overflow option that will link to another page once the text overflows by either me or by the browser size increases. I have divs with borders one side an image and the other the text. The text is inside a paragraph tag. This is not in a form at all. I prefer the code in JavaScript but will accept any other languages that will get the job done. I understand for the browser size increases that I can set the font-size but I want everybody including the blind to read the content.
Here is my logic::
Get JavaScript to detect the text size.
Determine if the text has passed the outside borders.
Create page for content. (optional)
Create/display link to rest of content.
I appreciate any help that you all can give.
To mrtsherman, if I used overflow it will look like an example I made below (tested in Firefox). I apologize for the confusion but the ultimate goal is to detect that the browser’s current text is too large for the divider tag, display a link to the detailed page and cut off all of the text that would typically overflow. I know I am making this a little complex but I would like for any reader to easily read the content. If you would go to tools > Options > content tab - fonts and colors - size: 28 in Firefox you will see big words in a hard to read overview of what the sentence/paragraph is trying to tell you. Simply put I am trying to make it easier to read the overview for reader who has truble seeing. Thank you for your input.
CSS:
.first_div
{
border: 2px dotted grey;
width: 415px;
height: 200px;
padding: 10px 10px 10px 10px;
overflow: auto;
}
.second_div
{
margin: -13px 0px 0px 205px;
padding: 10px 10px 10px 10px;
width: 200px;
height: inherit;
position: absolute;
overflow: auto;
border-left: 2px dotted grey;
}
#picture
{
background-color: green;
width: 200px;
height: inherit;
color: white;
}
h3
{
font-weight: bold;
color: black;
}
Body
<h3>Overflow Example:</h3>
<div class = "first_div">
<div class = "second_div">
<p>
This div text will be inside. This div text will be inside. This div text will be inside. This div text will be inside. This div text will be inside. This div text will be inside. This div text will be inside. This div text will be inside. This div text will be inside.
</p>
</div>
<div id = "picture">THIS IS A PICTURE</div>
</div>