Link to an element within the current page [closed] - html

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I created a HTML page with a number of tables with headers like this: Content, Main_Page, Document, Expenses, etc.
I want to create a link for the top of the page. When I click that link it should go to the specific section. So I use the below code to map the content. But it's not working for me.
Content Section

You need to create an anchor for the link. The modern way of doing this is to give the appropriate element an id="Content" attribute. The older way of doing this was to use <a name="Content"></a>.

Give the element you want to 'jump' to a clear ID, like so:
<p id="idOfTag">Your content goes here</p>
Then in the link on the top of the page, make it refer to the id of that element (mind the #):
Jump
Full example with multiple links:
<ul>
<li>Content</li>
<li>Main page</li>
<li>Document</li>
<li>Expenses</li>
</ul>
<p id="contentParagraph">
<h4>Content</h4>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p id="mainPageParagraph">
<h4>Main page</h4>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p id="documentParagraph">
<h4>Document</h4>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p id="expensesParagraph">
<h4>Expenses</h4>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

You can use name attribute for your anchor tag to achieve this.
Let say you have a div with id content
<div id="content">This is my div</div>
Next make sure you have a anchor tag with name attribute same as the id of the div content
Click to go to the top
Live Demo.
Scroll down to see the link
Another approach to do this would be
<div id="content">My div</div>
Then your anchor tag's href should be #content
Click to go to top
Live Demo.

Looks like the question has been answered but if you wanted to use a scrolling effect when transitioning to those elements here a little JS snipt.
$(function() {
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');
// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
$('a[href*=#]').each(function() {
// Ensure it's a same-page link
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'') ) {
// Ensure target exists
var $target = $(this.hash), target = this.hash;
if (target) {
// Find location of target
var targetOffset = $target.offset().top;
$(this).click(function(event) {
// Prevent jump-down
event.preventDefault();
// Animate to target
$(scrollElem).animate({scrollTop: targetOffset}, 2000, function() {
// Set hash in URL after animation successful
location.hash = target;
});
});
}
}
});
// Use the first element that is "scrollable" (cross-browser fix?)
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$scrollElement = $(el);
if ($scrollElement.scrollTop()> 0) {
return el;
} else {
$scrollElement.scrollTop(1);
var isScrollable = $scrollElement.scrollTop()> 0;
$scrollElement.scrollTop(0);
if (isScrollable) {
return el;
}
}
}
return [];
}
});

Related

Extract link text and use as class of <a> for analytics reporting label

I am trying to extract the link text of multiple <a> tags within the_content(); of Wordpress posts, so I can use them as the class for each <a>. I have successfully extracted the link text and used addClass to classify them so we can clean up our outbound link reporting.
The problem is that it is putting each <a> link text as a long class for all <a>.
var linkText = $('.entry-content a').text();
$('.entry-content a').addClass(linkText);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="entry-content">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</div>
This code shows up in inspector shown below
Pass a callback function to .addClass() instead like:
$('.entry-content a').addClass(function() {
return $(this).text();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="entry-content">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</div>

Get rid of one-letter word at the end of each line

I'm looking for a HTML/CSS solution to get rid of one-letter words in each line in paragraph. In my home country there is grammar rule not to leave one-letter words but unfortunately I haven't found any CSS property to deal with it.
Example of incorrect paragraph:
My name is John Doe and I
look for a solution
Example of grammaticaly correct paragraph:
My name is John Doe and
I look for a solution'
I don't think that's possible with HTML and CSS. But if it must be done you can use <br/> to create it. Like this:
<p>
My name is John Doe and
<br/>
I look for a solution
</p>
Try Google next time. I found something similar as your question: How can I avoid one word on the last line with CSS?
Ok, so I did a little bit more reasearch and found that HTML allows for non-breaking space (&nbsp) so basically I had to insert "&nbsp" into HTML e.x. :
My name is John Doe and&nbspI look for a solution
To avoid inserting it manually into HTML (which is quite large) I wrote JS function for that:
function nbspInsert (sentence) {
let inputArray = sentence.split(" ");
let output = "";
for (let i = 0; i < inputArray.length; i++) {
if (i == inputArray.length) {
output += inputArray[i];
}
if (inputArray[i].length > 2) {
output += inputArray[i];
output += " ";
}
else {
output += inputArray[i];
output += "&nbsp";
}
}
return output;
}
Posting this answer to help anyone who will have same question in the future.
Cheers!
JavaScript Solution:
const setup = () => {
const pList = document.querySelectorAll('p');
pList.forEach(p => noMoreLonelyWords(p));
};
const clearWordBreaks = (target) => target.textContent = target.textContent.replace(/\u00a0/g, ' ');
const noMoreLonelyWords = (target) => {
let textArray = target.textContent.split(' ');
let newTextArray = [];
textArray.forEach((word, i, list) => {
let textEntry = '';
if(word.length === 1)
textEntry = word + '\xa0';
else
textEntry = word + ' ';
newTextArray.push(textEntry);
});
target.textContent = newTextArray.join('');
};
const updateWordBreaks = (target) => {
clearWordBreaks(target);
noMoreLonelyWords(target);
};
//load
window.addEventListener('load', setup);
<p>Lorem ipsum dolor sit amet, consectetur adipiscing I elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat I nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cill I um dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Good luck

How to expand a component to the bottom of the page and make it eventually scrollable?

I would like to expand a component's height until the bottom of the page is reached. Eventually, a scrollbar should appear inside it, depending on the content, but the page doesn't have to scroll, only the component itself should be scrollable.
The solution I found so far is the following:
<div style="height: 83vh; overflow-y: auto;">
<div class="container-fluid pt-3">
<div class="card-columns">
<div class="card" style="max-width:250px;" *ngFor="let myImg of imgList">
<img class="card-img-top" style="width:100%;" [src]="myImg">
</div>
</div>
</div>
</div>
Which is not the perfect solution, because that height: 83vh; may depend by the browser and work well only in my case. I then tried doing the following:
<div style="height: 100%; overflow-y: auto;">
but the div would overflow the web page, activating the page scroll and not the component scroll.
Any suggestion to achieve the behavior I want?
Maybe you can play around with the calc() function in CSS; you can take into account the full viewport height and substract the amount in px equal to other components in the screen, so that the component you want to fill the screen with only uses that remaining space.
If you test the snippet; the component uses enough space depending on the content inside, but if the content grows large enough to push the component to the bottom, instead of causing the whole page to scroll, it stays in place and only scrolls the content inside.
/* These styles are just for consistency */
body {
margin: 0;
}
body * {
box-sizing: border-box;
}
/*****************************************/
.top-bar {
height: 60px;
background-color: black;
}
section .component {
max-height: calc(100vh - 60px);
max-width: 900px;
margin: 0 auto;
border: 1px solid red;
overflow-y: auto;
}
<div class="top-bar">
</div>
<section>
<div class="component">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</section>
You mentioned in one of your comments that you're using Angular - you should update the question to include that and add it as a tag.
You can use window.innerHeight to get the pixel height of the current view.
If you have a singleton service in your Angular application where you're maintaining state, you can use a Behavior Subject to store that value so you can observe it in your components:
ie: state.service.ts
import { Observable, Subject, BehaviorSubject } from 'rxjs';
// Observable number sources
private currentWindowHeightStore = new BehaviorSubject<number>(0);
// Observable number streams
public currentWindowHeight$ = this.currentWindowHeightStore.asObservable();
// Service message commands
public setCurrentWindowHeight(WindowHeight: number) {
this.currentWindowHeightStore.next(WindowHeight);
}
Then in your component, define variables to store the windowSize, and if you're using pageable content (a list of items), a variable to store the pageSize:
private windowSize: number;
private pageSize: number;
In ngOnInit in your component, subscribe to the state.service Observable, and set the windowSize and pageSize based on the total window size, less any space required for navigation etc. (I've used sample values here, you'll want to set them according to your own layouts)
this.stateSvc.currentWindowHeight$
.subscribe(
(windowSize => {
this.windowSize = windowSize;
this.pageSize = Math.round((this.windowSize - 200) / 30) - 2;
this.cvPaging.pageSize = this.pageSize;
this.flex.refresh(true);
// 200 is the total size of the navigation header if you have one
// 30 is the size of a single row in the grid
// Total window size - minus total navigation / divided by the row height gives us the number of rows
// that will fit on the current screen size and we set the paging parameter to that value - 2 rows
}))
Now you have a windowSize variable that will update whenever the browser window changes size, and a pageSize variable that you can use if you're paging long lists to know how many items will fit in the window at it's current size.
You can use the windowSize variable to set the height of your container div with ngStyle:
<div [ngStyle]="{'height': 'auto','max-height':windowSize}>
Your content here.
</div>
The style property you are looking for is max-height. You can set this on your div and it will keep it from ever growing larger than that.
One trick for viewing this max-height in the event that you currently don't have enough content to fill it to maximum is to set the height equal to the max-height (temporarily) and to also temporarily give yourself a border on the div. This will allow you to visualize just how big that div can get.
EDIT: Different approach... (With fiddle example):
html, body {
height: 100%;
overflow: hidden;
}
Then, make the height of your main div a percentage, 100% will make it absolutely to the bottom, you may not like the look of this so try 95%, add overflow: auto; to get a scrollbar whenever the height is greater than the container it is in.
See Fiddle Example

Provide border if div has overflow text

What would be the best way to implement a design that want div-containers be provides with a border, if the content of the div causes vertical scroll of the div?
CSS
div {
max-height: 100px;
overflow-y: auto;
// if content exceeds 100 px show border
border: solid 1px;
}
HTML
<div>
// Text ..
</div>
Set border if overflow.
var div = document.querySelector('div');
if (div.scrollHeight > div.clientHeight) {
div.style.border = '1px solid';
}
div {
max-height: 100px;
overflow-y: auto;
}
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
I am assuming there is some kind of event that changes or determines the content of that div.
In my humble opinion, you can not achieve that using html/css alone. You would have to use JavaScript.
https://jsfiddle.net/4u2Lurt3/
Here is a simple example of how to do that. You may need to "re-wire" a bit differently to get the exact behavior you wanted
<div id="myDiv">
Hello
</div>
<button onclick="addText()">
Click to change div
</button>
And
function checkWidth() {
var div = document.getElementById('myDiv');
if(div.offsetWidth > 100) {
div.style.border = "1px solid black"
}
}
function addText() {
var div = document.getElementById('myDiv');
div.style.width="250px";
div.innerText = "AAAAAAAAAAAAA VVVVVVEERRRRY LOOOONNNNGGG TEEEEEXXXXXTT";
checkWidth();
}

CSS hover + div not working

So, disclaimer, I'm about 2 days into learning HTML and CSS. I thought it would be a cool project to transform my resume into a website. However, I've run into some snags when designing the experience page. In theory, I'd want to hover over an which would then display some text contained in a div. The hovering part works if I just use :hover instead of #att1:hover, but if I do that I can't have multiple objects. Hope that made sense.
I've attempted creating a div for each and simply making the a div, but since the elements are being placed inside of timeline I was unable to get the formatting on the page correct.
On a side note, once this is fixed, is there any way to have hover apply only to the image, and not to any associated margin/padding?
Here's what I've got:
#job1
{
display: none;
}
#job2
{
display: none;
}
#att1:hover + #job1
{
display: block;
}
#att2:hover + #job2
{
display: block;
}
<div class = "timeline">
<div id = "line"></div>
<a id = "att1" href = "#"><img id = "scintern" src = "https://www.santandercareers.com/content/themes/scusa-careers/assets/images/bemore.png" alt = "Santander Logo"></a>
<a id = "att2" href = "#"><img id = "scdss" src = "https://www.santandercareers.com/content/themes/scusa-careers/assets/images/bemore.png" alt = "Santander Logo"></a>
</div>
<div class = "textbox" id = "job1">
<p class = "header">Santander Consumer USA, Inc.</p>
<p class = "body">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
<div class = "textbox" id = "job2">
<p class = "header">Santander Consumer USA, Inc. 2</p>
<p class = "body">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
ps. I promise I've researched for about 4 hours now. However, perhaps I'm not looking in the right places since this is so new to me.
Can be done if you change the html a bit. Put the .textbox divs to come after the anchors. Then use ~ to target siblings. The + is for direct sibling (if it comes right after).
#job1 {
display: none;
}
#job2 {
display: none;
}
#att1:hover ~ #job1 {
display: block;
}
#att2:hover ~ #job2 {
display: block;
}
<div class="timeline">
<div id="line"></div>
<a id="att1" href="#">
<img id="scintern" src="https://www.santandercareers.com/content/themes/scusa-careers/assets/images/bemore.png" alt="Santander Logo">
</a>
<a id="att2" href="#">
<img id="scdss" src="https://www.santandercareers.com/content/themes/scusa-careers/assets/images/bemore.png" alt="Santander Logo">
</a>
<div class="textbox" id="job1">
<p class="header">Santander Consumer USA, Inc.</p>
<p class="body">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
<div class="textbox" id="job2">
<p class="header">Santander Consumer USA, Inc. 2</p>
<p class="body">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
</div>
The CSS selector you are using at the moment + is called an adjacent sibling selector. It will select any element immediately follows the element. That doesn't suit your needs. You better of doing this with a little bit of JavaScript. What you will do is check for mouseenter and mouseleave eventes on your images, and then handle the text accordingly. Below is an implementation with jQuery, an easy to install JavaScript library.
To only detect hover on the images, don't apply margin to the image, but only padding to the surrounding links.
To install jQuery in your page, simply put the following tag in your head:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
The JavaScript is inserted using another script-tag following the jQuery tag, like this:
<script>
Your code here...
</script>
And here goes the snippet:
$("#scintern").mouseover(function() {
$("#job1").show();
});
$("#scintern").mouseleave(function() {
$("#job1").hide();
});
$("#scdss").mouseover(function() {
$("#job2").show();
});
$("#scdss").mouseleave(function() {
$("#job2").hide();
});
#att1, #att2 {
text-decoration: none;
}
#job1 {
display: none;
}
#job2 {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="timeline">
<div id="line"></div>
<a href="#" id="att1">
<img alt="Santander Logo" id="scintern" src="https://www.santandercareers.com/content/themes/scusa-careers/assets/images/bemore.png">
</a>
<a href="#" id="att2">
<img alt="Santander Logo" id="scdss" src="https://www.santandercareers.com/content/themes/scusa-careers/assets/images/bemore.png">
</a>
</div>
<div class="textbox" id="job1">
<p class="header">Santander Consumer USA, Inc.</p>
<p class="body">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
<div class="textbox" id="job2">
<p class="header">Santander Consumer USA, Inc. 2</p>
<p class="body">"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>