How to make collapse button inside div properly in bootstrap? - html

I am tring to make a collapse button for my quote container but when I click it, on the first click, nothing happens but when I click again, the whole div disappears? I think I am following correctly the sample here? getbootstrap
Also in my fiddle my collapse button the minus(-) is not functioning. But in my google chrome browser it is ok? Is it also possible that when I collapse, when it's collapse I can change to another fontawesome icon? the minus becomes plus when collapse/hidden?
this is my code and js fiddle:
JSFIDDLE
HTML
<div class="quote-box" id="collapse-quote">
<div class="text">
asdasd
</div>
<div class="buttons">
<button class="button" id="twitter-button"><a title="Tweet this quote!" target="_blank"> tweet
<i class="fa fa-twitter"></i>
</a></button>
<button class="button" id="facebook-button"><a title="Share this quote!" target="_blank">share
<i class="fa fa-facebook"></i>
</a></button>
<button class="button" id="close-open" type="button" data-toggle="collapse" data-target="#collapse-quote" aria-expanded="false" aria-controls="collapse-quote">
<i class="fa fa-minus"></i>
</button>
</div>
</div>
scss
.quote-box {
text-align: center;
position: relative;
border-radius: 4.5px;
border: solid black 1px;
display: table;
width: 50%;
height: 500px;
padding: 10%;
margin: 10% auto auto auto;
/* center the box */
}
.quote-box .buttons {
top: 0;
/* align to top */
left: 0;
width: 100%;
position: absolute;
/* out of the document flow and you can move*/
height: 100%;
text-align: left;
padding: 1%;
box-sizing: border-box;
}
/* sample: uncomment if you want to align on right
#twitter-button{
float: right;
}
*/
#close-open {
/* float the collapse button to the right */
float: right;
}
.fa-minus {
color: #11A5D6;
/* color for the button */
}
What am I doing wrong? I been fixing for a button for hours.

It works for me. All I did was remove your jquery-2.2.3.min.js reference and changed your bootstrap.min.js to use https.
You have other issues too, check out this Fiddle.
css
.quote-box {
text-align: center;
position: relative;
border-radius: 4.5px;
border: solid black 1px;
width: 50%;
padding: 10%;
margin: 10% auto auto auto; /* center the box */
}
html, you were missing the collapse class on the div, and also if you collapse all the buttons how are you supposed to get back to them?
<div class="quote-box">
<div class="text collapse" id="collapse-quote">
asdasd
</div>
<div class="buttons">
<button class="button" id="twitter-button"><a title="Tweet this quote!" target="_blank"> tweet
<i class="fa fa-twitter"></i>
</a></button>
<button class="button" id="facebook-button"><a title="Share this quote!" target="_blank">share
<i class="fa fa-facebook"></i>
</a></button>
<button class="button" id="close-open" type="button" data-toggle="collapse" data-target="#collapse-quote" aria-expanded="false" aria-controls="collapse-quote">
<i class="fa fa-minus"></i>
</button>
</div>
</div>

Related

How to show hidden div tag when hover on another div tag using css

I have an issue i know it is small but for my necessity i have doubt when i hover on one div i want second div should display and remove cursor again it should hidden how to do this using css
div 2 which will be hidden so when hover on div it should show this div tag and again hover remove it should get hidden using css
<div>
<a href="javascript:void(0)">
<div class="show-all-hover-zone" style="height: 212px;">
<i class="fa fa-chevron-left" style="font-size:25px;color:darkslategrey;position:relative;top:97px;"></i>
</div>
</a>
<div style="background-color:whitesmoke;padding: 3px;height:210px;width:0px;position:absolute;top:164px;display:none;" class="expand-menu1">
</div>
In your case
a:hover ~.expand-menu1{
display: block !important;
}
But don't use inline, please. It can be much more elegant.
For example:
HTML
<a class="hoverOnShow" href="javascript:void(0)">
<div class="show-all-hover-zone">
<i class="fa fa-chevron-left" ></i>
</div>
</a>
<div class="expand-menu1">
</div>
CSS
.show-all-hover-zone{
height: 212px;
}
.fa-chevron-left{
font-size: 25px;
color:darkslategrey;
position:relative;
top: 97px;
}
.expand-menu1{
background-color:whitesmoke;
padding: 3px;
height: 210px;
width: 0px;
position:absolute;
top: 164px;
display:none;
}
.hoverOnShow:hover ~.expand-menu1{
display: block;
}

Vertically align two items by the middle of each item

Sorry if the title is confusing. Hopefully, the image speaks for itself.
How can I use css to align the middle of the plus sign with the cross section of the x?
I know I could use something like position to nudge the x up a few pixels but I'm looking for a more consistent solution that works for several different screen sizes.
Heres the HTML. pretty-link is just a class with the cursor property set to hand and pointer
<span className='pull-right' style={{verticalAlign: 'middle', margin: 'auto', display: 'inline-block'}}>
<i className='fa fa-minus pretty-link' style={{verticalAlign: 'middle'}} onClick={e => toggleSystemUnit(e, index)}></i>
<i className='fa fa-times pretty-link' style={{verticalAlign: 'middle'}}></i>
</span>
Here is an example utilizing flex, does not work
http://jsfiddle.net/f1aejwwf/1/
Here is an example utilizing vertical-align, does not work
http://jsfiddle.net/hw4au2km/
In each example the x remains slightly below the +
Setting explicit widths for a wrapping span and floating each:
http://jsfiddle.net/u99q01t2/2/
In each of these examples the x seems to land slightly below the + so maybe it's a problem with fa?
For anyone coming here from Google, I do not think the fa-times icon can easily be aligned this way. All the above solutions work great for fa-plus and fa-minus but the fa-times icon is slightly off-center. Maybe someone can find a solution to that but for now I've switched to material icons for my project.
Those two images are horizontally aligned on the baseline, that's why you need to add some margin-bottom to the right one in order to make them horizontally centered, I think 2px do the job just fine:
.pretty-link {
cursor: pointer;
/* display: inline-block; not necessary */
vertical-align: middle;
}
.containerdiv {
display: flex; /* displays children inline */
justify-content: space-between; /* children are evenly distributed, first child is on the far left, last on the far right */
align-items: center; /* vertical alignment / centering */
margin: auto;
width: 70%;
padding: 5px 20px 5px 10px;
background-color: #eee;
border-bottom: 2px solid #ddd;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class='containerdiv'>
<h4>Detail</h4>
<span class='pull-right'>
<i class='fa fa-plus pretty-link'></i>
<i class='fa fa-times pretty-link' style="margin-bottom: 2px;"></i>
</span>
</div>
I created this snippet to help you with your question. As you can see the two blocks have different heights but giving them display: inline-block; and vertical-align: middle; they are vertically centered. Hope it helps :)
.element.first {
font-size: 65px;
background: blue;
margin-right: 10px;
}
.element.second {
font-size: 35px;
background: yellow;
}
.element {
display: inline-block;
vertical-align: middle;
}
<div class="container">
<div class="element first">First Icon</div>
<div class="element second">Second Icon</div>
</div>
Give your span class a width and height, then give your first <i> class float:left; and your second <i>classfloat:right; Both <i>must have width in px;
You can try this
<!DOCTYPE html>
<html>
<head>
<style>
.textpart {
margin-left: -6px;
}
</style>
</head>
<body>
<h1 class="text">+<span class="textpart">X</span></h1>
</body>
</html>
You can use flexbox or line-height . Flexbox is the greatest way if you are using autoprefixer and a task runner.
HTML
<h3>
Normal
</h3>
<span>
<i class="fa fa-minus pretty-link"></i>
<i class="fa fa-times pretty-link"></i>
Lorem ipsum
</span>
<hr>
<h3>
Flex
</h3>
<span class="container-flex">
<i class="fa fa-minus pretty-link"></i>
<i class="fa fa-times pretty-link"></i>
Lorem ipsum
</span>
<hr>
<h3>
Line Height
</h3>
<span class="container-line-height">
<i class="fa fa-minus pretty-link"></i>
<i class="fa fa-times pretty-link"></i>
</span>
CSS
.container-flex{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.container-line-height .fa{
vertical-align: middle;
display: inline-block;
}

CSS image background and overlay blocking link and text input click and focus

I have the following html and css:
.icon-bar {
width: 90px;
z-index: 100;
position: absolute;
}
#overlay {
position: absolute;
background-color: rgba(0,0,0,0.8);
top:0;
left: 0;
bottom:0;
height:100%;
width:100%;
z-index: -2;
}
#cover-photo {
width:100%;height: 400px;
background:url('./assets/covers.jpg') no-repeat center center fixed;
color:#fff;
background-size:cover;
text-align: center;
z-index: -1;
}
<div class="row">
<div class="col-md-12" id="cover-photo">
<div id="overlay">
</div>
<div class="icon-bar col-md-push-10">
<a class="active" href="#"><i class="fa fa-home"></i></a>
<i class="fa fa-search"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-globe"></i>
<i class="fa fa-trash"></i>
</div>
</div>
</div>
Now the background image is appearing, as well as the overlay div as expected, the div with the icon-bar class also appears in the front, but when I try to click one of the links inside that div it does not get the click, i have set a z-index of 100 for this div but it is unclickable, please assist me on this guys
You can add pointer-events: none to the overlay div. This will allow clicking the links behind it.
I think I got your point here. What's wrong in your code is where you position <div id="overlay"></div>
It should place after the end tag of cover-photo
I also rearrange your codes and modify some it.
My advise is not to make to have negative z-index instead use smaller to greater number to overlap the property of one element to another.
#cover-photo {
width: 100%;
height: auto;
background: url('./assets/covers.jpg') no-repeat center center fixed;
color: #fff;
background-size: cover;
text-align: center;
z-index: 5;
}
.icon-bar {
width: 90px;
z-index: 100;
position: relative;
}
#overlay {
position: fixed;
background-color: rgba(0, 0, 0, 0.8);
top: 0;
left: 0;
bottom: 0;
height: 100%;
width: 100%;
z-index: 1;
}
<div class="row">
<div class="col-md-12" id="cover-photo">
<div class="icon-bar col-md-push-10">
<a class="active" href="#"><i class="fa fa-home"></i></a>
<i class="fa fa-search"></i>
<i class="fa fa-envelope"></i>
<i class="fa fa-globe"></i>
<i class="fa fa-trash"></i>
</div>
</div>
<div id="overlay"></div>
</div>
I think it is because of anchor tag it is inline tag
try to make it inline-block so it will work.
Check below link
https://jsfiddle.net/ashishbhalerao/Ldot4y96/4/
Thanks,
Ashish Bhalerao

Positioning Font Awesome icon and a paragraph

I wanna position the icon to be on top of the sentence and both centered within bootstrap column. I tried changing the position and display in css for both the paragraph and icon but it doesnt work.
Right now it looks like this
I want it to be like this
Here's the code
#home-info {
width: 500px;
height: 200px;
background-color: rgba(0,0,0,0.7);
top: 550px;
z-index: 1;
position: absolute;
}
.col-md-3 {
height: 100px;
background-color: #1e2c38;
text-align: center;
color: white;
border-bottom: 1px solid white;
border-top: 1px solid white;
}
.col-md-4 {
height: 300px;
text-align: center;
background-color: #1b2328;
}
.col-md-3 p {
position: relative;
width: 300px;
text-align: center;
}
<div class="container-fluid"> <!-- HOME INFO -->
<div class="row">
<div class="col-md-3" id="navy2">
<div class="content-container">
<i class="fa fa-newspaper-o fa-3x" aria-hidden="true"></i>
<p>Learn more about our recent events and news!</p>
</div>
</div>
<div class="col-md-3" id="navy3">
<div class="content-container">
<i class="fa fa-calendar fa-3x" aria-hidden="true"></i>
<p>Stay up to date! Get the school's calendar here!</p>
</div>
</div>
<div class="col-md-3" id="navy2">
<div class="content-container">
<i class="fa fa-facebook-square fa-3x" aria-hidden="true"></i>
<p>Like and connect with us via Facebook!</p>
</div>
</div>
<div class="col-md-3" id="navy3">
<div class="content-container">
<i class="fa fa-youtube fa-3x" aria-hidden="true"></i>
<p>Learn more about us through our videos!</p>
</div>
</div>
</div> <!-- ROW -->
Thanks!
You can center it by making the inner p a display:block element and use margin: 0 auto to center it...
.col-md-3 p {
position: relative;
width: 300px;
display: block;
margin: 0 auto;
}
http://www.codeply.com/go/kFJwok7k0T
However, because you have the 300px set on the .col-md-3 p, the text will get cut-off at smaller widths. It would be better to not set any specific width on the .col-md-3 p so that it's responsive.
You may use <br> tag to separate the icon and text. And since you are using font-awesome icons, you use text-align: center to center both the icon and the text.

bootstrap collapse to show a div it work but how to make it didn't affect side items?

I was using bootstrap collapse to show a div but when i using it the side item will be affected like go down when a div open by collapse. how do i make side item wont be going down will stay at their position
here i have make a Jsfiddle example
here is my html code
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="right-lower-container">
<div class="testing-notification">
<span class="glyphicon glyphicon-comment notification-bar" data-toggle="collapse" data-target="#testing1"></span>
<div id="testing1" class="collapse notification-block">
testing 1
</div>
</div>
<span class="btn glyphicon glyphicon-bell notification-bar" data-toggle="collapse" data-target="#testing2"></span>
<div id="testing2" class="collapse notification-block">
testing2
</div>
<a class="option-font" href="#">
<span>
new items
</span>
</a>
<a class="option-font" href="#">
<span class="glyphicon glyphicon-search">
search
</span>
</a>
</div>
here is my css code
.right-lower-container {
height: 40%;
width: 100%;
display: block;
vertical-align: top;
text-align: right;
}
.notification-bar {
color: black;
margin-right: 2.5%;
}
.notification-bar:hover {
color: gray;
}
.notification-block {
width: 100px;
height: 100px;
}
.testing-notification {
display: inline-block;
width: 20%;
}
#testing1,#testing2{
background-color:red;
width:100px;
height:200px;
}
Add following css:
.option-font,
.notification-bar,
.testing-notification {
display: inline-block;
vertical-align: top;
}