Overlap divs within a div - html

This might be quite easy but I'm having problems getting this to work the way I need.
I'm using bootstrap and below is my css and div structure. I'm having 3 divs hidden and 3 buttons to make them visible. My problem is how do I make the divs be in the same level? At the moment the 3 divs are one below the other.
For Better understanding I've created a Fiddle.
<div class="row">
<div class="col-xs-6 col-xs-offset-3 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 wrapper">
<div class="groupHolder">
<div id="xx" class="overlapDiv" Style="background-color:#F00;">Fruits</div> // need these overlaping
<div id="yy" class="overlapDiv" Style="background-color:#888;">Flowers</div> // need these overlaping
<div id="zz" class="overlapDiv" Style="background-color:#f60;">Veggies</div> // need these overlaping
</div>
<div class="buttonHolder">
<button type="button" id="aa" class="standardBtn">Btn 1</button>
<button type="button" id="bb" class="standardBtn">Btn 2</button>
<button type="button" id="cc" class="standardBtn">Btn 3</button>
</div>
</div>
</div>

CSS visibility property just hide/show the element keeping the space of this element. If you want to remove the space of the element when it is invisible, you should use display property with block/none value.
like that :
https://jsfiddle.net/6Lf9spha/3/

Use this
.overlapDiv {display: inline-block;}
Z-index could work aswell

From what I understand you need, one of the possibilities is to not only make them invisible but hide them completely by changing visibility: hidden to display: none
$("#aa").click(function(){
$('.overlapDiv').css('display', 'none');
$('#xx').css('display', 'block');
});
overlapDiv{
display: block;
}
/* Make all elements except the first one hidden by default */
.overlapDiv:nth-child(n+2){
display: none;
}
Visibility affects if the element is visible, but does not change its playe in layout. ex. Element with visibility: hidden will still take space on the page, display: none will not.
$("#aa").click(function(){
$('.overlapDiv').css('display', 'none');
$('#xx').css('display', 'block');
});
$("#bb").click(function(){
$('.overlapDiv').css('display', 'none');
$('#yy').css('display', 'block');
});
$("#cc").click(function(){
$('.overlapDiv').css('display', 'none');
$('#zz').css('display', 'block');
});
.wrapper{
margin-top: 25px;
position: relative;
text-align: center;
}
.buttonHolder{
position: relative;
}
.groupHolder{
overflow: hidden;
position: relative;
}
.overlapDiv{
display: block;
}
.overlapDiv:nth-child(n+2){
display: none;
}
.standardBtn{
display: inline-block;
cursor: pointer;
padding: 12px 8px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-xs-6 col-xs-offset-3 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 wrapper">
<div class="groupHolder">
<div id="xx" class="overlapDiv" Style="background-color:#F00;">Fruits</div>
<div id="yy" class="overlapDiv" Style="background-color:#888;">Flowers</div>
<div id="zz" class="overlapDiv" Style="background-color:#f60;">Veggies</div>
</div>
<div class="buttonHolder">
<button type="button" id="aa" class="standardBtn">Btn 1</button>
<button type="button" id="bb" class="standardBtn">Btn 2</button>
<button type="button" id="cc" class="standardBtn">Btn 3</button>
</div>
</div>
</div>

Related

How can i divide the window in 4 columns and fill it with images

I'm trying to divide this in 4 columns, but this never works. I tried with full height,
<style="heigth:100%">
in each div and nothing resulted. I could do it with colors, but not with images.
So, how can I divide the window in 4, even when resized and fill it with images?
I have a nav-bar too, but for that I can put it with z-index=1 and make it be visible.
#index1 {
background: url('img/WhatsApp Image 2022-01-24 at 17.07.09.jpeg');
position: relative;
}
#index2 {
background: url('img/WhatsApp Image 2022-01-24 at 17.07.08.jpeg');
position: relative;
}
#index3 {
background: url('img/WhatsApp Image 2022-01-24 at 17.07.08(1).jpeg');
position: relative;
}
#index4 {
background: url('img/WhatsApp Image 2022-01-24 at 17.07.08(2).jpeg');
position: relative;
}
<div class="row col-md-12" style="width:100%; height:100%">
<div class="col-md-3" id="index1"><input type="button" class="btn btn-outline-info" onclick="myFunction1()" value="Calendar" /></div>
<div class="col-md-3" id="index2"><input type="button" class="btn btn-outline-info" onclick="myFunction2()" value="Classifications" /></div>
<div class="col-md-3" id="index3"><input type="button" class="btn btn-outline-info" onclick="myFunction3()" value="Winner-Driver" /></div>
<div class="col-md-3" id="index4"><input type="button" class="btn btn-outline-info" onclick="myFunction4()" value="Winner-Constructor" /></div>
</div>
You can set up flex layout and alignment using Bootstrap flex classes.
One problem is that your buttons don't fit on smaller screens. You may want to use a vertical stack for mobile and a row for larger screens.
#index1 {
background: url('https://via.placeholder.com/800');
}
#index2 {
background: url('https://via.placeholder.com/800/dddddd');
}
#index3 {
background: url('https://via.placeholder.com/800');
}
#index4 {
background: url('https://via.placeholder.com/800/dddddd');
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="d-flex vw-100 vh-100">
<div class="w-25 flex-column d-flex justify-content-center align-items-center" id="index1">
<input type="button" class="btn btn-outline-info" onclick="myFunction1()" value="Calendar" />
</div>
<div class="w-25 flex-column d-flex justify-content-center align-items-center" id="index2">
<input type="button" class="btn btn-outline-info" onclick="myFunction2()" value="Classifications" />
</div>
<div class="w-25 flex-column d-flex justify-content-center align-items-center" id="index3">
<input type="button" class="btn btn-outline-info" onclick="myFunction3()" value="Winner-Driver" />
</div>
<div class="w-25 flex-column d-flex justify-content-center align-items-center" id="index4">
<input type="button" class="btn btn-outline-info" onclick="myFunction4()" value="Winner-Constructor" />
</div>
</div>
By default any <div> has a height=0. It can expand if there is an element inside the div. But it will not expand with the size of background-image of the <div>.
Your code is perfect except that you have not specified height in the corresponding <div> elements. You have to specify height to each div containing a background. Otherwise the browser will make it's height=0 or in this case the height of the button.
Height='100%' does not work in your case because the row height will be calculated to 100% to it's largest child element (Not the browser window!). That is the div -> which is the height of it's child element button.
The height must be specified in either px, em, rem, vh. Height does not behave like width!
Easiest solution: Set row height to 100vh instead of 100%
If you want to set height of each div, you can do it by adding height or min-height property to them. Try experimenting with different values.
**Tip: You can check your div size by going to code inspector of browser (in windows: right mouse click and inspect)
<style>
#index1 {
background: url('https://source.unsplash.com/1600x900/?fire');
position: relative;
height: 90vh; //Experiment here
}
#index2 {
background: url('https://source.unsplash.com/1600x900/?beach');
position: relative;
height: 500px; //Experiment here
}
#index3 {
background: url('https://source.unsplash.com/1600x900/?team');
position: relative;
min-height: 100vh; //Experiment here
}
#index4 {
background: url('https://source.unsplash.com/1600x900/?love');
position: relative;
min-height: 50vh; //Experiment here
}
</style>
Html:
<div class="container-fluid">
<div class="row col-md-12">
<div class="col-md-3" id="index1"><input type="button" class="btn btn-outline-info" onclick="myFunction1()"
value="Calendar" /></div>
<div class="col-md-3" id="index2"><input type="button" class="btn btn-outline-info" onclick="myFunction2()"
value="Classifications" /></div>
<div class="col-md-3" id="index3"><input type="button" class="btn btn-outline-info" onclick="myFunction3()"
value="Winner-Driver" /></div>
<div class="col-md-3" id="index4"><input type="button" class="btn btn-outline-info" onclick="myFunction4()"
value="Winner-Constructor" /></div>
</div>
</div>
*Remember: The row will always have a height of the largest child element here.
I hope this guideline will help you in this project and all your future projects. All the best.

bootstrap css classes hierarchy

I would like to learn how to build my css file using bootstrap elements. It's pretty tricky to try to select a unique element when all have pretty much the same classes so beside using id's how can I select a unique element from a structure like this one?
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-md-2">CREATED</div>
<div class="col-md-2">MODIFIED</div>
<div class="col-md-2">USER STATUS</div>
<div class="col-md-2">STATUS</div>
<div class="col-md-2">MODEL</div>
</div>
<div class="row">
<div class="col-md-2">26/02/2018</div>
<div class="col-md-2">26/02/2018</div>
<div class="col-md-2">quote requested</div>
<div class="col-md-2">
<select class="form-control"></select>
<button class="btn btn-default">SAVE</button>
</div>
<div class="col-md-2">
<button class="btn btn-default">DOWNLOAD FILE</button>
</div>
<div class="col-md-2">
<button class="btn btn-default">SELECT</button>
</div>
</div>
</div>
</div>
Let's assume I want the DOWNLOAD FILE button to have this property: width:50% . How can I select that particular button without giving him an id?
Solution 1:
Use css selector instead of IDs.
Example:
.row .col-lg-12 .row:nth-child(2) .col-md-2:nth-child(5) button.btn.btn-default {
width: 50%;
background-color: red;
color: #ffffff;
}
More: W3School.
Here is the solution(1) of your question on Codepen.
Solution 2:
Use a custom css class for the button(s).
Example:
.btn-custom {
width: 50%;
background-color: red;
color: #ffffff;
}
Here is the solution(2) of your question on Codepen.
Hope this helps.

image in bootstrap column has space on right side

EDIT: This was my issue
bootstrap 4 center-block unable to center
I cannot for the life of me figure out how to properly align this image inside a bootstrap column. You can see how there is a big whitespace gap to the right of the image between the border of the image and the padding for the div column the image is in.
I have a row with 3 columns. I want the 2 images to be properly aligned in the page. this would be more easily accomplished if this awkward whitespace did not appear.
For now, I've added the below as a (not-so) quick fix.
.right-img {
padding-left: 45px;
}
I have tried several avenues including
class="center-block"
and removing
float-left
from the show-image class and flexbox and display-block and all the align properties and ensuring I have a container above the row.
I would really appreciate it if someone could help with the issue.
Here is the HTML:
<div class="container">
<div class="row">
<div class="col-lg-5 show-image">
<img class="img-responsive rounded head-img" src="{{ url_for('static', filename='#') }}" alt="Image Failed to Load">
<div class="hover-buttons">
<button type="submit" class="btn btn-danger btn-sm">Why Join?</button>
<button type="submit" class="btn btn-danger btn-sm">How It Works</button>
</div>
</div>
<div class="col-lg-2" id="with-container">
<h1 class="my-4 text-center">WITH</h1>
</div>
<div class="col-lg-5 show-image right-img">
<img class="img-fluid rounded head-img" src="{{url_for('static', filename='#')}}" alt="Image Failed to Load">
<div class="hover-buttons left-buttons">
<button type="submit" class="btn btn-danger btn-sm">Why Join?</button>
<button type="submit" class="btn btn-danger btn-sm">How It Works</button>
</div>
</div>
</div>
</div>
And here is the styling:
div {
border: 1px dashed red;
}
.head-img {
width: 400px;
height: 287px;
}
#with-container {
display: flex;
justify-content: center;
align-items: center;
}
div.show-image {
position: relative;
float: left;
}
div.show-image:hover img{
opacity:0.5;
}
div.show-image:hover .hover-buttons {
display: inline-block;
}
.hover-buttons {
position: absolute;
display:none;
}
div.show-image .hover-buttons {
top: 75%;
left: 12%;
}
div.show-image .left-buttons {
top: 75%;
left: 19%;
}
You could apply the following bootstrap helper class to the parent div:
text-center
Which should horizontally align the image for you. The full div class structure should look like the following:
<div class="col-lg-5 show-image text-center">
Further reading: https://v4-alpha.getbootstrap.com/utilities/typography/#text-alignment

Right aligned button is misaligned vertically

I have a row with header text and a button on the right.
<div class="page-header">
<div class="pull-right">
<button type="button" class="btn btn-success pull-right">Set All Values</button>
</div>
<h4>Points Earned for Each Chapter</h4>
</div>
The code above is what I have currently but I have tried many variations. In all of them, the button is not vertically aligned with the text. (The image below includes the overlay when I hover over the element in the Elements pane of Chrome, in order to show vertical alignment.)
Searching existing questions on stackoverflow, I've found this question posted a number of times; however, I found no knowledgeable answers.
Has anyone figured this out?
This happens because the line-height of the heading and the height of the button differ.
With a line-height: 1.9; for the heading it should work:
.page-header h4 {
line-height: 1.9;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="page-header">
<div class="pull-right">
<button type="button" class="btn btn-success pull-right">Set All Values</button>
</div>
<h4>Points Earned for Each Chapter</h4>
</div>
You can try using the grid to be mobile friendly and make everything inside vertically aligned.
<div class="page-header vertical-center">
<div class="row">
<div class="col-md-8">
<h1>Text on the left</h1>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-success pull-right">Set All Values</button>
</div>
</div>
</div>
Add this CSS
.row > div {
border: 1px solid black;
}
.vertical-center .row {
display: flex;
align-items: center;
}
/*maybe create an id instead of h1*/
h1 {
margin: 0;
}

Text always overflowing on the right in Bootstrap modal dialog

I have created a small dialog with UI Bootstrap that contains some basic text. The text content always overflow on the right when it's too large. Here is the code:
<div>
<script type="text/ng-template" id="/panel-list/panel-list.details-template.html">
<div class="modal-header">
<h3 class="modal-title">{{panel.name}}</h3>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col-md-1">
<img src={{panel.image_url}} id="img-beer">
</div>
<div class="col-sm-10 col-md-10 col-lg-10 details-info-content">
<p>
{{panel.description}}
</p>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">Close</button>
</div>
</script>
</div>
I have added in the CSS the following stype property:
.details-info-content {
overflow-wrap:break-word;
}
.modal-dialog {
width: 75%;
height: 70%;
}
but the problem persists. Where is the error?
You can simply use Bootstrap's text-wrap class.
I think you have a typo - overflow-wrap, not overflow-wrape
Try this
.details-info-content {
word-wrap: break-word;
}
.modal-dialog {
width: 75%;
height: 70%;
}