I've got the following:
div.div
p.paragraph
| about 3 lines of text... (dynamic)
button.button-i-want-to-center
| click_me
I want it to look like this:
___________________________
| Text.....................|
| Text.....................|
| Text.....................|
| ______ |
| |BUTTON| | <--- Center of div:
| | I want the button to ignore
| | the text.
| |
| |
___________________________
Keeping in mind that the size of the div is dynamic.
How can I achieve this? I tried flex, but didn't do the trick. Fixed margins are no good either.
you can use css3 flexbox concept
html,body{
height:100%;
width:100%;
}
.wrapper {
display:flex;
justify-content:center;
width:100%;
height:100%;
background-image: url("https://i.stack.imgur.com/wwy2w.jpg");
background-repeat:no-repeat;
background-size:cover;
}
.button {
position:absolute;
align-self:center;
}
p{
color:white;
}
<div class="wrapper">
<p> other texts</p>
<button class="button">Button</button>
</div>
You should use position:absolute;
on the button position:relative;
on the div. See this example:
div{
position:relative;
height:180px;
background-color:green;
}
button{
position:absolute;
top:calc(50% - 15px);
left:calc(50% - 50px);
height:30px;
width:100px;
}
<div>
<p>
lines of textlines of textlines of textlines of textlines of textlines of textlines of textlines of textlines of textlines of textlines of textlines of textlines of textlines of text
</p>
<button>Click me</button>
</div>
You can use display: block
& margin: 0 auto
, like:
button {
display: block;
margin: 20px auto;
font-size: 20px;
}
Have a look at the snippet below:
button {
display: block;
margin: 20px auto;
font-size: 20px;
}
<div class="content-holder">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium, consectetur, saepe. Praesentium doloribus dolorum qui nisi rem veniam iure. Ducimus, harum, molestiae. Harum consequatur cum accusantium fugiat, reiciendis repudiandae iste!
<button>Button</button>
</div>
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With