CSS 样式不适用于按钮:如何删除单击时的蓝色突出显示?

问题描述 投票:0回答:1

我正在通过 pycharm 使用 html、css 和 js 开发一个 Web 应用程序。目前我遇到了上传按钮的问题,该按钮旨在触发源代码的上传。我仍在学习,但找不到解决方案。

当您单击并按住“上传”按钮时,它会表现出不需要的视觉行为,即变成蓝色。当然,我不必按住它,但即使点击一小会儿,也会出现蓝色。

上传按钮gif

这是我的CSS代码:

.btn-primary {
    background-color: #fc3e00;                       
    border: none;                                    
    border-radius: 5px;                              
    transition: background-color 0.3s ease, transform 0.2s ease; 
    color: white;                                    
    appearance: none;                                
}

.btn-primary:hover {
    background-color: #b80c09;                       
}

.btn-primary:focus {
    outline: none !important;                        
    box-shadow: none !important;                     
    background-color: #b80c09;                       
}

.btn-primary:active {
    background-color: #b80c09;                       
    transform: scale(0.95);                           
    box-shadow: none !important;                      
}

这是 HTML:

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap Link -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

    <!-- CSS Link -->
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

    <!-- Font Link -->
    <link href="https://fonts.googleapis.com/css?family=Roboto+Mono:100,100i,300,300i,400,400i,500,500i,700,700i"
          rel="stylesheet"/>
    <!-- Project Name -->
    <title>Viewie - Source Code Visualizer</title>
</head>
<body>
    <div class="container">
        <h1 class="text-center mt-4">Welcome to Viewie: A Code Source Visualizer!</h1>
        <h2 class="text-center mt-4">Input your Python, Javascript, or Java Code :D</h2>
        <form id="codeForm" class="mt-4">
            <div class="form-group">
                <textarea class="form-control" id="code" rows="10" placeholder="Please upload your source code :)"></textarea>
            </div>
            <button type="submit" class="btn btn-primary">Upload</button>
        </form>
        <div id="output" class="mt-4"></div>
        <div id="umlDisplay" class="mt-4"></div>
    </div>

    <script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>

我确实尝试将轮廓设置为“无”并将框阴影设置为“框阴影”,但这没有用。我在这里看到了针对移动设备的相同解决方案,但我还没有看到针对非移动设备的任何解决方案,除非我是盲人。我还刷新了页面和应用程序。我还尝试了不同的浏览器,因为我目前使用的是 Firefox。

html css button bootstrap-5
1个回答
0
投票

您还需要在 css 文件中的颜色中添加 !important 。所以按钮的外观将是正确的。

.btn-primary {
    background-color: #fc3e00 !important;                       
    border: none;                                    
    border-radius: 5px;                              
    transition: background-color 0.3s ease, transform 0.2s ease; 
    color: white;                                    
    appearance: none;                                
}

.btn-primary:hover {
    background-color: #b80c09 !important;                       
}

.btn-primary:focus {
    outline: none !important;                        
    box-shadow: none !important;                     
    background-color: #b80c09 !important;                       
}

.btn-primary:active {
    background-color: #b80c09 !important;                       
    transform: scale(0.95);                           
    box-shadow: none !important;                      
}
  <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap Link -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

    <!-- CSS Link -->
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

    <!-- Font Link -->
    <link href="https://fonts.googleapis.com/css?family=Roboto+Mono:100,100i,300,300i,400,400i,500,500i,700,700i"
          rel="stylesheet"/>
    <!-- Project Name -->
    <title>Viewie - Source Code Visualizer</title>
</head>
<body>
    <div class="container">
        <h1 class="text-center mt-4">Welcome to Viewie: A Code Source Visualizer!</h1>
        <h2 class="text-center mt-4">Input your Python, Javascript, or Java Code :D</h2>
        <form id="codeForm" class="mt-4">
            <div class="form-group">
                <textarea class="form-control" id="code" rows="10" placeholder="Please upload your source code :)"></textarea>
            </div>
            <button type="submit" class="btn btn-primary">Upload</button>
        </form>
        <div id="output" class="mt-4"></div>
        <div id="umlDisplay" class="mt-4"></div>
    </div>

    <script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>

© www.soinside.com 2019 - 2024. All rights reserved.