html - CSS 类将应用于不同的 div 元素和不同的按钮元素

标签 html css

我正在做一个元素,我有一个包含 3 个按钮的页面。 第一个按钮是按钮标签,另外两个是 div 标签。 我对这两个 div 使用了一个类,使它们看起来像我的按钮标签。 问题是我为按钮标签和带有类的 div 编写了相同的 CSS 规则,但正如您从下面的照片中看到的那样,它们并不相同。

Problem with div and button class

这是我的代码: HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Δομημένος προγραμματισμός</title>
    <meta charset="utf-8"/>
</head>
<body>
<button onclick="exercise()">Click me</button>
<div class="button" onclick="klimakoti()">Klimakoti xreosi</div>
<div class="button" onclick="hw()">Height and weight</div>
</body>
</html>

CSS:

button{
    border: 0px;
        padding: 15px;
        font-size: 18px;
        color: green;
        font-style: italic;
        border-radius: 6px;
        border-left:4px dashed #f22aa9;
 }
     .button{
        border: 0px;
        padding: 15px;
        font-size: 18px;
        color: green;
        font-style: italic;
        border-radius: 6px;
        border-left:4px dashed #f22aa9;
    }

请帮帮我!!!

最佳答案

您必须应用背景色来覆盖浏览器默认值:

button, .button {
    border: 0px;
    padding: 15px;
    font-size: 18px;
    color: green;
    font-style: italic;
    border-radius: 6px;
    border-left:4px dashed #f22aa9;
    background-color: transparent;

 }

编辑 — 如果您想要 <div>元素看起来像按钮,而不是相反,你必须做一些其他的事情:

button, .button {
    border: 0px;
    padding: 15px;
    font-size: 18px;
    color: green;
    font-style: italic;
    font-family: sans-serif;
    border-radius: 6px;
    border-left:4px dashed #f22aa9;
    background-color: #ddd;
    margin: 0;
    display: inline-block;
 }

我已确保字体系列相同,并且它们显示为内联元素。

关于html - CSS 类将应用于不同的 div 元素和不同的按钮元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26061401/

相关文章:

javascript表单文本框post js和html

css - 如何在 GWT 的 UiBinder 中将样式名称 "Multiple css classes"添加到 1 个元素中?

html - 导航上的 CSS 样式问题

python - 使用样式使用 Pandas 样式为单个单元格着色

css - 如何通过css实现颜色由深到浅?

html - H1 元素上的边距

javascript - 发帖前如何编辑POST数据?

javascript - MDL - 单击时将 + 图标更改为 - ?

javascript - 使用 Electron 时出错 `app.getPath(' home');`

html - 像图像一样排列 div?