I have a doubt, I think it's even simple. I have a table that receives data from a JSON, each row of that table is a JSON field. On each line I added two buttons (Like/Dislike) to check the search quality. However, when I click on the like, for example, and I click on the like of the second line, it does not keep the like of the first line selected.
The method should work like this, after returning the data, the user will go through line by line evaluating the search, choosing between like or dislike. After that, we will take this assessment and save it.
However, it is not keeping the evaluation option selected in each line.
The code already has integration with VUE
Follow File HTML
<template>
<div v-for="regList in myJson" :key="regList" class="container" >
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<table>
<thead>
<tr>
<th>Documento</th>
<th colspan="2">Avalie a Busca</th>
</tr>
</thead>
<tbody>
<tr v-for="countryList in regList[2]" :key="countryList">
<td style="visibility: visible">
{{countryList}}
</td>
<td>
<button class="btn btn-1" type="button"><i class="fa fa-thumbs-up"></i></button>
</td>
<td>
<button class="btn btn-2" type="button"><i class="fa fa-thumbs-down"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</template>
EDIT 1
Nikola Pavicevic's solution seems to be adequate, but I needed to detail my code a little more. I have a Vue file running the code. The project is for the user to type a term, send it to the backend, which will return a Json, with an autocomplete phrase and also information from another API. In the frontend I separate this sentence from the rest of the JSON and present the autocomplete with the JSON inside the Table. The data I show in the table is just a description. I'll also leave a model of how the JSON goes to the table.
Part. Vue:
<script>
export default {
name: 'Autocomplete',
data: function() {
return {
autoComplete: "",
maxChars: 75,
connection: null,
myJson: []
}
},
mounted() {
const url = "ws://localhost:8000/"
this.connection = new WebSocket(url);
this.connection.onopen = () => console.log("connection established");
this.connection.onmessage = this.receiveText;
},
methods: {
sendText() {
const inputText = this.$refs.editbar.textContent;
this.connection.send(inputText);
},
receiveText(event) {
let result = JSON.parse(event.data)
this.autoComplete = result.shift();
this.myJson = result
}
}
}
</script>
Return Json in table:
[
{
"1": 0.471,
"2": {
"82": "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."
}
},
{
"1": 0.47,
"2": {
"686": "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."
}
}
]
EDIT 2 - Problem Soluction OK
Following Nikola's instructions, I ended up solving the problems. I just had to adjust to my situation. Follow code:
The ForEach I had to leave inside the Receive Text, as it is the place where my JSON is supplied with information
receiveText(event) {
let result = JSON.parse(event.data)
this.autoComplete = result.shift();
this.myJson = result
this.selected = []
this.myJson.forEach((m, i) => {return this.selected.push({i: i, state: null})})
}
For the rest, I followed the same guidelines as Nikola, just adjusting the code I already had and implementing the suggestions.
If I understood you correctly maybe like following snippet:
const app = Vue.createApp({
data() {
return {
myJson: [{"1": 0.471, "2": {"82": "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."}}, {"1": 0.47, "2": {"686": "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."}}],
selected: []
};
},
mounted() {
this.myJson.forEach((m, i) => {
return this.selected.push({i: i, state: null})
})
},
methods: {
setState(idx, state) {
this.selected[idx].state = state
}
}
})
app.mount('#demo')
.active {
background: gold !important;
}
.btn {
border-radius: 4px;
border: none;
padding: .5em 1em;
cursor: pointer;
}
.btn-1 {
background: lime;
}
.btn-2 {
background: crimson;
}
.btn:hover {
background: gold;
}
.fa {
color: white;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://unpkg.com/vue#3/dist/vue.global.prod.js"></script>
<div id="demo">
<div v-for="(regList, idx) in myJson" :key="regList" class="container" >
<table>
<thead>
<tr>
<th>Documento</th>
<th colspan="2">Avalie a Busca</th>
</tr>
</thead>
<tbody>
<tr v-for="countryList in regList[2]" :key="countryList">
<td style="visibility: visible">
{{countryList}}
</td>
<td>
<button #click="setState(idx, true)" class="btn btn-1" :class="selected[idx]?.state && 'active'">
<i class="fa fa-thumbs-up"></i>
</button>
</td>
<td>
<button #click="setState(idx, false)" class="btn btn-2" :class="selected[idx]?.state === false && 'active'">
<i class="fa fa-thumbs-down"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
{{selected}}
</div>
Related
I need to take the (html) section from each page in the array (0, 1) how would I go about doing this? The API call worked perfectly fine, just need to take the main html data and display it on the webpage where the placeholders {welcome.text} and {about.text} are.
Thanks for any help.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CMS Test</title>
</head>
<body>
<header>
<h1>CMS Test</h1>
<nav>
Home
About
Posts
Contact
</nav>
</header>
<section id="Home">
<div class="container">
<h2>Welcome to website</h2>
{welcome.text}
</div>
</section>
<section id="About">
<div class="container">
<h2>About Section</h2>
{about.text}
</div>
</section>
<section id="Posts">
<div class="container">
<h2>Posts Section</h2>
{posts.list}
</div>
</section>
<section id="Contact">
<div class="container">
<h2>Contact Section</h2>
<p>contact on: email#provider.com</p>
</div>
</section>
<script>
fetch('http://68.183.219.114/ghost/api/v3/content/pages/?key=276f4fc58131dfcf7a268514e5')
.then(response => response.json())
.then(data => console.log(data));
</script>
</body>
</html>
JSON response after fetching from that URL.
{
"pages": [
{
"id": "5efb6bbeeab44526aecc0abb",
"uuid": "38b78123-e5a8-4346-8f6e-6f57a1a284d0",
"title": "About Section",
"slug": "about-section",
"html": "<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>",
"comment_id": "5efb6bbeeab44526aecc0abb",
"feature_image": null,
"featured": false,
"visibility": "public",
"created_at": "2020-06-30T16:43:42.000+00:00",
"updated_at": "2020-06-30T16:58:53.000+00:00",
"published_at": "2020-06-30T16:58:37.000+00:00",
"custom_excerpt": null,
"codeinjection_head": null,
"codeinjection_foot": null,
"custom_template": null,
"canonical_url": null,
"url": "http://68.183.219.114/about-section/",
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\nincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis\nnostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu\nfugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\nculpa qui officia deserunt mollit anim id est laborum.",
"reading_time": 0,
"page": true,
"og_image": null,
"og_title": null,
"og_description": null,
"twitter_image": null,
"twitter_title": null,
"twitter_description": null,
"meta_title": null,
"meta_description": null
},
{
"id": "5efb6f53eab44526aecc0ac4",
"uuid": "26463d5f-011e-46b3-a1e2-60e213e33f6f",
"title": "Welcome",
"slug": "welcome",
"html": "<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>",
"comment_id": "5efb6f53eab44526aecc0ac4",
"feature_image": null,
"featured": false,
"visibility": "public",
"created_at": "2020-06-30T16:58:59.000+00:00",
"updated_at": "2020-06-30T16:59:02.000+00:00",
"published_at": "2020-06-30T16:59:02.000+00:00",
"custom_excerpt": null,
"codeinjection_head": null,
"codeinjection_foot": null,
"custom_template": null,
"canonical_url": null,
"url": "http://68.183.219.114/welcome/",
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\nincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis\nnostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu\nfugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\nculpa qui officia deserunt mollit anim id est laborum.",
"reading_time": 0,
"page": true,
"og_image": null,
"og_title": null,
"og_description": null,
"twitter_image": null,
"twitter_title": null,
"twitter_description": null,
"meta_title": null,
"meta_description": null
}
],
"meta": {
"pagination": {
"page": 1,
"limit": 15,
"pages": 1,
"total": 2,
"next": null,
"prev": null
}
}
}
Change the {[identifier]} with a span or a container tag element and assign an unique id to it (in the example I am using a span tag).
When the DOM is loaded create a variable for each container tag identified by the id (or query selector, you have many possibilities).
When the fetch operation succeded (I am using a test REST endpoint), extract the data and "populate" the container tag (assigned before) with the fetched data.
Here is a working example:
// FAKE DATA
const FAKE_DATA = JSON.parse(`{"pages":[{"id":"5efb6bbeeab44526aecc0abb","uuid":"38b78123-e5a8-4346-8f6e-6f57a1a284d0","title":"About Section","slug":"about-section","html":"<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>","comment_id":"5efb6bbeeab44526aecc0abb","feature_image":null,"featured":false,"visibility":"public","created_at":"2020-06-30T16:43:42.000+00:00","updated_at":"2020-06-30T16:58:53.000+00:00","published_at":"2020-06-30T16:58:37.000+00:00","custom_excerpt":null,"codeinjection_head":null,"custom_template":null,"canonical_url":null,"url":"http://68.183.219.114/about-section/","excerpt":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod temporincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quisnostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eufugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt inculpa qui officia deserunt mollit anim id est laborum.","reading_time":0,"page":true,"og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null},{"id":"5efb6f53eab44526aecc0ac4","uuid":"26463d5f-011e-46b3-a1e2-60e213e33f6f","title":"Welcome","slug":"welcome","html":"<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>","comment_id":"5efb6f53eab44526aecc0ac4","feature_image":null,"featured":false,"visibility":"public","created_at":"2020-06-30T16:58:59.000+00:00","updated_at":"2020-06-30T16:59:02.000+00:00","published_at":"2020-06-30T16:59:02.000+00:00","custom_excerpt":null,"codeinjection_head":null,"custom_template":null,"canonical_url":null,"url":"http://68.183.219.114/welcome/","excerpt":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod temporincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quisnostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eufugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt inculpa qui officia deserunt mollit anim id est laborum.","reading_time":0,"page":true,"og_image":null,"og_title":null,"og_description":null,"twitter_image":null,"twitter_title":null,"twitter_description":null,"meta_title":null,"meta_description":null}],"meta":{"pagination":{"page":1,"limit":15,"pages":1,"total":2,"next":null,"prev":null}}}`);
// Fetch url, change with http://68.183.219.114/ghost/api/v3/content/pages/?key=276f4fc58131dfcf7a268514e5
const FETCH_URL = "https://reqres.in/api/users?page=2";
// Data page index 1
const PAGE_1_INDEX = 0;
// Data page index 2
const PAGE_2_INDEX = 1;
window.addEventListener('DOMContentLoaded', (event) => {
const txtWelcome = document.getElementById("txtWelcome");
const txtAbout = document.getElementById("txtAbout");
const listPost = document.getElementById("listPost");
fetch(FETCH_URL)
.then(response => response.json())
.then(data => {
// Assign page 1
const page1 = FAKE_DATA.pages[PAGE_1_INDEX];
// Assign page 2
const page2 = FAKE_DATA.pages[PAGE_2_INDEX];
// START populating for example with page 2
txtWelcome.innerHTML = page2.title; // Example
txtAbout.innerHTML = page2.slug; // Example
listPost.innerHTML = page2.html; // Here you can add the HTML as above
// END Populating
});
});
p:first-child {
font-weight: bold;
font-size: 2em;
text-decoration: underline;
color: red;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CMS Test</title>
</head>
<body>
<header>
<h1>CMS Test</h1>
<nav>
Home
About
Posts
Contact
</nav>
</header>
<section id="Home">
<div class="container">
<h2>Welcome to website</h2>
<span id="txtWelcome">Loading...</span>
</div>
</section>
<section id="About">
<div class="container">
<h2>About Section</h2>
<span id="txtAbout">Loading...</span>
</div>
</section>
<section id="Posts">
<div class="container">
<h2>Posts Section</h2>
<span id="listPost">Loading...</span>
</div>
</section>
<section id="Contact">
<div class="container">
<h2>Contact Section</h2>
<p>contact on: email#provider.com</p>
</div>
</section>
</body>
</html>
Hope it helps :)
I'm trying to make multilingual website with redux, I have followed this tutorial > http://www.bebetterdeveloper.com/coding/getting-started-react-redux.html and adapt it to my project however I have a problem. I put my whole content inside json file. The thing is I wish to make some particular words bolded. Is it possible to add html tags inside the Json content? I found some way in the google but it doesn't work... Will be glad for any suggestions, That's my code:
[
{
"lang": "en",
"page": {
"menu": {
"home": "Home",
"brand": "Brand",
"contact": "Contact"
},
"home": {
"header": "Lorem Ipsum",
"paragraphOne": "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
"paragraphTwo": "Lorem <span className=\"bold-me\"> ipsum <\/span> 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."
}
}
}
}
]
You can use dangerouslySetInnerHTML if you want to parse the HTML in a string. You could then style the bold-me class to have bolder text, or simply use the b tag.
Example
const content = [
{
lang: "en",
page: {
menu: {
home: "Home",
brand: "Brand",
contact: "Contact"
},
home: {
header: "Lorem Ipsum",
paragraphOne:
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
paragraphTwo:
"Lorem <b> ipsum </b> 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."
}
}
}
];
function App() {
return (
<div
dangerouslySetInnerHTML={{ __html: content[0].page.home.paragraphTwo }}
/>
);
}
ReactDOM.render(<App />, document.getElementById("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>
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();
}
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>
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 [];
}
});