How can I display page content according to the button I click?
I would like that on entering the page it presents the HTML of a button, but if you click on the other button the page loads another HTML.
I made a very simple example, and I would like the page to load the html inside the container class and then click on another button to load the content of the container-fluid class.
Sorry if I was confused.
Thanks!
My simple example
<li class="nav-item">
<a class="Grelha">
<img src="http://icons.iconarchive.com/icons/hopstarter/button/128/Button-Close-icon.png" style="width:30px; height:30px; cursor:pointer" >
</a>
</li>
<li class="nav-item">
<a class="Vquadrado">
<img src="http://icons.iconarchive.com/icons/hopstarter/button/128/Button-Play-icon.png" style="width:30px; height:30px cursor:pointer">
</a>
</li>
<div class="container">
<div class="row text-center text-lg-left tab-pane">
<div class="col-sm-2">
<a href="#" class="d-block mb-4 h-100">
<img class="Images" src="https://source.unsplash.com/pWkk7iiCoDM/400x300" alt="">
<div class="ImageText"> Name</div>
</a>
</div>
<div class="col-sm-2">
<a href="#" class="d-block mb-4 h-100">
<img class="Images" src="https://source.unsplash.com/aob0ukAYfuI/400x300" alt="">
<div class="ImageText"> Name</div>
</a>
</div>
</div>
</div>
<div class="container-fluid">
<div class="d-flex flex-row flex-wrap" style="margin-left: 3px;">
<div class="d-flex flex-column">
<a>
<img src="https://images.unsplash.com/photo-1485963631004-f2f00b1d6606?auto=format&fit=crop&w=668&q=80" class="img-fluid Vimages">
<div class="VimageText"> Name1</div>
</a>
<a>
<img src="https://images.unsplash.com/photo-1502865787650-3f8318917153?auto=format&fit=crop&w=334&q=80" class="img-fluid Vimages">
<div class="VimageText"> Name1</div>
</a>
</div>
</div>
</div>
You can toggle container with all styles which makes it visible or not.
For example:
display:none;
visibility: hidden;
const button1 = document.querySelector('.toggle-first');
const button2 = document.querySelector('.toggle-second');
const firstContainer = document.querySelector('.first');
const secondContainer = document.querySelector('.second');
button1.addEventListener('click', () => {
firstContainer.style.display = 'block'; // Or visibility: visible or other style
secondContainer.style.display = 'none';
});
button2.addEventListener('click', () => {
secondContainer.style.display = 'block'; // Or visibility: visible or other style
firstContainer.style.display = 'none';
});
<div class="container first">
<h1> First container </h1>
</div>
<button class="toggle-first"> Toggle first container </button>
<div class="container second">
<h1> Second container </h1>
</div>
<button class="toggle-second"> Toggle second contianer </button>
Related
I have a modal with a dropdown. When clicking the dropdown the modal always gets a scrollbar and I wanted to know if I miss something obvious? I could probably just add a class modalheight and define in css:
.modalheight {
min-height: 400px;
}
but this seems not like a true solution.
function closeModal () {
var modal = document.getElementById("mymodal")
modal.classList.remove("is-active")
};
function activateDropDown () {
var dropdown = document.getElementById("mydropdown");
dropdown.classList.add("is-active")
};
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.9.4/css/bulma.min.css">
<div class="modal is-active" id="mymodal">
<div class="modal-background">
</div>
<div class="modal-content">
<div class="box">
<article class="media">
<div class="media-content">
<div class="content">
this is a test:
<div class="dropdown" id="mydropdown">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu" onclick="activateDropDown()">
<span>Dropdown button</span>
<div class="dropdown-menu" id="dropdown-menu" role="menu">
<div class="dropdown-content">
<a href="#" class="dropdown-item">
test 1
</a>
<a href="#" class="dropdown-item">
test 2
</a>
<a href="#" class="dropdown-item">
test 3
</a>
</div>
</div>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
Can I somehow make the modal big enough to fit all the buttons options dynamically? If not, how would I do it statically?
Check this option, I think the behaviour is connected with the dropdown menu absolute positioning that takes it out of the normal flow. By the way, for button html tag both the starting and ending tag are mandatory.
function closeModal () {
var modal = document.getElementById("mymodal")
modal.classList.remove("is-active")
};
function activateDropDown () {
var dropdown = document.getElementById("mydropdown");
dropdown.classList.toggle("is-active")
};
#dropdown-menu {
position: static;
}
#modal-content {
max-height: none;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.9.4/css/bulma.min.css">
<div class="modal is-active" id="mymodal">
<div class="modal-background">
</div>
<div class="modal-content" id="modal-content">
<div class="box">
<article class="media">
<div class="media-content">
<div class="content">
this is a test:
<div class="dropdown" id="mydropdown">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu" onclick="activateDropDown()"> <span>Dropdown button</span></button>
<div class="dropdown-menu" id="dropdown-menu" role="menu">
<div class="dropdown-content">
<a href="#" class="dropdown-item">
test 1
</a>
<a href="#" class="dropdown-item">
test 2
</a>
<a href="#" class="dropdown-item">
test 3
</a>
</div>
</div>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
I'm working on making a site, and im currently dealing with BS4.1.3
I'm still new to this world so i have this issue right now:
<div class="container">
<nav class="navbar sticky-top">
<div class="grid">
<div class="row">
<div class="col-md-4">
<a class="btn btn-primary" data-toggle="collapse" href="#collapse-top-menu" role="button" aria-expanded="false" aria-controls="collapse-top-menu">
<img src="img/baseline-menu-24px.svg">
</a>
</div>
<div class="col-md-4">
<a class="navbar-brand" href="#">
<img src="img/bootstrap-solid.svg" width="40" height="40">
</a>
</div>
<div class="col-md-4">
Test
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="collapse" id="collapse-top-menu">
<input type="text" class="form-control" id="input-top-collapse-search" placeholder="Cosa stai cercando?">
</div>
</div>
</div>
</div>
</nav>
</div>
But the end result it's like this
While i wanted that the first blue button and the "logo" (B) were aligned, "test" a lot more in the right part of the navbar
Also the bottom search bar should be the same width as the container, so full lenght
<div class="container">
<nav class="navbar sticky-top">
<div class="grid">
<div class="row">
<div class="col-md-4">
<a class="btn btn-primary" data-toggle="collapse" href="#collapse-top-menu" role="button" aria-expanded="false" aria-controls="collapse-top-menu">
<img src="img/baseline-menu-24px.svg">
</a>
</div>
<div class="col-md-8 pull-right">
<a class="navbar-brand" href="#">
<img src="img/bootstrap-solid.svg" width="40" height="40">
<span>Test</span>
</a>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="collapse" id="collapse-top-menu">
<input type="text" class="form-control" id="input-top-collapse-search" placeholder="Cosa stai cercando?">
</div>
</div>
</div>
</div>
</nav>
</div>
.collapse input{
width:100%;
}
I am on mobile Stack Overflow app hence not able to test this.
In Bootstap 4, to put the test at the right of the navbar you can try,
<ul class="navbar-nav ml-auto">The content which goes to right comes here as a li</ul>
Also for aligning the blue button (The button you are using here is called as hamburger, remember that) can be aligned by using some margin-top for it.
Just use a CSS selector to select the hamburger and give some margin-top property to it.
Please consider adding a codepen so that we mobile users can play around with your code.
I'm creating my first HTML website using Bootstrap, and I have been following this template: Freelancer - Start Bootstrap.
I've been able to customize the template to fit my needs for the most part. However, I have not been able to figure out how I can make it so that when I hover over a picture, you get the color overlay and the YouTube logo appears, and then when you click on the transparent overlay, the link opens.
With the template I'm using, there is an example of this, included below, but instead of a modal opening when you click on the overlay, I want an external URL to open. To do this, I thought I could just change the href to point to the external URL, but this doesn't seem to work. I can right click and open in a new window, but clicking on the overlay does nothing.
Image with overlay & logo:
<div class="col-md-4 col-lg-3">
<a class="portfolio-item d-block mx-auto" href="#s-sign">
<div class="portfolio-item-caption d-flex position-absolute h-100 w-100">
<div class="portfolio-item-caption-content my-auto w-100 text-center text-white">
<i class="fa fa-search-plus fa-3x"></i>
</div>
</div>
<img class="img-fluid" src="img/project/s_sign.png" alt="">
</a>
</div>
Modal that pops up when clicked on:
<div class="portfolio-modal mfp-hide" id="s-sign">
<div class="portfolio-modal-dialog bg-white">
<a class="close-button d-none d-md-block portfolio-modal-dismiss" href="#">
<i class="fa fa-3x fa-times"></i>
</a>
<div class="container text-center">
<div class="row">
<div class="col-lg-8 mx-auto">
<h2 class="text-secondary text-uppercase mb-0">Decorative Sign</h2>
<hr class="star-dark mb-5">
<img class="img-fluid mb-5" src="img/project/s_sign.png" alt="">
<p class="mb-5">The frame is made from poplar. The slats are red oak. The "S" is MDF and was cut out by hand.</p>
<a class="btn btn-primary btn-lg rounded-pill portfolio-modal-dismiss" href="#">
<i class="fa fa-close"></i>
Close Project</a>
</div>
</div>
</div>
</div>
</div>
My attempt to modify the href to point to an external URL instead of the modal section:
<div class="col-md-6 col-lg-4">
<a class="projects-item d-block mx-auto" href="https://youtu.be/qXev3N5QE9A">
<div class="projects-item-caption d-flex position-absolute h-100 w-100">
<div class="projects-item-caption-content my-auto w-100 text-center text-white">
<i class="fa fa-youtube fa-3x"></i>
</div>
</div>
<img class="img-fluid" src="img/youtube/tote.png" alt="">
</a>
</div>
I know how to make it so I can click on the image, and the URL opens, as seen below, but I want to have the overlay and logo appear when hovering.
<div class="col-md-6 col-lg-4">
<a class="nav-link external" href="https://youtu.be/zjTrW9-GrSs">
<img class="img-fluid" src="img/youtube/tote.png" alt="">
</a>
</div>
However over image to reveal overlay, can right-click to open, but cannot click to open:
This might get you started.
Within your bootstrap column, create a container div that is the approx shape of the images/overlays you wish to move one on top of the other.
Within the container div, which should be made position:relative, make two more container divs, both position:absolute (so then can sit exactly one on top of the other)
Inside each pos:abs container div go your specific image and your youTube logo/overlay.
Then you can use javascript/jquery to swap them around on hover (or mouseenter/mouseleave).
$('.myImg').mouseenter(function(){
$(this).fadeOut();
$(this).next().fadeIn();
});
$('.ytLogo').mouseleave(function(){
$(this).fadeOut();
$(this).prev().fadeIn();
});
$('.ytLogo').click(function(){
$(this).find('a').click();
});
.ytContainer{position:relative;}
.myImg{position:absolute;height:50px;width:50px;}
.ytLogo{display:none;}h
.w-100{width:100px;}
.h-100{height:100px;}
.fa{width:100px;height:100px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<div class="col-xs-6 col-md-6 col-lg-4">
<div class="ytContainer">
<div class="myImg">
<img class="img-fluid ytImg" src="http://placeimg.com/100/100/animals" alt="">
</div>
<div class="ytLogo">
<a class="projects-item d-block mx-auto" href="https://youtu.be/qXev3N5QE9A">
<div class="projects-item-caption d-flex position-absolute h-100 w-100">
<div class="projects-item-caption-content my-auto w-100 text-center text-white">
<i class="fa fa-youtube fa-3x"></i>
</div>
</div>
</a>
</div>
</div>
</div>
I want to use css, bootstrap to align the first line align left, and the second line will center on the text length of the first line.
I tried many ways but not.
code follow
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<div class="col-md-2" style="padding:0">
<img src="/Content/images/logo.png" class="img-responsive" alt="">
</div>
<div class="col-md-10 tex-center" style="padding-right:0;">
<div style="padding:0">
<div class="line1-bold">THIS IS THE FIRST LONG HEADLINE</div>
<div class="line2">THIS IS THE SECOND HEADLINE</div>
</div>
</div>
</div>
</a>
</div>
Please check this..
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<div class="col-xs-2" style="padding:0">
<img src="https://www.tenforums.com/attachments/browsers-email/18558d1485951187t-microsoft-edge-logo-microsoft-edge-100582336-large.png" class="img-responsive" style="width:100px" alt="">
</div>
<div class="" style="float:left;">
<div class="line1-bold" style="color:#b63957; font-size:18px;">THIS IS THE FIRST LONG HEADLINE</div>
<div class="line2" style="color:#b63957; font-size:16px; text-align:center;">THIS IS THE SECOND HEADLINE</div>
</div>
</div>
</a>
</div>
Try adding the class text-center to your divs.
Here is a working pen.
Something like this?
I don't know about your task, but I deleted some tags.
CSS
.img-responsive {
width: 100px;
float: left;
}
span {
display: block;
}
HTML
<div class="col-md-6">
<a href="/" style="text-decoration:none">
<div class="col-md-12 row-eq-height" style="padding:0;">
<img src="https://www.tenforums.com/attachments/browsers-email/18558d1485951187t-microsoft-edge-logo-microsoft-edge-100582336-large.png" class="img-responsive" alt="">
<span class="text-left">THIS IS THE FIRST LONG HEADLINE</span>
<span class="text-center">THIS IS THE SECOND HEADLINE</span>
</div>
</a>
</div>
Reference Link
I searched here already and tried some accepted solutions but not worked for my case. I have listed some html and I need these elements both wrapper element and inner elements in single line.
here how it looks now and html;
html;
<div class="container-fluid">
<div class="col-sm-4 col-md-4 col-lg-4">
<div class="well">
<ul class="media-list">
<li class="media">
<a class="toggle-area pull-left" href="javascript:void(0);">
<img class="media-object" alt="Mali Sistemler" src="/Content/img/login/mali_hizmetler.png">
</a>
<div class="media-body">
<h4 class="toggle-area media-heading"><span style="width: 95%;">Mali Sistemler</span><i class="fa fa-parent-container fa-plus-square pull-right"></i></h4>
<div class="container-menus" style="display:none;"></div>
</div>
</li>
</ul>
</div>
<div class="well">... </div>
</div>
<div class="col-sm-4 col-md-4 col-lg-4">
<div class="well">
<ul class="media-list">
<li class="media">
<a class="toggle-area pull-left" href="javascript:void(0);">
<img class="media-object" alt="Denetim Sistemleri" src="/Content/img/login/denetim.png">
</a>
<div class="media-body">
<h4 class="toggle-area media-heading"><span style="width: 95%;">Denetim Sistemleri</span><i class="fa fa-parent-container fa-plus-square pull-right"></i></h4>
<div class="container-menus" style="display:none;"></div>
</div>
</li>
</ul>
</div>
<div class="well">... </div>
</div>
</div>
Sequences of white-space will collapse into a single white-space. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered
Use white-space:nowrap
Update css
.media-body, .media-left, .media-right {
display: table-cell;
vertical-align: top;
white-space: nowrap; /* Add this */
}
Working fiddle
fiddle code