簡體   English   中英

如何在此代碼中僅使用 CSS 垂直對齊 html 單選按鈕?

[英]How to vertically align html radio buttons with CSS-only in this code?

我發現這個很酷的CSS-只有縮略圖我的應用程序幻燈片這里 我一直在嘗試使用代碼在右側垂直對齊縮略圖而不是在底部水平對齊,但沒有成功......

大圖需要640px(x)640px:

    /*Time for the CSS*/
* {margin: 0; padding: 0;}
body {background: #ccc;}

.slider{
    width: 640px; /*Same as width of the large image*/
    position: relative;
    /*Instead of height we will use padding*/
    padding-top: 640px; /*That helps bring the labels down*/

    margin: 100px auto;

    /*Lets add a shadow*/
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
}


/*Last thing remaining is to add transitions*/
.slider>img{
    position: absolute;
    left: 0; top: 0;
    transition: all 0.5s;
}

.slider input[name='slide_switch'] {
    display: none;
}

.slider label {
    /*Lets add some spacing for the thumbnails*/
    margin: 18px 0 0 18px;
    border: 3px solid #999;

    float: left;
    cursor: pointer;
    transition: all 0.5s;

    /*Default style = low opacity*/
    opacity: 0.6;
}

.slider label img{
    display: block;
}

/*Time to add the click effects*/
.slider input[name='slide_switch']:checked+label {
    border-color: #666;
    opacity: 1;
}
/*Clicking any thumbnail now should change its opacity(style)*/
/*Time to work on the main images*/
.slider input[name='slide_switch'] ~ img {
    opacity: 0;
    transform: scale(1.1);
}
/*That hides all main images at a 110% size
On click the images will be displayed at normal size to complete the effect
*/
.slider input[name='slide_switch']:checked+label+img {
    opacity: 1;
    transform: scale(1);
}

要使它們垂直對齊,請刪除.slider label float:left; . 您將需要使用邊框和定位 CSS,但這應該很簡單。 希望這有幫助。

我在 Chrome 中修改了一些元素以獲得請求的視圖。 只需修改以下 CSS,您將在左側看到單選滑塊,在右側看到圖像。 你有transform: scale以獲得正確的大小。

.slider {
      width: 640px;
      position: relative;
      /* padding-top: 320px; Remove the padding top */
      margin: 100px auto;
      box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
    }

.slider input[name='slide_switch'] ~ img {
  opacity: 0;
  transform: scale(0.5);
  margin-left: 120px; /* Push the image to the right side.*/
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM