I am trying to have buttons centered below divs...very new at coding and working my way through courses. Ideally, the buttons would be responsive and follow the divs, wherever they may be (my code could be messy, not sure, sorry if it is :P) any tips?
.items {
height:20rem;
width:20rem;
background-color:#7FDEFF;
display:inline-block;
margin:4em;
display:center;
}
.items:hover {
background-color: #9ce5ff;
}
<section id="sale">
<div class="items"></div>
<button class="buy">Add to Cart</button>
<div class="items"></div>
<button class="buy">Add to Cart</button>
<div class="items"></div>
<button class="buy">Add to Cart</button>
</section>
</body>
</html>
You may try to wrap each one with a wrapper element (.content-wrapper).
You can check the code below.
.items {
height:20rem;
width:20rem;
background-color:#7FDEFF;
margin:4em;
}
.content-wrapper{
display:flex;
flex-direction:column;
width:20rem;
align-items:center;
}
<section id="sale">
<div class="content-wrapper">
<div class="items"></div>
<button class="buy">Add to Cart</button>
</div>
<div class="content-wrapper">
<div class="items"></div>
<button class="buy">Add to Cart</button>
</div>
<div class="content-wrapper">
<div class="items"></div>
<button class="buy">Add to Cart</button>
</div>
</section>
You can also do it without using flex, see below:
.column {
text-align:center;
margin-bottom: 1rem;
padding: .5rem;
width: 10rem;
}
.items {
width: 100%;
background-color: #7FDEFF;
padding: 40px 0px;
margin-bottom: 10px;
}
.items:hover {
background-color: #9ce5ff;
}
<section id="sale">
<div class="column">
<div class="items"></div>
<button class="buy">Add to Cart</button>
</div>
<div class="column">
<div class="items"></div>
<button class="buy">Add to Cart</button>
</div>
<div class="column">
<div class="items"></div>
<button class="buy">Add to Cart</button>
</div>
</section>
The important steps are to
have text-align: center in the parent div
define a width for the parent div
define the child-div's width as 100% (thereby spreading to parent-div's width)
provide two values for child-div's padding. The first one (40px) makes sure there is some visible vertical space in the div, the second one (0px) makes it fill out the parent div horizontally.
Related
I'm trying to have a 100% div height so that based on the variety on screen sizes it looks good, but then I need the ul to be scrollable if the content is to large and will not fit in the screen.
HTML
<div id="category_modal_body" class="modal-body">
<div id="category_filters" class="row">
<div id="category_list" class="col-md-4">
<ul>
<li> ... </li>
</ul>
</div>
</div>
</div>
<div id="category_modal_footer" class="modal-footer">
<div id="category_selected_path"></div><div id="category_footer_buttons">
<button type="button" id="add_another_category">Tjeter</button>
<button type="button" id="add_category_path">Përfundo</button>
</div>
</div>
CSS:
#category_modal_body #category_list{
padding: 0;
height: 100%
}
#category_modal_body #category_list ul{
list-style: none;
padding: 0;
margin: 0;
height:100%;
overflow:scroll;
}
This is the result I got:
So u can see how the last buttons go over the div.
How can I fix this?
First thing I would try is putting category_modal_footer div inside category_modal_body div, like this:
<div id="category_modal_body" class="modal-body">
<div id="category_filters" class="row">
<div id="category_list" class="col-md-4">
<ul>
<li>...</li>
</ul>
</div>
</div>
<div id="category_modal_footer" class="modal-footer">
<div id="category_selected_path"></div>
<div id="category_footer_buttons">
<button type="button" id="add_another_category">Tjeter</button>
<button type="button" id="add_category_path">Përfundo</button>
</div>
</div>
</div>
I'm struggling to stretch the left navigation section to reach the bottom of the page and stay responsive. I'm using Bootstrap 5.2.0. I tried many solutions like h-100, flex-grow, min-vh-100m self-align: stretch. Nothing seems to do the trick.
Codepen: (You may have to increase the height of the output window to see what I mean) :
https://codepen.io/ma66ot/pen/KKQZXew
HTML
<div class="col-md-3 col-lg-2">
<div class="logo">
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Circle_-_black_simple.svg/300px-Circle_-_black_simple.svg.png" id="circle" alt="">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="navigation ">
<div class="title-nav">
<img src="./assets/verwaltung.png" alt="" id="verwaltung-logo">
</div>
<div class="button-container">
<ul>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Übersicht</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TrainerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TeilnehmerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Gruppen</button></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9 col-lg-10">
<div class="mainfenster">
</div>
</div>
</div>
</div>
</div>
CSS
h2 {
width:100%;
}
html button {
border: 0;
width: 100%;
}
html ul {
list-style-type: none;
padding: 0;
margin: 0;
}
html .container-fluid {
padding: 1em;
}
#circle{
width: 100%;
height: 100%;
}
#verwaltung-logo {
width: 50%;
height: 50%;
}
html .links {
padding-right: 3em;
}
/* Navigation */
html .navigation {
background: #FFA500;
border-radius: 48px;
padding: 1em;
margin-top: 1em;
}
li {
margin-top: 1em;
margin-bottom: 1em;
}
.button-container{
width: 80%;
margin: auto;
}
.navigation a {
color: white;
text-decoration: none;
}
.mainfenster {
background: #FF6E13;
border-radius: 48px;
overflow-y: scroll;
height: calc(100vh - 2em);;
}
/* Hide scrollbar for Chrome */
.mainfenster::-webkit-scrollbar {
display: none;
}
.mainfenster {
/* Hide scrollbar for IE, Edge and Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.mainfenster button {
border-radius: 10px !important;
}
As explained here anytime you want to fill or stretch the remaining height flexbox column direction and flex grow.
make the left column viewport height and use min-vh-100
also make the left column d-flex flex-column
use flex-grow-1 on the div you want to fill the remaining column height
finally, use h-100 on the navigation so it fills the height of its' parent
https://codeply.com/p/CqV3FF1x5L
<div class="container-fluid ">
<div class="row">
<div class="col-md-3 col-lg-2 min-vh-100 d-flex flex-column">
<div class="logo">
<div>
<img ...>
</div>
</div>
<div class="row flex-grow-1">
<div class="col-md-12">
<div class="navigation h-100">
<div class="title-nav">
<img .. >
</div>
<div class="button-container">
<ul>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Übersicht</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TrainerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TeilnehmerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Gruppen</button></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9 col-lg-10">
<div class="mainfenster">
</div>
</div>
</div>
</div>
First you need to fix height of left logo after that you need to add height to .navigation class and minus height of logo. see the below exmple
html .navigation {
height: calc(100vh - 200px);
}
In this above case your logo div height 200px.
The title might be misleading, but I didn't know how else to name it.
In any case, I need to have an div/image inlined with a text, and a button beneath that text. The issue is, I can't really make the button take the full width without adding any padding, no matter what I try.
To make my explanation clearer, here's an image of what I'm trying to make:
And I'm trying to use Bootstrap 4 utilities only.
This is my code so far:
.col-md-3 {
background-color: #ededed;
}
.img {
width: 188px;
height: 88px;
background-color: #292a2c;
}
.btn {
background-color: #292a2c;
color: #ededed;
}
<div class="col-md-3 d-flex p-0">
<div class="img"></div>
<div>
<h6 class="m-auto">Text goes here</h6>
<button class="btn rounded-0 btn-block">Button</button>
</div>
</div>
How can I make this work? Also, the div with a class .img is a placeholder in a way, and needs to stay like that.
Thank you!
You can achieve this by using bootstrap media object with no additional css. Please see code snippet below
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="media">
<img src="https://via.placeholder.com/188x88" class="mr-3" alt="">
<div class="media-body">
<h5 class="mt-0">Media heading</h5>
<button class="btn btn-primary btn-block">Button</button>
</div>
</div>
</div>
</div>
</div>
You can try something like this, then style it accordingly:
<div class="container-fluid">
<div class="row">
<div class="col-4">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ79Qe630Fli9-SIDz188GQURmrRfhh6AksMKexPP5JvsE7AJ6t01mf5A">
</div>
<div class="col-8">
<div class="row">
<p>text</p>
</div>
<div class="row">
<button>button</button>
</div>
</div>
</div>
</div>
Here is the code for getting as shown in the image
'<div class="col-md-12"><div class="row"><div class="col-md-3"><div class="row"><div class="img"></div></div></div>
<div class="col-md-6"><div class="row">
<h6 class="m-auto">Text goes here</h6><button class="btn rounded-0 btn-block">Button</button></div></div></div>
For style use the style in your question
You could do something like this.
Note that Bootstrap by default does not have a black background class so you would have to create one.
.bg-black {
background-color: #000 !important;
border: 2px solid #000 !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid"> <!-- Make it full width -->
<div class="row d-flex"> <!-- display flex -->
<div class="col-4 align-self-stretch"> <!-- stretch the column -->
<img class="w-100" src="http://placehold.it/200x200" />
</div>
<div class="col-8 align-self-stretch"> <!-- stretch the column -->
<p>Some Text Here.<br/> Can be long or short</p>
<p>Yet another paragraph</p>
<p>And one more paragraph</p>
<button class="btn btn-primary bg-black btn-block rounded-0">Btn Txt</button>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
.col-md-3 {
background-color: #ededed;
width:100% !important;
}
.col-md-3> div{
display:inline-block;
float:left;
width: 60%;
height:100%;
}
.img {
width: 15% !important;;
height: 88px !important;
background-color: #292a2c;
display:inline-block;
}
.btn {
width: 60%;
background-color: #292a2c;
color: #ededed;
height:50%;
display:inline-block;
}
<div class="col-md-3 d-flex p-0">
<div class="img"></div>
<div>
<h6 class="m-auto">Text goes here</h6>
<button class="btn rounded-0 btn-block">Button</button>
</div>
</div>
Everything looks good just make sure that you have bootstrap.css file in right place and make sure that its working.
I made some changes to your code, its a bit hard coded but u must take care to overwrite bootstrap classes and don't change them directly.
.box {
background-color: #ededed;
}
.img {
width: 188px;
height: 88px;
background-color: #292a2c;
float: left;
margin-right: 5px;
}
.text {
float: left;
}
.btn {
background-color: #292a2c;
color: #ededed;
margin-top: 33px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-6 d-flex p-0">
<div class="box">
<div class="img"></div>
<div class="text">
<h6 class="m-auto">Text goes here</h6>
<button class="btn rounded-0 btn-block">Button</button>
</div>
</div>
</div>
I'm trying to align a row of buttons on the bottom but also have two rows of text at the top both justified left using twitter bootstrap. Here is what I'm trying to achieve:
Here is a jsfiddle of my recent attempt:
My current css files look like this:
.profile-avatar {
position:relative;
height:170px;
}
.profile-avatar img {
height: 160px;
width: 160px;
margin-left: 20px;
}
.profile-buttons {
margin-left: 15px;
margin-top: 110px;
}
I'm completely lost on how to add two rows of text to the top right of the image above the three buttons.
Any thoughts?
Thanks,
-Paul
http://jsfiddle.net/kks6h0bc/7/
.text-0,.text-1{
position: absolute;
top: 0px;
left: 200px;
display:block;
}
.text-0{
top: 0px;
font-size:30px;
}
.text-1 {
top: 50px;
}
Try with position: absolute; (watch fiddle)
Check this Fiddle. I Hope it helps.
<div class="row">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-3">
<div class="profile-avatar">
<div class="row">
<div class="col-xs-12">
<img src="http://www.kanorika.com/friendly/demo/data/avatars/min4/SyWH14RnFCt.jpg" class="profile-img img-responsive"/>
</div>
</div>
</div>
</div>
<div class="col-xs-9">
<div class="row">
<div class="col-xs-12">
Large Text<br>Small Text
</div>
</div>
<div class="row">
<div class="col-xs-12">
<button type="button" class="btn btn-default profile-buttons">Default</button>
<button type="button" class="btn btn-default profile-buttons">Default</button>
<button type="button" class="btn btn-default profile-buttons">Default</button>
</div>
</div>
</div>
</div>
</div>
</div>
I'm using bootstrap 2.3.2. I have a div with some wells inside. Here is a Preview
My structure is
<body>
<div class="page-header">
<h1 id="title">Title</h1>
</div>
<div class="row">
<div class="span3 my_span">
<div class="well my_well">
<h1>Text</h1>
<hr>
<p>More Text</p>
<hr>
<button class="btn btn-primary">Button</button>
</div>
</div>
<div class="span3 my_span">
<div class="well my_well">
<h1>Textr</h1>
<hr>
<p>More Text</p>
<hr>
<button class="btn btn-primary">Button</button>
</div>
</div>
<div class="span3 my_span">
<div class="well my_well">
<h1>Textr</h1>
<hr>
<p>More Text</p>
<hr>
<button class="btn btn-primary">Button</button>
</div>
</div>
</div>
</body>
The wells are inside a row div, how to center all the wells horizontally?
Here is the jsfiddle with the code.
I think this is what you were describing: Fullscreen View
See jsfiddle
I modified my_span:
.my_span {
width: 300px;
margin: 0 33px;
float: none;
display:inline-block;
}
and added:
.row {
text-align: center;
margin: 0;
}
EDIT: I edited the fiddle a bit to fix the margins.
Just use margin: 0 auto to set your divs to be centered.
.my_span {
width: 300px;
margin: 0 auto;
}
http://jsfiddle.net/BVmUL/367/
You can do
.parent-of-centered-div {
text-align: center;
}
.centered-div {
display:inline-block;
width: 20px; /* needs fixed width */
}