This question already has answers here:
How can I position my div at the bottom of its container?
(25 answers)
Closed 3 years ago.
I'm trying to move the element to the bottom of its parent but only way to do that is to make it positioned absolute but i want it to be relative.
#output{
height: 100px;
background-color: red;
}
#inner{
height: 30px;
background-color: blue;
/*float: down*/
}
<div id="output">
<div id="inner"></div>
</div>
#output{
height: 100px;
background-color: red;
display: flex;
flex-direction: column;
}
#inner{
margin-top: auto;
height: 30px;
background-color: blue;
/*float: down*/
}
<div id="output">
<div id="inner"></div>
</div>
Related
This question already has answers here:
Center one and right/left align other flexbox element
(11 answers)
Closed 1 year ago.
I want to accomplish something like the image, but without the third element, having one element fixed on the left and another in the center.
Is there an easier way without flexbox?
<div style="display: flex; justify-content: space-between">
<button>Left Header</button>
<button>middle</button>
</div>
Im sure there is a better way, but how about just hiding last column?
.container {
display: flex;
justify-content: space-between;
}
.item {
/* no important; just to visualize*/
width: 50px;
height: 50px;
background-color: blue;
border: 1px solid;
}
.item.last { /* :last-child doesn't work */
visibility: hidden;
background-color: red;
}
<div class="container">
<div class="item">A</div>
<div class="item">B</div>
<div class="item last">C</div>
<div>
You can use postion for first div and margin for the second div, like this
.container {
postion: relative;
}
.item {
width: 50px;
height: 50px;
background-color: teal;
border: 1px solid grey;
}
.item.one {
position: absolute;
}
.item.two {
margin: auto
}
<div class="container">
<div class="item one">A</div>
<div class="item two">B</div>
<div>
you can follow this code
<div style="display: flex; justify-content: space-between">
<button>Left Header</button>
<button style="margin-right: auto; margin-left: auto">middle</button>
</div>
You can just use flexbox "self-align".
Just check it here.
This question already has answers here:
Center aligning a fixed position div
(16 answers)
Closed 2 years ago.
How can I horizontally center the fixed element which has red border? I added 3 cubes for visual hint.
By center I mean that center cube is in viewport center (and stay there when viewport is resized) and rest of the fixed element is cut off from left and right if necessary.
This needs to be old-school, i.e no flexbox.
#element {
width: 120%;
height: 200px;
position: fixed;
left: 0;
top: 0;
border: 2px dashed #ec6161;
}
#children {
display: flex;
justify-content: space-around;
align-items: center;
height: 100%;
}
.child {
width: 50px;
height: 50px;
border: 2px dashed #888;
postion: absolute;
}
<div id="element">
<div id="children">
<div class="child left"></div>
<div class="child center"></div>
<div class="child right"></div>
</div>
</div>
#element {
width: 120%;
height: 200px;
position: fixed;
left: 0;
top: 0;
border: 2px dashed #ec6161;
margin-left: -10%;
}
You could add margin-left: -10%to your #element component
This question already has answers here:
CSS when inline-block elements line-break, parent wrapper does not fit new width
(2 answers)
Make container shrink-to-fit child elements as they wrap
(4 answers)
Closed 4 years ago.
The overlay text takes up the full width of its container when there is a word break. I only want it to take up the width of the actual text. Is this possible?
See problem in codepen.
HTML
<div class="container">
<div class="overlay">
<p class="centered-overlay-text">Not Good</p>
</div>
</div>
<div class="container">
<div class="overlay">
<p class="centered-overlay-text">Good</p>
</div>
</div>
CSS
.container {
position: relative;
width: 60px;
height: 60px;
background-color: yellow;
margin-bottom: 10px;
}
.overlay {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
display: flex;
align-items: center;
justify-content: center;
}
.centered-overlay-text {
text-align: center;
background-color: blue;
}
codepen
https://codepen.io/anon/pen/MVpLKz
Try adding width: min-content; to centered-overlay-text
Like so
As mentioned in the comment though, this isn't fully cross-browser.
Like this ?
.container {
display: flex;
justify-content: center;
width: 60px;
height: 60px;
background-color: yellow;
}
.centered-overlay-text {
text-align: center;
background-color: blue;
align-self: center;
color: white;
}
<div class="container">
<p class="centered-overlay-text">Hell<br>Yeah !</p>
</div>
This question already has answers here:
Align first div to left with subsequent divs aligned right
(3 answers)
Closed 6 years ago.
How could it be possible use Flex css to leave the elements as follows?
You can use margin-left: auto on second element and that will push second and third element to right.
.content {
display: flex;
}
.content > div {
width: 50px;
height: 50px;
border: 1px solid black;
}
.content > div:nth-child(2) {
margin-left: auto;
}
<div class="content">
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
</div>
You could also achieve this with margin-right: auto on the first element. In this case the main horizontal align is flex-end and only the first div is flex-start. Because of that you can push the first div with margin-right: auto to the left and the others will keep the flex-end alignment. So every additional div will also be positioned to the right side.
#wrapper{
background: #eee;
display: flex;
justify-content: flex-end;
}
.box{
width: 100px;
height: 100px;
background: #000;
}
.box:nth-child(1){
background: rgba(0,255,0,0.3);
margin-right: auto;
}
.box:nth-child(2){
background: rgba(0,0,255,0.3);
}
.box:nth-child(3){
background: rgba(255,0,255,0.3);
}
<div id="wrapper">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
This question already has answers here:
vertical align bottom + inline block
(2 answers)
Closed 6 years ago.
I have the following html structure
<div class="examples">
<div class="option"></div>
<div class="option"></div>
<div class="option"></div>
</div>
CSS:
.examples {
whitespace: nowrap;
min-height: 400px;
}
.option {
width: 18%;
max-width: 18%;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 1%;
vertical-align: bottom;
cursor: pointer;
border: 4px solid red;
display: inline-block;
}
How can I vertically align inline blocks (option) at the bottom of the container (examples) using CSS? These are a row of images inside the examples container. I tried vertical align: bottom, but that doesn't work and I want to stay away from flex because of lack of cross browser support. I also want to stay away from absolute position because the elements (option) are a row of images.
You'll probably want to use flexbox and use display: flex; justify-content: flex-end; on the container div. That should put them at the bottom.
.examples {
whitespace: nowrap;
min-height: 400px;
position: relative;
background: blue;
}
.aligner {
position: absolute;
bottom: 0;
width: 100%;
}
.option {
width: 18%;
max-width: 18%;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 1%;
cursor: pointer;
border: 4px solid red;
display: inline-block;
}
<div class="examples">
<div class="aligner">
<div class="option"></div>
<div class="option"></div>
<div class="option"></div>
</div>
</div>