我需要在h2
元素中有两个按钮元素,我希望两个按钮位于同一行,水平对齐而不是一个在另一个之上,标题和它们之间有一些空白但是我不想更改h2
父显示或样式,我还能以其他方式实现这一目标吗?可能吗?
.btn {
display: inline-block;
padding: 8x 16px;
cursor: pointer;
transition: 500ms;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
background-color: transparent;
border: 1px solid black;
color: black;
font-size: 16px;
letter-spacing: 2px;
}
.btn--small {
padding: 4px 16px;
}
<h2 id="myId">Amazing title
<div class="video" data-link="jksaj898" data-params="modestbranding=1&am;showinfo=0&vq=720&color=white&theme=light&fs=1">
<button class="play-button btn btn--small">
<use xlink:href="#video-play">
</use>WATCH IT
</button>
</div>
<button class="btn btn--small">REGISTER</button>
</h2>
.btn {
display: inline-block;
padding: 8x 16px;
cursor: pointer;
transition: 500ms;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
background-color: transparent;
border: 1px solid black;
color: black;
font-size: 16px;
letter-spacing: 2px;
margin-top: 1em;
}
.btn--small {
padding: 4px 16px;
}
.button-div {
display:inline-flex;
}
<h2 id="myId">Amazing title
<div class="button_div">
<div class="video" data-link="jksaj898" data-params="modestbranding=1p;fs=1">
<button class="play-button btn btn--small">
<use xlink:href="#video-play">
</use>WATCH IT
</button>
</div>
<button class="btn btn--small">REGISTER</button>
</div>
</h2>
答案 0 :(得分:0)
更改HTML并将两个按钮放在.video
div。
#myId {
text-align: center;
}
.btn {
display: inline-block;
padding: 8x 16px;
cursor: pointer;
transition: 500ms;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
background-color: transparent;
border: 1px solid black;
color: black;
font-size: 16px;
letter-spacing: 2px;
margin-top: 1em;
}
.btn--small {
padding: 4px 16px;
}
&#13;
<h2 id="myId">Amazing title
<div class="video" data-link="jksaj898" data-params="modestbranding=1&am;showinfo=0&vq=720&color=white&theme=light&fs=1">
<button class="play-button btn btn--small">
<use xlink:href="#video-play">
</use>WATCH IT
</button>
<button class="btn btn--small">REGISTER</button>
</div>
</h2>
&#13;
答案 1 :(得分:0)
FLoat :float属性指定元素是否应该浮动。
只需在您的css
中添加float
属性即可
.btn--small {
float:left;
padding: 4px 16px;
}
I need to have two buttons elements inside an h2 element, I want the two buttons to be in the same line, aligned horizontally and not one above another, with some blank space between the title and them but I don't want to change the h2 parent display or styles, what other way can I achieve this? Is it possible?
.btn {
display: inline-block;
padding: 8x 16px;
cursor: pointer;
transition: 500ms;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
background-color: transparent;
border: 1px solid black;
color: black;
font-size: 16px;
letter-spacing: 2px;
}
.btn--small {
padding: 4px 16px;
}
<h2 id="myId">Amazing title
<div class="video" data-link="jksaj898" data-params="modestbranding=1&am;showinfo=0&vq=720&color=white&theme=light&fs=1">
<button class="play-button btn btn--small">
<use xlink:href="#video-play">
</use>WATCH IT
</button>
</div>
<button class="btn btn--small">REGISTER</button>
</h2>
Full page
.btn {
display: inline-block;
padding: 8x 16px;
cursor: pointer;
transition: 500ms;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
background-color: transparent;
border: 1px solid black;
color: black;
font-size: 16px;
letter-spacing: 2px;
margin-top: 1em;
}
.btn--small {
float:left;
padding: 4px 16px;
}
.button-div {
display:inline-flex;
}
&#13;
<h2 id="myId">Amazing title
<div class="video" data-link="jksaj898" data-params="modestbranding=1&am;showinfo=0&vq=720&color=white&theme=light&fs=1">
<button class="play-button btn btn--small">
<use xlink:href="#video-play">
</use>WATCH IT
</button>
<button class="btn btn--small">REGISTER</button>
</div>
</h2>
&#13;
答案 2 :(得分:-1)