HTML Anchors not working inside divs with overflow:scroll? - html

I wrapped all contents with <div> which height and width is both 100px. Contents inside this <div> contains index and content.
The problem is that clicking "a2" in the following code won't let me jump to the bottom contents in Google Chrome.
<div style="height:100px;width:100px;overflow:scroll;">
<ul>
<li>a1</li>
<li>a2</li>
</ul>
<h2 id="a1">a1</h2>
a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>
<h2 id="a1">a2</h2>
a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>
</div>
The working code can be seen from the following link.
http://jsfiddle.net/L7rQ6/
Is there some good solution to make "a2" jump to the proper contents?

You missing to update your 2nd <h2> element set id="a2" instead of id="a1"
Check demo jsfiddle
Update this small,
<h2 id="a2">a2</h2>
HTML (Updated)
<div style="height:100px;width:100px;overflow:scroll;">
<ul>
<li>a1</li>
<li>a2</li>
</ul>
<h2 id="a1">a1</h2>
a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>
<h2 id="a2">a2</h2>
a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>
</div>

You need to use:
<h2 id="a2">
instead of:
<h2 id="a1">
for your second h2 element. Current you've duplicated id which is invalid HTML as well.
Updated Fiddle

As Felix and user1153551 has said you have duplicated the Id for both of the tags try this.
<div style="height:100px;width:100px;overflow:scroll;">
<ul>
<li>a1</li>
<li>a2</li>
</ul>
<h2 id="a1">a1</h2>
a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>a1<br/>
<h2 id="a2">a2</h2>
a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>a2<br/>
</div>

Related

Timeline - overlap text?

I have created timeline, but i have problem with overlap text.
https://jsfiddle.net/Lkn8qda0/1/
<div class="container">
<div class="item">
<div id="timeline">
<div>
<section class="year" *ngFor="let d of data">
<h3>PARTIALLY ACCEPTED/REJECTED</h3>
<section>
<ul>
<li>20.01.2020}</li>
</ul>
</section>
</section>
</div>
</div>
</div>
</div>
This is my fiddle,but i dont know how to fix problem when text is longer.
Any suggestion?
You can use white-space: wrap; to avoid breaks in the middle of words, see this older discussion. But this will treat "ACCEPTED/REJECTED" as one word, so you would probably want to add whitespace characters there, like "ACCEPTED / REJECTED".
This article has an extensive explanation of text wrapping possibilities and strategies in CSS.

CSS can't check for focus

I have the following code in html:
<nav class="box">
<div class="logo">
<button class="c-hamburger c-hamburger--htx linksbuendig">
<span>toggle menu</span>
</button>(...)
</div>
</nav>
<div class="relative box">
<div class="nav">
<ul>
<li>
Login
</li>
</ul>
</div>
and this in CSS:
.c-hamburger:focus ~ div.nav {
margin:0;}
so if the button is focused the div should change the margin. But it won't work, until i copy the code for the button 1 to 1 directly over the div with the class nav. Why does it so and what can I change? Just copy solves the problem until now, but then is the full page destroyed, because there're other elements in between etc.
JS or sth. like that is not allowed. Please only CSS resp HTML.
Beforehand: Thanks!

nth-child, change style of every other div with class name

I have got some elements on my page, they should all be styled the same except for every other one, where I just want to change some styling.
Here is the CSS which I was hoping would select the div inside the stack of different elements:
.stagger_reviews[class=inner]:nth-child(2n+2) {
background-color:#003;
}
Here is the HTML:
<div class="stagger_reviews">
<!-- Later use PHP to load reviews, CSS should switch the images from left to right -->
<article class="container box style1">
<a style="background-image:url(images/blank-user.jpg); " href="#" class="image fit"></a>
<div class="inner">
<header>
<h2>Martyn Ball</h2>
</header>
<p>
I found this service on a Google Search, didn't expect it to be so great!
</p>
</div>
</article>
<article class="container box style1">
<a style="background-image:url(images/blank-user.jpg); " href="#" class="image fit"></a>
<div class="inner">
<header>
<h2>Martyn Ball</h2>
</header>
<p>
I found this service on a Google Search, didn't expect it to be so great!
</p>
</div>
</article>
</div>
As you can see I just want to adjust the one div inside each article which has the class name inner. And maybe some other elements as well but once I have this working I can do that.
The style isn't being applied to the second inner div, I have made about 4 copies of the article and none are being changed.
Here is the solution, I put the nth-child in the wrong place.
.stagger_reviews > article:nth-child(2n+2) div[class=inner]

How to show/hide divs

I am trying to figure out how to do this... I have 4 divs that I am looking to show and hide one at a time. The link to the divs are in a separate nested div. Here's my code:
<div id="container">
<div class="roundbox">
<ul>
<li class="t">
Main
</li>
<li class="e">
News
</li>
<li class="t">
History
</li>
<li class="e">
Contact
</li>
</ul>
</div>
<div class="inceptioncontent">
<div class="content">
<div class="contentnest">
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id="4"></div>
</div>
</div>
</div>
</div>
I want the Main, News, Contact, and History links to show/hide the corresponding divs in the contentnest div. Any ideas? Thanks!
JQuery is great at doing his sort of thing. This looks like a good place to start: http://papermashup.com/simple-jquery-showhide-div/
It seems your looking for a drop down menu. You can achieve this:
Coding it in Javascript + css ( with a framework like jQuery it will be easier)
; With Css
; Downloading A plugin
I think the "Css only" is the best way, jQuery is cool and download a plugin it's the easiest way, but you need the js of the user's explorer to be on.
You can check how to do it only with css here:
https://www.grc.com/menudemo.htm

DIV to trigger a Radio Button

I'm struggling to get my "event" div to trigger the allocated radio button.
<section class="main">
<ul class="timeline">
<li class="event">
<input type="radio" name="tl-group"/>
<label></label>
<div class="thumb user-3">title</div>
<div class="content-perspective">
<div class="content">
<div class="content-inner">
<h3>Title</h3>
<p>TEXT</p>
</div>
</div>
</div>
</li>
<li class="event">
...
</li>
</ul>
I want <div class="thumb user-3">title</div> to work as a radio button as well. I want both to be clickable. I've tried different ideas but doesn't seems to work.
Many thanks.
You can set the checked attribute of radio to value "checked" when clicked the div.
<div class="thumb user-3" onclick="document.getElementsByName('tl-group').checked='checked';">title</div>
I have been searching for the same piece of code as well. It worked! Saved my day.
div class="thumb user-3" onclick="document.getElementsByName('tl-group')[0].checked='‌​checked';"
For those who are looking into refining the existing code by clicking barely anywhere (radio button, img div or ...the content-inner to trigger event), this is the code that works for me:
div class="content-inner" onclick="document.getElementsByName('tl-group')[0].checked='checked';"
Increase the [0] to 1,2,3, etc for more contents array.