Align a Span and Heading within card-header - html

I would like to style Bootsrap 4's card-header so that there is a heading and span vertically aligned on same line. The header should consist of a <hX> heading for expanding card's card-body and a <span> which is non-clicable and pulled to the right:
How can I ensure the "Non-clicable body summary" span appear on same line as the "Clicable header"?
.card-header h3 {
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.bundle.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css" rel="stylesheet" />
<div class="card">
<div class="card-header" id="headingOne">
<div class="float-right card-summary">Non-clicable body summary</div>
<a class="mb-0" data-toggle="collapse" data-target="#collapse" aria-expanded="true" aria-controls="collapse">
<h3>
Clicable header
</h3>
</a>
</div>
<div id="collapse" class="collapse" aria-labelledby="headingOne">
<div class="card-body">
<p>Some content</p>
</div>
</div>
</div>

Is this what you're looking for?
.card-header h3 {
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.bundle.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css" rel="stylesheet" />
<div class="card">
<div class="align-items-center card-header d-flex justify-content-between" id="headingOne">
<a class="mb-0" data-toggle="collapse" data-target="#collapse" aria-expanded="true" aria-controls="collapse">
<h3>
Clicable header
</h3>
</a>
<div class="card-summary">Non-clicable body summary</div>
</div>
<div id="collapse" class="collapse" aria-labelledby="headingOne">
<div class="card-body">
<p>Some content</p>
</div>
</div>
</div>
Removed floats and used default BS flexbox utility classes for
section.

first remove float-right class.
you can use the d-flex justify-content-between class in card-header div.
<div class="card-header d-flex justify-content-between" id="headingOne">
and also add align-self-center class. <div class="card-summary align-self-center">Non-clicable body summary</div>
Working Demo
Ref : Bootstrap utilities

Related

Bootstrap 5 Vertical Alignment issue with responsive

I have a issue with vertical alignment in a container. I have the following code that does what I want, that is, the first row in the center and the second at the bottom of the container.
Full screen
<header class="masthead" id="home">
<div class="container h-100">
<div class="row h-100 align-items-center justify-content-evenly text-center">
<div class="col-4">
<img src="assets/img/profil.png" class="rounded-circle img-fluid" alt="...">
<hr class="divider" />
<h1 class="text-white font-weight-bold">d3vyce</h1>
</div>
<div class="col-md-8 col-lg-4">
<h2 class="text-white font-weight-bold">Hi 👋, Welcome to my Site!</h2>
<p class="text-white">Developer, CTF Player, Homelab, 3D Printing</p>
<hr class="divider" />
<div class="d-grid col-6 mx-auto">
<a class="btn btn-outline-light btn-lg" href="https://blog.d3vyce.fr" target="_blank"><i class="fa fa-bookmark fa-lg"></i> Blog</a>
<a class="btn mt-2 btn-outline-light btn-lg" href="https://github.com/d3vyce" target="_blank"><i class="fa fa-github fa-lg"></i> Github</a>
</div>
</div>
</div>
<div class="row head-row justify-content-center">
<div class="col-12 mouse_scroll p-0">
<a href="#about">
<div class="mouse">
<div class="wheel"></div>
</div>
<div>
<span class="m_scroll_arrows unu"></span>
<span class="m_scroll_arrows doi"></span>
<span class="m_scroll_arrows trei"></span>
</div>
</a>
</div>
</div>
</div>
</header>
For the alignment at the bottom of the second row I use the following CSS:
.mouse_scroll {
display: block;
width: 24px;
height: 100px;
position: absolute;
bottom: 0; }
The problem happens with the responsive. The columns of the first row are well one on top of the other, but the space between the two is much too important and I can't modify it :(
I tried to search on stackoverflow for answers, but after many tests I'm in a dead end...
Reponsive
Thank you in advance for your answers!

How to make font-awesome inline with div

How to make font-awesome inline with div?
HTML
<div class="row clearfix">
<div class="col-lg-12">
<div class="alert alert-info" role="alert">
<span aria-hidden="true"><i class="fa fa-warning"></i></span>
<marquee>Lorem..</marquee>
</div>
</div>
</div>
I would use a flexbox to align both items. Be aware that <marquee> is obsolete.
div[role="alert"] {
display: flex;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="row clearfix">
<div class="col-lg-12">
<div class="alert alert-info" role="alert">
<span aria-hidden="true"><i class="fa fa-warning"></i></span>
<marquee>Lorem..</marquee>
</div>
</div>
</div>
You can do with CSS the following to align in right next to your text.
display: inline;

Bootstrapping buttons

I am trying to make three parallel square shape buttons with title in center. something like this
My title
Square button-1 square button-2 square button-3
My code is as follows::
<div class="col-md-12 pt-md-5 text-center">
<p>My title</p>
</div>
<div class="container">
<div class="row">
<div class="col-xs-4">
<div>
<button class="btn btn-sq-lg btn-info">button-1</button>
</div>
<div >
<button class="btn btn-sq-lg btn-info">button-2</button>
</div>
<div>
<button class="btn btn-sq-lg btn-info">button3</button>
</div>
</div>
</div>
</div>
.btn-sq-lg {
width: 150px !important;
height: 150px !important;
}
output I am getting is three vertical without any spaces. But I want three parallel square buttons with equal spaces
how can I do that?
Also how can I make button with white color and black text and title with white color and increase font size?
Just made button as info but want a white background with black text
col-xs-** has been replaced with col-** in v4. You need to separate each button with col-4
.btn-sq-lg {
width: 150px !important;
height: 150px !important;
background: #ffff!important;
color: black!important
}
.square {
text-align: center
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<p class="p-5 w-100 text-center">My title</p>
<div class="container">
<div class="row">
<div class="col-4">
<div class="square">
<button class="btn btn-sq-lg btn-info ">button-1</button>
</div>
</div>
<div class="col-4">
<div class="square">
<button class="btn btn-sq-lg btn-info">button-2</button>
</div>
</div>
<div class="col-4">
<div class="square">
<button class="btn btn-sq-lg btn-info">button3</button>
</div>
</div>
</div>
</div>
Use justify-content-between to row and remove the div with col-xs-4 (xs does not exist in bootstrap 4)
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="col-md-12 pt-md-5 text-center">
<p>My title</p>
</div>
<div class="container">
<div class="row justify-content-between">
<div>
<button class="btn btn-sq-lg btn-info">button-1</button>
</div>
<div>
<button class="btn btn-sq-lg btn-info">button-2</button>
</div>
<div>
<button class="btn btn-sq-lg btn-info">button3</button>
</div>
</div>
</div>

Bootstrap 4: Vertically center badge with utilities only

I'm making a Bootstrap 4 card that in its header needs to have an image, title, subtitle, badge and a close button. And the badge needs to be vertically centered on the right, while the image, title and subtitle need to be vertically centered on the left.
Here's an image, it'll explain things better:
And I can't get either title and subtitle, nor badge vertically centered. I must do this using Bootstrap utilities only, so no additional CSS if possible(or very little if there's no other choice). How can I achieve this?
Here's my code:
.close {
font-size: 20px;
text-shadow: none;
color: #000;
opacity: 1;
position: absolute;
right: 0;
top: 0;
}
.card-title {
font-size: 18px;
}
.card-subtitle {
font-size: 11px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="card">
<button type="button" class="close close-chat mr-1" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<div class="card-header border-0 py-3">
<img src="http://placehold.it/45x45" class="rounded-circle float-left mr-3">
<h4 class="card-title mb-0 d-inline align-middle">Card title</h4>
<span class="badge badge-success float-right px-4 py-1 mt-2">Success</span>
<h6 class="card-subtitle text-muted">Card subtitle</h6>
</div>
<div class="card-block">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
Use the flexbox utility classes in Bootstrap 4. Here's a good guide to flexbox if you're not familiar.
The added classes in the code below are d-flex justify-content-between align-items-center, but you'll also need a new wrapper around the title and subtitle with its own classes.
.close {
font-size: 20px;
text-shadow: none;
color: #000;
opacity: 1;
position: absolute;
right: 0;
top: 0;
}
.card-title {
font-size: 18px;
}
.card-subtitle {
font-size: 11px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="card">
<button type="button" class="close close-chat mr-1" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<div class="card-header border-0 py-3 d-flex justify-content-between align-items-center">
<img src="http://placehold.it/45x45" class="rounded-circle float-left mr-3">
<div class="mr-auto">
<h4 class="card-title mb-0 d-inline align-middle">Card title</h4>
<h6 class="card-subtitle text-muted">Card subtitle</h6>
</div>
<span class="badge badge-success px-4 py-1 mt-2">Success</span>
</div>
<div class="card-block">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
Use the BS 4 flexbox utils. You can change the card-header to display:flex using the d-flex class then align its' contents accordingly...
http://codeply.com/go/qj2pblwSWB
<div class="card">
<button type="button" class="close close-chat mr-1" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<div class="card-header bg-info border-0 py-3 d-flex align-items-center">
<img src="http://placehold.it/45x45" class="rounded-circle align-self-start mr-3">
<div>
<h4 class="card-title mb-0">Card title</h4>
<h6 class="card-subtitle text-muted">Card subtitle</h6>
</div>
<span class="badge badge-success ml-auto px-4">Success</span>
</div>
<div class="card-block">
..
</div>
</div>
http://codeply.com/go/qj2pblwSWB
Bootstrap 4 leverages flexbox primarily for it's layout/grid utilities. You can use classes such as align-items-* to vertically position elements within a row. In this case align-items-center can be used to center the items.
You'd use .col-*-auto in combination with .col within a .rowto have Bootstrap auto size elements.
You technically don't need to use a .card if you don't want to as long as you have control over the class representing this "card" like element. The grid system could give you much more control over the layout of your custom "card" like element.
Here is a link to a plunker demonstrating the functionality using the built in Bootstrap 4 classes.
<!-- This extra .row and .col.col-sm-auto allows card to be auto sized -->
<div class="row">
<div class="col col-sm-auto">
<div class="foo">
<div class="row align-items-center">
<div class="col col-sm-auto"><img class="rounded-circle" src="https://placeholdit.imgix.net/~text?txtsize=6&txt=50%C3%9750&w=50&h=50" /></div>
<div class="col col-sm-auto text-center">
<span>TITLE</span>
<br>
<span>SUBTITLE</span>
</div>
<div class="col"></div>
<div class="col col-sm-auto text-right">
<span>BADGE</span>
</div>
<div class="col col-sm-auto">
<span class="close">X</span>
</div>
</div>
</div>
</div>
</div>
Hopefully this helps!

Putting Elements side by side

I am trying to put these two elements side by side. I tried using the float: right or float left, but so far no luck. Here is my html code.
#idd11 {
float: left;
width 100px;
height 100px;
}
<div class="row row-bottom-padded-sm" id="idd11" style="display: block">
<div class="col-md-4 col-md-9 col-xxs-9">
<div class="fh5co-project-item to-animate">
<div class="fh5co-text">
<span><br></span>
<h2 align="center">Items List</h2>
<span><br></span>
<div id="MainMenu">
<div class="list-group panel">
<a href="#item1" class="list-group-item list-group-item-default strong item1" data-toggle="collapse" data-parent="#MainMenu">
Item 1
<i class="fa fa-caret-down"></i>
</a>
<div class="collapse" id="item1"></div>
</div>
<div class="list-group panel">
<a href="#item2" class="list-group-item list-group-item-default strong item2" data-toggle="collapse" data-parent="#MainMenu">
Item 2
<i class="fa fa-caret-down"></i>
</a>
<div class="collapse" id="item2"></div>
</div>
</div>
<h2 id="answer">Footer</h2>
</div>
</div>
<!--Answer A-->
<div class="row row-bottom-padded-sm" id="floating" style="display: block">
<div class="col-md-4 col-md-3 col-xxs-3">
<div class="fh5co-project-item to-animate">
<div class="fh5co-text">
<span><br></span>
<div id="MainMenu">
<h1 id="newAnswer">A</h1>
</div>
</div>
</div>
</div>
</div>
<!--Answer A-->
</div>
</div>
If anybody can help me with it, it would be greatly appreciated. I tried at least :p. I attached a screenshot too: I want to put the A element in the right side of the Items list.
Use display: flex; for the id="MainMenu" . you can then adjust the width and height for its child elements too..
Try learning more about css3 flexbox property
You need three divs to do this. One div to hold the other two child divs. Then float the two child divs next to each other. So put the things you want floated next to each other inside a div and try to float them.
HTML
<div id='parent'>
<div id='child1'>
...
</div> <!-- End child1 div -->
<div id='child2'>
...
</div> <!-- End child2 div -->
</div> <!-- End parent div -->
CSS
#parent{
width: 500px;
}
#child1{
float: left;
width: 40%;
}
#child2{
float: right;
width: 40%;
}
In your code, you have the div you are trying to float to the right within the div you are trying to float to the left. You need to make sure your divs are separated and put into a parent div. Take a look at my example and notice how my divs are separate from each other, but inside a parent div
<div id='parent'> <!-- Look here -->
<div class="row row-bottom-padded-sm" id="idd11" style="display: block">
<div class="col-md-4 col-md-9 col-xxs-9">
<div class="fh5co-project-item to-animate">
<div class="fh5co-text">
<span><br></span>
<h2 align="center">Items List</h2>
<span><br></span>
<div id="MainMenu">
<div class="list-group panel">
<a href="#item1" class="list-group-item list-group-item-default strong item1" data-toggle="collapse" data-parent="#MainMenu">
Item 1
<i class="fa fa-caret-down"></i>
</a>
<div class="collapse" id="item1"></div>
</div>
<div class="list-group panel">
<a href="#item2" class="list-group-item list-group-item-default strong item2" data-toggle="collapse" data-parent="#MainMenu">
Item 2
<i class="fa fa-caret-down"></i>
</a>
<div class="collapse" id="item2"></div>
</div>
<h2 id="answer">Footer</h2>
</div>
</div>
</div>
</div> <!-- End the floating left section -->
<!--Answer A-->
<div class="row row-bottom-padded-sm" id="floating" style="display: block">
<div class="col-md-4 col-md-3 col-xxs-3">
<div class="fh5co-project-item to-animate">
<div class="fh5co-text">
<span><br></span>
<div id="MainMenu">
<h1 id="newAnswer">A</h1>
</div>
</div>
</div>
</div>
</div> <!-- End the floating right Section -->
<!--Answer A-->
</div> <!-- End parent div -->