javascript - 如何添加设定的边框半径?

标签 javascript css

我在网上浏览了一下,看到一篇关于每次刷新页面时都会更改 img 和引用的帖子,并且它处于堆栈溢出状态 这是代码,归功于原始开发人员,但我只想知道在哪里可以添加类 img-circle ,以便它可以在 css 中工作以具有图像的圆形边框,抱歉这是我的第一篇文章在 Stackoverflow 中

(function() {
  var quotes = [
    {
      text: "text1",
      img:  "/image/FqBE6.jpg?s=32&g=1"
    },
    {
      text: "text2",
      img:  "https://www.gravatar.com/avatar/ca3e484c121268e4c8302616b2395eb9?s=32&d=identicon&r=PG",
    }
  ];
  var quote = quotes[Math.floor(Math.random() * quotes.length)];
  document.getElementById("quote").innerHTML =
    '<p>' + quote.text + '</p>' +
    '<img src="' + quote.img + '">';
})();

最佳答案

只需将其添加到 img 代码中即可:

'<img class="img-circle" src="' + quote.img + '">';

完整代码:

(function() {
  var quotes = [
    {
      text: "text1",
      img:  "/image/FqBE6.jpg?s=32&g=1"
    },
    {
      text: "text2",
      img:  "https://www.gravatar.com/avatar/ca3e484c121268e4c8302616b2395eb9?s=32&d=identicon&r=PG",
    }
  ];
  var quote = quotes[Math.floor(Math.random() * quotes.length)];

  document.getElementById("quote").innerHTML =
    '<p>' + quote.text + '</p>' +
    '<img class="img-circle" src="' + quote.img + '">';
})();

希望这有帮助。

(function() {
  var quotes = [
    {
      text: "text1",
      img:  "/image/FqBE6.jpg?s=32&g=1"
    },
    {
      text: "text2",
      img:  "https://www.gravatar.com/avatar/ca3e484c121268e4c8302616b2395eb9?s=32&d=identicon&r=PG",
    }
  ];
  var quote = quotes[Math.floor(Math.random() * quotes.length)];

  document.getElementById("quote").innerHTML =
    '<p>' + quote.text + '</p>' +
    '<img class="img-circle" src="' + quote.img + '">';
})();
.img-circle{
  border-radius: 50%;
}
<div id="quote"></div>

关于javascript - 如何添加设定的边框半径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40873624/

相关文章:

javascript - 为什么 Mongoose 插入 null 作为子文档数组的最后一个元素?

html - ul li 垂直多行 - 位置错误

css - 为什么不能将带有供应商前缀的选择器放在同一行?

javascript - 提交表单时忽略基本 href,不使用 Javascript

javascript - 根据子域为特定客户设计网站样式

javascript - 如何获得透明元素后面的颜色?

javascript - 在 Angular 9 中创建具有动态 styleUrls 的组件

带有边距和垂直对齐的左右文本的 CSS Div

html - 使 <marquee> 成为屏幕宽度

html - 段落省略号逻辑,P末尾的省略号如何显示