简体   繁体   English

用 CSS 设计一个 inner.html

[英]Styling a inner.html with CSS

I have used have to change the wording of this CV whenever you click on a button.每当您单击一个按钮时,我都必须更改此 CV 的措辞。

 function myFunction(){ document.getElementById("demo").innerHTML= " ACERCA DE MI Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent id pellentesque orci. Duis vulputate est a nulla consectetur, vitae hendrerit purus malesuada. r"; } function myFunction2(){ document.getElementById("demo").innerHTML = " EXPERIENCIA Proin et tortor ut lorem finibus enter image description hereblandit. Etiam convallis, libero eu pellentesque semper, nibh mauris suscipit magna, vehicula vulputate nibh urna at urnas."; } function myFunction3(){ document.getElementById("demo").innerHTML = " ESTUDIOS Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent id pellentesque orci. Duis vulputate est a nulla consectetur, vitae hendrerit purus malesuada. Vestibulum am."; } function myFunction4(){ document.getElementById("demo").innerHTML = " HABILIDADES Proin et tortor ut lorem finibus blandit. Etiam convallis, libero eu pellentesque semper, nibh mauris suscipit magna, vehicula vulputate nibh urna at urna. Duis eget dolor eros."; }
 <div class="text-center"> <button class="button button1" type="button" onclick="myFunction()">ACERCA DE MI</button> <button class="button button2" type="button" onclick="myFunction2()">EXPERIENCIA </button> <button class="button button3" type="button" onclick="myFunction3()">ESTUDIOS </button> <button class="button button4" type="button" onclick="myFunction4()">HABILIDADES </button> </div> <p id="demo"><img class="bloque__icono" src="iconos/double.arrow.png" alt="arrow"> ACERCA DE MI Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent id pellentesque orci. Duis vulputate est a nulla consectetur, vitae hendrerit purus malesuada. Vestibulum euismod orci volutpat fringilla egestas. Etiam pellentesque orci sed risus rhoncus tempor. Cras molestie id turpis ac laoreet. Curabitur vel justo nunc. Maecenas eget ante tincidunt lorem fermentum dapibus non in quam. orem ipsum dolor </p>

How can I style the new text that appears with the click of the button?如何设置单击按钮后出现的新文本的样式? I have no idea how to link the inneHTML to CSS and be able to change the font, size and add space between sentences.我不知道如何将 inneHTML 链接到 CSS 并能够更改字体、大小和在句子之间添加空格。 Thank you!谢谢!

how it looks so far.到目前为止看起来如何。 I want to create paragraphs with the text我想用文本创建段落

I tried adding tags to the inner.html but that just breaks the link so far I just styled de我尝试将标签添加到 inner.html 但这只是打破链接到目前为止我只是设计了 de

tag in css to forcefully make it as it looks now but it is not enough to change it into paragraphs tag in css 强行改成现在的样子 但是改成段落是不行的

Be aware, that your code removed the image within <p> element too.请注意,您的代码也删除了<p>元素中的图像。

What you can do, is according to which button was clicked, add a different css class and define a style for it.您可以做的是,根据单击的按钮,添加不同的 css class 并为其定义样式。 Simplified, it would look something like this:简化后,它看起来像这样:

 <script> function myFunction() { let element = document.getElementById('demo'); element.classList = ['style1']; element.innerHTML = 'new red inner text'; } function myFunction2() { let element = document.getElementById('demo'); element.classList = ['style2']; element.innerHTML = 'new green inner text'; } </script> <style>.style1 { color: #FF0000; font-weight: bold; }.style2 { color: #00FF00; font-weight: bold; } </style> <div class="text-center"> <button class="button button1" type="button" onclick="myFunction()">Button 1</button> <button class="button button2" type="button" onclick="myFunction2()">Button 2</button> </div> <p><img class="bloque__icono" src="iconos/double.arrow.png" alt="arrow"> <span id="demo">Inner Text </span> </p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM