18910140161

HTML-使用填充对齐屏幕中心的两个按钮-堆栈溢出

顺晟科技

2022-10-18 13:30:57

72

我的代码中有两个按钮,我想知道如何使用CSS将它们移动到屏幕中心。我尝试使用 padding: 10px 24px 24px 30px;但它似乎没有将两个按钮放在屏幕中央。同时,我希望他们能有所回应。

以下是我的片段:

/* .btn-group button {   */
    .btn-group-vertical button { 
      background-color: #0b0e0d; /* Black background */
      border: 1px solid rgb(239, 240, 239); /*  border */
      color: white; /* White text */
      padding: 10px 24px 24px 30px; /* Some padding top right bottom left */
      cursor: pointer; /* Pointer/hand icon */
      width: 50%; /* Set a width if needed */
      display: block; /* Make the buttons appear below each other */
      font-weight: bold;
      font-size: 14px;
      text-transform: uppercase;
      margin-bottom: 50px;
    }
    
    .btn-group button:not(:last-child) {   
      border-bottom: none; /* Prevent double borders */
    }
    
    /* Add a background color on hover */
    /* .btn-group button:hover { */
    .btn-group-vertical button:hover {    
      background-color: #ffffff; 
      color: #0b6d11;
    }
<代码><;细分(>;)<;细分(>;)<;DIV类=“ btn-group-vertical ”>;<;button type=“ button ” ID=“ stbbutton ” ' ">;第一个按钮<;/button>;<;button type=“ button ” ID=“ cdbbutton ”>;第二个按钮<;/button>;<;/DIV>;<;/DIV>;<;/DIV>;


顺晟科技:

在容器中

使用<div > <div > <div class="btn-group-vertical"> <button type="button" id = "stbButton " '">First Button</button> <button type="button" id = "cdbButton" >Second Button</button> </div> </div> </div> ,然后将元素与中心对齐。将display:flex设置为flex-container将使元素相互堆叠。

将高度

设置为column将使容器填充视口的高度,并且您的内容将在其中垂直居中:

<代码>.btn-group-vertical{显示:Flex;align-items:居中;Justify-content:中心;Flex-Direction:列;高度:100VH;}/*.btn-group按钮{*/.btn-group-垂直按钮{背景色:#0b0e0d;/*黑色背景*/边框:1px实心RGB(239,240,239);/*边框*/颜色:白色;/*白色文本*/填充:10px 24px 24px 30px;/*右上左下一些填充*/游标:指针;/*指针/手形图标*/宽度:50%;最大宽度:300px;/*如果您喜欢,可以设置最大宽度*//*根据需要设置宽度*/显示:块;/*使按钮显示在彼此下方*/字体粗细:粗体;字体大小:14px;文本转换:大写;margin-bottom:50px;}.btn-group按钮:非(:最后一个子级){border-bottom:无;/*防止双重边框*/}/*悬停时添加背景颜色*//*.btn-group按钮:悬停{*/.btn-group-垂直按钮:悬停{背景色:#FFFFFF;颜色:#0B6D11;}
<代码><;DIV类=“ btn-group-vertical ”>;<;button type=“ button ” ID=“ stbbutton ”>;第一个按钮<;/button>;<;button type=“ button ” ID=“ cdbbutton ”>;第二个按钮<;/button>;<;/DIV>;

margin:auto添加到BTN-Group-Vertical类。它将被定位在中心,并且反应灵敏。

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航