<div>Mandatory Documents</div>
<div>
<button type="text" (click)="delete()" pButton icon="pi pi-times" label="Delete">
</button>
</div>
I have two div tags. The word Mandatory Documents is coming in two lines. I need the whole word to come in only one line and the Delete button beside to it
What CSS should I apply?
you just need to use "display: inline-block" by default div elements are block. or you could also span i guess which are inline by default. I dont know why you say don't break the two words? anyway you could add between the words so it wouldnt break
<div style="display:inline-block">Mandatory Documents</div>
<div style="display:inline-block">
<button type="text" (click)="delete()" pButton icon="pi pi-times" label="Delete">test</button>
</div>
I just don't understand why it would split up the words? can you provide a screen shot if it doesnt work just to show the full layout?
Use a non-breakable space between your words:
To keep the two div on the same line, use display: flex on their parent with flex-direction: row. Here is an example with a parent container which is too small yet the children are correctly placed on the same row.
.group {
display: flex;
flex-direction: row;
border: 1px solid black;
max-width: 100px;
}
.group > div {
border: 1px solid green;
margin: 2px;
}
<div class="group">
<div>Mandatory Documents</div>
<div><button>Button</button></div>
</div>
<br>
<div class="group">
<div>Mandatory Documents</div>
<div><button>Button</button></div>
</div>
Related
This question already has an answer here:
Understanding how width of scrollbar is computed in nested flex container
(1 answer)
Closed last year.
I have an issue with text clipping where flex items are clipped too early even though their flex-basis is set to 0 so I would expect the flex container to stretch all items to be at least as big as the biggest item in the container. Anyway here's a fiddle:
https://jsfiddle.net/nxbwufLk/
How is it choosing to wrap the text? Why is it not stretching the first item.
.button {
flex: 1 1 0;
border: 1px solid red;
}
.container {
display: inline-flex;
}
<div class="container">
<div class="button">
Some text
</div>
<div class="button">
Some text that is very long indeed
</div>
</div>
I can see that the second text is wrapped but how is that decided? There are no widths set anywhere
I can see that the second text is wrapped but how is that decided? There are no widths set anywhere
There is a width set it's just not trivial to notice, You're using inline-flex which on it's own should tell you what's going on.
The width of the container will equal it's content, in this case the width of the text of both elements.
Demo
.button {
border: 1px solid red;
}
.container {
display: inline-flex;
}
.test>.button {
flex: 1 1 0;
}
No flex properties set
<br/>
<div class="container">
<div class="button">
Some text
</div>
<div class="button">
Some text that is very long indeed
</div>
</div>
<br/>
<br/>
<br/> flex properties set
<br/>
<div class="container test">
<div class="button">
Some text
</div>
<div class="button">
Some text that is very long indeed
</div>
</div>
As you can see the width of the containers is the same.
Now regardless of what we do, the width of the container is set and won't change, so when you apply flex: 1 1 0; you're simply dividing that width (evenly flex-basis:0;) between the two elements and then you get the wrapping.
I have the following problem in html: Cannot move the add button to the side. I have tried inserting the words within the div of the button or removing the br/ in the button div. It doesnt work. I know this seems to be a stupid question to all the pros out here but im seriously stuck
<h4>More details: </h4>
<div class="col-md-1">
<div class="form-group">
<div class="text-sm-center">
<button type="button" class="btn btn-outline-success btn-rounded" id="addrow"><i class="dripicons-plus"></i></button>
</div>
</div>
</div>
If I understand correctly, you want the <h4>More details:</h4> element to be side-by-side with the + button in a row format. Since <h1>-<h6> and <div> tags are block-level the only way to have your h4 in the same row as the nested <button> is to manipulate the amount of space each element occupies, ie change their layout with CSS.
A Block-level element occupies the entire horizontal space of its parent element (container), and vertical space equal to the height of its contents, thereby creating a "block".
To make the <h4> and the + button right next to eachother, you could use CSS Flexbox and nest your HTML in a parent container <div class="row">.
.row {
display: flex;
align-items: center;
}
.row .btn {
margin-left: 10px;
}
<div class="row">
<h4 class="details-heading">More details: </h4>
<div class="col-md-1">
<div class="form-group">
<div class="text-sm-center">
<button type="button" class="btn btn-outline-success btn-rounded" id="addrow">+<i class="dripicons-plus"></i></button>
</div>
</div>
</div>
</div>
In this case you can just use CSS. You need all three of the parent DIV elements to have zero px for border-left, margin-left and padding-left.
Try adding another class to each, like:
<h4>More details: </h4>
<div class="col-md-1 left-side">
<div class="form-group left-side">
<div class="text-sm-center left-side">
<button type="button" class="btn btn-outline-success btn-rounded" id="addrow"><i class="dripicons-plus"></i></button>
</div>
</div>
</div>
CSS
.left-side {
margin-left: 0px;
border-left: 0px;
padding-left: 0px;
}
Some prefer 0 to 0px.
The reason to use another class, i.e. left-side is to avoid messing with any other elements elsewhere of the existing classes.
This method/answer is a bit of a hack; more elegant solutions will be out there.
I have used both of the display properties whenever I wanted the width of an element to be the same as its content.
But is one better than the other? I'm referring to accessibility, browser compatibility, responsiveness, etc.
Note: I am asking because I'm planing to use only one of these in my new web site. I just don't know which one is better, if any.
Ultimately, it depends on the use case:
display: inline-block will create an inline-block element
display: table will create a table element
Here they are in use:
span.mySpan {
background-color: red;
}
<div>
<span>A span element.</span>
<span class="mySpan" style="display: table;">a <code>display: table</code> element.</span>
<span>Another span element.</span>
</div>
<br/>
<br/>
<div>
<span>A span element.</span>
<span class="mySpan" style="display: inline-block;">a <code>display: inline-block</code> element.</span>
<span>Another span element.</span>
</div>
As can be seen, the results are very different. The table element positions itself on a new line, and causes the next element to be on a new line as well. The inline-block element positions itself inline with it's sibling elements.
In many cases, the above differences will be enough to choose one or the other.
If not, let's continue...
There are some cases when display: table is useful:
Horizontal and vertical centering of elements
Equal height elements
However, browsers can produce inconsistent results when not implemented correctly so you should always couple display: table with the standard table markup (using rows and cells):
.table {
display: table;
}
.table-row {
display: table-row:
}
.table-cell {
display: table-cell;
background-color: #eaeaea;
padding: 10px;
}
<div class="table">
<div class="table-row">
<div class="table-cell">
Content
</div>
<div class="table-cell" style="height: 100px;">
Content
</div>
<div class="table-cell">
Content
</div>
</div>
</div>
This becomes pretty tedious. And with modern CSS we can accomplish the same using display: flex, with a simpler HTML structure and less CSS:
.flex {
display: flex;
}
.flex-cell {
background-color: #eaeaea;
padding: 10px;
}
<div class="flex">
<div class="flex-cell">
Content
</div>
<div class="flex-cell" style="height: 100px;">
Content
</div>
<div class="flex-cell">
Content
</div>
</div>
Honestly, I can't think of many times I would need to decide between display: inline-block and display: table as they produce such different results. However, if I were on the fence I'd follow this decision tree:
Do I need to make a table? Use a true <table></table> element
Do I need equal height/width elements, and/or vertical centering? Use a display: flex element
Otherwise, use the appropriate HTML element (display: inline-block)
In HTML, I have two elements, one with text and one containing a couple of buttons.
Instead of touching in the middle, I want them spaced to align to the left and right margins. So I want my text aligned to the left margin, and my buttons aligned to the right margin, without losing their vertical alignment as is.
I also happen to be using Bootstrap 3.
When I use pull-left/pull-right, float:left/float:right, or align="left"/align="right", I get a change in the vertical alignment of these two elements.
Paired down code looks like this essentially:
<div style="width:200px;height:100px">
Delete dashboard?
<button class="btn btn-secondary cancel">
Cancel
</button>
<button class="btn btn-danger">
Delete
</button>
</div>
What is the the most straightforward way to align these items to the left and right margins? I can do it with a table, but is that not the ideal way?
[![A modal example][2]][2]
Without seeing your code, I would use a flex layout. The key in a flex row is to use justify-content: space-between to push 2 children in the row to the far edges. Then align-items on the parent will set the vertical alignment.
.flex {
display: flex;
}
.col {
flex-direction: column;
max-width: 250px;
border: 1px solid black;
}
.bot {
border-top: 1px solid #ccc;
justify-content: space-between;
align-items: center;
}
<div class="flex col">
<div>
<h1>confirm</h1>
</div>
<div class="flex bot">
<p>delete dashboard</p>
<div>
<button>cancel</button>
<button>delete</button>
</div>
</div>
</div>
What about this?
<div class="row">
<div class="col-md-6">Dashboard</div>
<div class="col-md-6 text-right">Cancel Delete</div>
</div>
This will split your area in two columns, where all content of the right column will be aligned right, without affecting the CSS of the elements itself.
I've a 3 column layout. My issue is that content in the second <div> populates from the bottom, as you can see in this fiddle. I would like to align it's content to the top.
Following is the corresponding html
<div class="user-info" style="width: 100%;">
<div id="image-container">
<img src="image.jpeg" height="200px" width="200px">
</div>
<div id="info">
<div class="info-item">
<div class="info-attribute">tullsy</div>
</div>
<div class="info-item">
<div class="info-attribute">tullsy</div>
</div>
<div class="info-item">
<div class="info-attribute">tullsy</div>
</div>
</div>
<div id="button-container">
<input type="button" id="edit_button" value="edit" class="button" onclick="function()">
<br>
</div>
</div>
and css
#image-container {
display: inline-block;
width: 100;
}
#info {
display: inline-block;
}
#button-container {
display: inline-block;
float: right;
padding: 10px;
}
I can fix this issue by applying display: flex; for the container, however it seems I can't float elements inside a flex container.
I've managed to achieve what i want using <br>, as you can see in this fiddle. But i want to achieve the same without using <br>s or fixed padding.
If i understood correctly,
First of all you need to apply a height to the container #info, (So you can avoid using <br>s to add height) Otherwise it'll shrink wrap to the height of it's child items.
Then you can apply vertical-align:top; for aligning the inline-block child items in it to the top without using <br>s
Demo