i have this button where if i give width="140px" and content is big it goes outside div.
i want content to auto fit to given div.
i tried lot but nothing working,
<div id="pushdaddy-button" class="pushdaddy-button" style="width:140px;height:30px;border-radius: 8px;bottom: 20px;right:2%; ; ;background-size: auto;background-position: center;background-repeat: no-repeat; ; ; ;;"><div class="pushdaddy-button-label" id="pushdaddy-button-label" style="color:#F2CA80; ;margin:0 34px;padding:4px 4px; ;; ; right: unset; background-color: transparent;color: #F2CA80;box-shadow:none; font-size: 16px; ">Chat with us 976654654444</div></div>
content is Chat with us 976654654444
and chat with us fits in 140 px but when we add some more text it goes outside of div which looks ugly
any help in solving this issue so that text always fits in div will be great.
i tried
display:inline-block
width:auto
and several other combination but nothing worked
here is screenshot how it looks
i want it to be fit in div. 140px is not the constraint. i want text to fit in whatever width it takes. but should be in one line. not in multiline
You're almost there with display: inline-block, but as you can see, allowing the button to determine its own width makes supporting arbitrary labels difficult.
.btn {
display: inline-block;
width: 140px;
border-radius: 10px;
}
.btn-primary {
background-color: purple;
color: white;
}
<div class="btn btn-primary">Chat with us 976654654444</div>
Instead, you can remove the width and let the label decide how wide the button should be. Here I've used padding to place some space around the width of the text.
.btn {
display: inline-block;
padding: 10px;
border-radius: 10px;
}
.btn-primary {
background-color: purple;
color: white;
}
<div class="btn btn-primary">Chat with us 976654654444</div>
You can still support widths with this approach, but you should switch to max-width and make sure it's only used when you need to prevent the button from taking up all the room in your template.
Here I've added a max-width to keep the button at 200px or below, but I have also had to add:
overflow: hidden to prevent the text from flowing out of the button
white-space: nowrap to prevent the text from forming multiple lines
text-overflow: ellipsis to prevent the text from being cut off by the end of the button
.btn {
display: inline-block;
padding: 10px;
max-width: 200px;
border-radius: 10px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.btn-primary {
background-color: purple;
color: white;
}
<div class="btn btn-primary">The label for this button is too long and would intrude on other parts of the template</div>
Related
So i'm trying to make a box in which if the content is to big, it only scrolls on the X. I have tried every stack overflow way i have seen, and can't find a answer after days that works.
Here is my HTML:
<div class="outputElement">
<div class="xOutput" style="border-bottom: 1px solid black;"><h1 class="algbra-h1">X: 10432323232323232323232323232323232323232322</h1></div>
<div class="yOutput" style=""><h1 class="algbra-h1">X: 10432323232323232323232323232323232323232322</h1></div>
</div>
CSS:
.outputElement {
background-color: #f5f1ef;
width: 226px;
margin-left: 3%;
border: 1px solid black;
height: 80px;
}
.xOutput,.yOutput{
vertical-align:top;
text-align: center;
}
.xOutput {
overflow-x: scroll;
height: 40px;
}
.yOutput {
width: 226px;
overflow-x: scroll;
font-size: 30px;
}
.algbra-h1 {
font-size: 30px;
}
Now here is what happens when a long number is in the box:
https://postimg.cc/image/5phnvjiot/
Just encase you want to, the project i am using this on is -->
Line 72 HTML & Line 219-243 CSS
https://codepen.io/Mike-was-here123/pen/QrdJdO
It jumps down a line on the Y-axis, then scrolls on the X. Note that its the same thing in both of those boxes. Its two div's onto of each other, inside of a main div.
Here is what i need:
It only to scroll on the X-axis, it cannot jump down a line then scroll.
Here is what i tried:
Making the Y-hidden --> Just hides it, doesn't prevent it, Anything else amounts to the same outcome.
Setting fixed pixel heights to the containing divs is causing the problem. Remove the fixed heights to allow all the text to be visible. The splitting between X and the number is caused by whitespace wrapping. When there isn't enough horizontal space for text, it is broken to the next line at the next whitespace character. The wrapping can be overridden with white-space:nowrap;.
.outputElement {
background-color: #f5f1ef;
width: 226px;
margin-left: 3%;
border: 1px solid black;
}
.yOutput {
width: 226px;
overflow-x: scroll;
font-size: 30px;
}
.xOutput {
overflow-x: scroll;
}
.algbra-h1 {
font-size: 30px;
white-space:nowrap;
}
I'm not sure what you want in the big picture but I did resolve the problem described in the question.
I tried to create a code snippet but things broke since the project seems to use a lot of external libraries. I have instead opted to fork the original codepen.
Note: forked, working example pen removed upon request.
When using a <button> inside a <div>, I've noticed if the button is left with no text, an unexpected white space appears below it.
The fiddle here shows it: https://jsfiddle.net/042pt648/ If you comment out the empty button and try the others, they work fine without a white space below. Upon investigation, it seems the height of the parent div with class .post-comments is different when the button is empty. When the white space is visible, the parent div has a height of 25px while the button has a height of 20px, causing the space. In the other cases, the height is the same as the button(20px) just as expected.
Could someone explain what is causing this?
Here is the snippet in question:
.post-comments {
border: 1px solid blue;
}
.comment-div-toggle {
width: 100%;
height: 20px;
border: none;
margin: 0;
padding: 0;
background-color: gray;
color: white;
}
<div class="post-comments">
<button class="comment-div-toggle"></button>
</div>
By default <button> is an inline level element. Try this to get rid of the whitespace:
button {
display: block;
}
Or:
button {
vertical-align: top;
}
I have a bolded text block where I'd like to control the size of. Unfortunately, it appears to be resisting every effort to constrain its (actual) size. My goal is to have it to do ellipsis on text overflow but that's not happening because it just extends off-screen. It does get properly cut off by the boundary of the parent but that doesn't look elegant.
I have searched online for a solution but I don't see anything useful due to the immense amount of noise associated with the keywords I use (i.e. span, override width, b element, etc). I have made a sample code below to illustrate my problem (where span and b elements resist width overrides)
<body>
<b class="token_actor_cell" title="(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" style="
/* width: 100px; */
padding: 1px;
margin: 1px;
color: brown;
max-width: 100px;
word-wrap: break-word;
">(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</b>
<span class="token_actor_cell" title="(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" style="
/* width: 100px; */
padding: 1px;
margin: 1px;
color: blue;
max-width: 100px;
word-wrap: break-word;
">(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</span>
<p class="token_actor_cell" title="(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" style="
/* width: 100px; */
padding: 1px;
margin: 1px;
color: green;
max-width: 100px;
word-wrap: break-word;
">(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</p>
</body>
I suppose I can change my element type to p but I kinda prefer to stick with my original element type if possible.
Input on this would be appreciated. I am pretty sure it is a well-understood issue.
You should play around with the "display" property.
If you want it to behave like a <p> Tag you should use display: block;. If you want to keep the inline behaviour of your elements you should use display: inline-block;. Then they will listen to your width.
By default inline elements (like span and b) don't have width. To make them adjust to a width you need them to float either left or right. This will create a block box around them.
You example with float left http://jsfiddle.net/0ja257L9/
.token_actor_cell{
float: left;
}
Or you can use display: inline-block for the inline elements :)
What about:
<b class="token_actor_cell" title="(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" style="
width: 100px;
padding: 1px;
margin: 1px;
color: brown;
display:block;
text-overflow: ellipsis;
overflow:hidden">
(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
</b>
Seems to work for me.
I am trying to display 2 values on the same row and give the one on the right priority to grow (it is a mobile app and needs to detect the width of the screen and "squash" the left cell to be smaller.
Here is my attempt: http://jsfiddle.net/rodneyjoyce/TxBhD/
HTML
<div id="screen">
<div id="leftDesc">This is a Long Description</div>
<div id="rightDesc">1000</div>
</div>
CSS
#screen
{
width: 200px;
}
#leftDesc
{
display: inline-block;
overflow: hidden;
float: left;
height: 20px;
max-width:160px;
color: blue;
}
#rightDesc
{
float: right;
display: inline-block;
text-align: right;
color: red;
}
What should happen: Increase "1000" to "1000 000". Blue text should chop off the end of the word "Description" and the red and blue text should stay on the same line.
Disclaimer: I am not very good at CSS - in XAML I use the * value on width so that a cell auto-grows and shrinks the others.
I do not want to use Javascript or JQuery.
I'm not sure if you can dynamically change the size of your floated elements with CSS based on the content, but part of the problem can be solved with:
Adding to #leftDesc:
text-overflow:ellipsis;
white-space:nowrap;
The white-space property keeps the text on one line; text-overflow should be pretty self-explanatory.
JSFiddle
Use the flexible box layout:
#screen
{
width: 200px;
display: -webkit-flex;
display: -moz-flex;
display: flex;
}
#leftDesc
{
overflow: hidden;
height: 20px;
color: blue;
white-space:nowrap;
}
#rightDesc
{
text-align: right;
color: red;
}
I've removed your floats and your inline-blocks, and added display: flex to get the boxes to behave.
I've also added white-space:nowrap; to make sure the description gets cut off, like you've asked.
I've also removed max-width:160px;, because it didn't appear to have any effect in this scenario.
Keep in mind that this will not work in IE.
I want to create two DIVs, a container DIV (which contains arbitrary content) and an arrow DIV which allows the user to scroll the content horizontally.
Ignoring the Javascript aspect, the basic layout and CSS could be something like:
<!DOCTYPE html>
<html>
<head>
<style>
.outer-wrapper {
min-width:275px;
overflow: hidden;
border: 1px solid #000000;
height: 40px;
}
.container {
width: 90%;
min-width:100px;
margin-left: 0.5em;
margin-right: 0.5em;
height: 40px;
overflow: hidden;
white-space: nowrap;
float: left;
}
.inner-content {
margin-top: 10px;
white-space: no-wrap;
position: relative;
display: inline-block;
white-space: nowrap;
}
.inner-element {
display: inline-block;
}
.arrow {
margin-top: 12px;
min-width: 30px;
font-size: 10px;
text-align: right;
margin-right: 2px;
}
</style>
</head>
<body>
<div class = "outer-wrapper">
<div id = "container" class = "container">
<div class = "inner-content" id = "inner-content">
Options Options Options Options Options Options Options Options Options
</div>
</div>
<div id = "arrow" class = "arrow">
▶
</div>
</div>
</body>
</html>
Here's a jsfiddle link showing the rendering: http://jsfiddle.net/RSTE9/1/
The problem I have is that, ideally, I'd like the DIV containing the arrow to be as small as possible, so that most the width of the screen is comprised of the container DIV.
To achieve this, I thought I'd set the container DIV to a width of like 98%, and the arrow DIV to a width of like 2%. Unfortunately, this causes the arrow DIV to wrap to the next line on smaller screen sizes.
The essential problem is that I want the arrow DIV to always take up a very small portion of the screen, but I can't find a way to do this using percentages. If the screen width is large, the arrow DIV always takes up too much space. But if the screen width is very small (say on a mobile device), the arrow DIV might be pushed to the next line. I played around with different percentage values, but there's seemingly no way to get an ideal value. I settled at a width of 90% - this looks good on small screens, but on a large screen it means the arrow DIV is taking up 10% of the screen!
I was thinking of using CSS3 media queries to adjust the percentages dynamically, but I am wondering if there is some easier solution that I'm just not thinking of.
I would suggest that using css calc would be the answer:
CSS Calc on MDN
give the arrow div a fixed size and the container a calc(100%-30px):
.container {
width: calc(100%-30px);
min-width:100px;
margin-left: 0.5em;
margin-right: 0.5em;
height: 40px;
overflow: hidden;
white-space: nowrap;
float: left;
}
Here is an example on jsFiddle:
http://jsfiddle.net/RSTE9/5/
Notice I removed a few of the options options so you can see the effect better.
You do have a minimum width on the main container, which prevents more collapsing.
Why not set width of container as "*"?
.container {
width: *;
min-width:100px;
margin-left: 0.5em;
margin-right: 0.5em;
height: 40px;
overflow: hidden;
white-space: nowrap;
float: left;
}
jsFiddle: http://jsfiddle.net/RSTE9/6/
seems like you messed a bit with float , display and white space.
display and white space is a good clue, width a little less.
the idea is:
set the block container width no width nor overflow, but margin and white-space,
for inner content, reset white-space to normal , use display instead float.
Set min-width to text-content (100% - margin given to container)
Finally , vertical-align on both inline boxe containers text + arrow.
.outer-wrapper {
min-width:275px;
white-space: nowrap;
margin:0 1%;
}
.container {
min-width:98%;
margin-left: 0.5em;
margin-right: 0.5em;
min-height: 40px;
vertical-align:middle;
border: 1px solid #000000;
display:inline-block;
white-space:normal;
}
.arrow {
font-size: 10px;
width:1em;
text-align: right;
display:inline-block;
vertical-align: middle;
}
http://jsfiddle.net/GCyrillus/2e3du/1/