How can I target a div without missing the title part? Let's say I have this code:
<div class="row featurette" id="Feeding">
<div class="col-md-7">
<h2 class="featurette-heading">1. Transformational Feeding </h2>
<p class="lead text-justify">As TransDev provides supplemental feeding (lunch three times per week) to undernourished school children, the mothers of the participating children are encouraged to plant vegetables to ensure availability of food on the table. With the increase in price of commodities, food production, will provide an additional income for the family.</p>
</div>
<div class="col-md-5">
<img class="featurette-image img-responsive" src="contents/gallery/7.jpg" alt="Generic placeholder image">
</div>
</div>
and for the button:
<a class="btn btn-warning" href="index.php?pl1=about#Feeding" role="button">Learn more</a>
But whenever I click the button, it looks like this:
Output
When it should look like this:
How it should be
So maybe it's my navbar that messes the content? Is it something that I can fix with css? I tried putting the ID on the <h2>, but the result is the same.
Your code is working correctly, clicking you anchor scrolls the page so that the h2 is in the top. Problem is with your menu that has fixed positioning and is overlapping it.
This should be fixable with JS by overriding default a behaviour and writing your custom logic that adds the height of your navbars to the target scroll position, like so:
function scrollToAnchor(id){
var navbarHeight = $(".menu").height(); // or whatever seletor you use for navbar
var aTarget = $(id);
$('html,body').animate({scrollTop: aTarget.offset().top-navbarHeight},'slow');
}
You need to trigger this function when clicking on an item that is supposed to do the scroll. Assuming your a looks like this:
<a class="menu-item btn btn-warning" href="Feeding" role="button">Learn more</a>
you can use do:
$('a.menu-item').click(function(){
scrollToAnchor($(this).attr('href'));
});
But if you want to use a full path in your a that does the page reload and than scrolls to the id than your're gonna need to play with reading an url, extracting value after hash and than triggering scrollToAnchor, like t his:
$(document).ready(function(){
if(window.location.hash) {
var hash = window.location.hash;
scrollToAnchor(hash);
}
});
Here's the working demo on jsFiddle: http://jsfiddle.net/ony0590k/
Related
enter image description hereMy image wont show within the accordion line. Wondering how to fix this?
<div class="accordion-item">
<button id="accordion-button-2" aria-expanded="false"><span class="accordion-title">What do these icons
mean? <img src="/Untitled.png" alt="Untitled"></span><span class="icon" aria-hidden="true"></span></button>
<div class="accordion-content">
<p>They show you how many items have been offered for the pictured item. For example this item has had 7 items
offered. It is up to the items owner to decide which item to accept.</p>
</div>
</div>
The problem is most likely that your image is not in the position you mentioned in the src attribute.
I would recommend you to take a look at how the HTML file paths work. Iäll provide you with a link: https://www.w3schools.com/html/html_filepaths.asp
I am trying to put tooltips on divs in an attempt to explain a user interface I'm working on.
On the right div the tooltip shows up just fine, and exactly how I want it to.
On the other end of my UI is a tooltip that ends up covering the whole div! I want it to display like the other div displays.
Here is the html for both
Working Version:
<div id="percentCompleteDiv"
class="container top-profile well text-center"
style="border-radius:3px;"
data-placement="right"
data-trigger="manual"
data-content="Displays the completion percentage
progress of the current upload"
data-original-title="Completion Percentage"
rel="popover">
<h4 style="color:#555;">Complete Pct:</h4>
<h3 id="uploadpercent">0%</h3>
</div>
Not-working version:
<div class="container text-center well"
data-placement="left"
data-trigger="manual"
data-content="Displays the current cost of this Job.
For more information on pricing see our pricing page"
data-original-title="Estimated Cost"
rel="popover">
How do I get it to display on the left properly?
I am using bootstrap (Twitter-Bootstrap 3) in a quiz style application and I use bootstrap buttons for the answers of the quiz. My problem is that sometimes the answers are quite long, and instead of wrapping the text to the width of the col that the buttons are placed in, the text just keeps going in one line and goes over the col and the width. Is there an easy way to fix this (Note that I canot define set widths as the length of the answers change)? Showing the code is a bit difficult, as it uses javascript to populate the answer buttons, but I will show a screen shot and the resulted populated HTML (after the javascript has populated the question and answers):
Here is the resulting HTML:
<div class="row">
<div style="float: none; margin: 0 auto;" class="col-sm-7">
<div class="panel panel-default">
<div class="panel-heading">Quiz 4 - This is the quiz 4 description</div>
<div class="panel-body" id="question" style="display: block;"><font color="#AAAAAA"><strong>Code: </strong>80559</font><br><br><font color="#888888"><strong>Instruction: </strong>Based on the provided correct answer, select the answer choice that correctly gives the required evidence from the text. Once the timer runs down you will be forced to move onto the next question.</font><br><br><div class="alert alert-info"><strong>Question: </strong>express a negative sentiment in humorous terms</div></div>
<div class="panel-footer clearfix">
<div class="row">
<div class="col-sm-1" id="submit"></div>
<div class="col-sm-11" id="answers" style="display: block;"><button onclick="submitAnswer(22)" class="btn btn-default btn-sm">negative sentiment: You couldn't pay me to watch that....that's how I feel / humorous terms: beach reading without the beach, airport reading without the airport...</button><br><br><button onclick="submitAnswer(23)" class="btn btn-default btn-sm">negative sentiment: they are just the wrong amount of time / humorous terms: they don't have the compressed energy of a short story</button><br><br></div>
</div>
</div>
</div>
</div>
I would think that bootstrap should be wrapping the button text within the div automatically, but it doesn't. I have been looking for solutions but I haven't been able to find anything that covers this problem particularly. Any help would be appreciated. I don't want to use <a href='#" ...> because it is important that the page not reload or be redirected when the button is pressed. Only the onclick function submitAnwers() should be called with no redirect.
The btn class in Bootstrap 3 contains 'white-space:no-wrap;', so the buttons will not wrap on mutliple lines. You can change this using a simple CSS override like:
.btn {
white-space: normal;
}
Demo: http://www.bootply.com/90082
This is an old question with an old answer. The answer solves the problem, but you can get ugly word breaks, where the button breaks in the middle of a word, seemingly wherever it wants to.
My answer forces the button to wrap between words, providing for a nice, clean, and responsive button.
.btn-responsive {
white-space: normal !important;
word-wrap: break-word;
}
Click Here
Hope it helps someone in the future.
I would like to create an HTML button that acts like a link to an item on the same page. So, when you click the button, it redirects to item on the same page.
How can I do this? (I would limit the solution to HTML, CSS, and JavaScript, because currently I am not using any other language)
Current Button (Bootstrap):
<a class="btn btn-large btn-primary" href="">Democracy</a>
Try:
<button onclick="window.location.href='location'">Button Name</button
This is assuming that you are not talking about scrolling down to a regular anchor, and instead you want to scroll to actual HTML elements on the page.
I'm not sure if jQuery counts for you, but if you're using Bootstrap, I imagine it does. If so, you can bind to the "click" event for your button and put some javascript code there to handle the scrolling. Typically you might associate the link/button with the element you want to scroll to using a "data" attribute (e.g. data-scroll="my-element-id").
Without jQuery, you'll have to make a function that contains the code as described, and put in an onclick attribute that references your function, and passes "this" as a parameter to your function, so you can get the reference to the link/button element that called it.
For the code to use to actually scroll to the corresponding element, check out this article:
How to go to a specific element on page?
Quick example without jQuery:
<a class="scrollbutton" data-scroll="#somethingonpage"
onchange="scrollto(this);">something on page</a>
<div id="somethingonpage">scrolls to here when you click on the link above</a>
<script type="text/javascript">
function scrollto(element) {
// get the element on the page related to the button
var scrollToId = element.getAttribute("data-scroll");
var scrollToElement = document.getElementById(scrollToId);
// make the page scroll down to where you want
// ...
}
</script>
With jQuery:
<a class="scrollbutton" data-scroll="#somethingonpage">something on page</a>
<div id="somethingonpage">scrolls to here when you click on the link above</a>
<script type="text/javascript">
$(".scrollbutton").click(function () {
// get the element on the page related to the button
var scrollToId = $(this).data("scroll");
var scrollToElement = document.getElementById(scrollToId);
// make the page scroll down to where you want
// ...
});
</script>
Note: If you literally want a "button" rather than a "link", you can really use any element and make that clickable, e.g.:
<button class="scrollbutton" data-scroll="#somethingonpage">something on page</button>
hey try this : -
<button>Click Me</button>
then to which ever place you want to go in your site : -
u may just place the line below wherever you want,
<a name="A"></a>
hope it works for you
Bookmark your item on the same page that you want to redirect to by assigning it an id. Assume id="itemId", then use<a class="btn btn-large btn-primary" href="#itemId">Democracy</a>. When you click the button, you will be redirected to the part of the page containing that item.
Read More
<section id="sectionA">
<p>You will be directed to this section. You can use id inside div/section/p tags etc</p>
</section>
which section or div using same id in <a href="?">
Democracy
div or section eg:
<section id="democracy">
your content
</section>
try this method abosolutly work
This is the easy way to do it
<button type="button""> Click </button>
try this following code :
<button>Click Over Here</button>
then to which ever place you want to go in your site u may just place the line below wherever you want :
<a name="Link"></a>
I'm making a webpage that's using bootstrap-modal.js from Twitter bootstrap
bootstrap-modal.js allows you to create "modals." You basically click a button and a little javascript window slides down where you can display different content etc. Here's a demo http://jsfiddle.net/mjmitche/xt4aQ/44/
I'm going to have several buttons/modals on my webpage, so I have to set it up so each button triggers a different modal. I assume that the best way to do this is to give them different classes or ids
Problem, if I change the ids given by bootstrap-modal.js, it changes the properties of the modals...For example, it may remove or add a black screen backdrop etc. The fiddle linked to above shows how the code below works.
Question: Do you know how I could differentiate the modals so that each button triggers a different modal but allow them all to have the same properties?
<div id="modal-from-dom" class="modal hide fade">
<div class="modal-header">
×
<h3>Modal Heading</h3>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
Primary
Secondary
</div>
</div>
Button
<button data-controls-modal="modal-from-dom" data-backdrop="true" data-keyboard="true" class="btn important">Launch left Modal</button>
You said you can't use id's so why not classes? try adding a different class to each modal. Here is your updated fiddle: http://jsfiddle.net/xt4aQ/52/
And I tried changing the id to number "2" and it works just fine. Just copy all the code and change the id by appending an ascending number.