.slide{
display: block;
font-size: 16px;
line-height: 20px;
padding: 7px 4px;
cursor: pointer;
height: 32px;
width: 32px;
margin: 5px auto;
background-color: #2874f0;
border-radius: 50%;
color: #fff;
text-align: center;
}<a class = "slide"><</a>
<a class = "slide">></a>Пожалуйста, помогите мне. Как мне добавить обе кнопки в один ряд с выравниванием по центру? Сейчас кнопка 1 находится сверху, а кнопка 2 - в нижнем колонтитуле. Как я могу решить эту проблему?






div.arrow {
text-align: center;
}
.slide {
display: inline-block;
font-size: 16px;
line-height: 20px;
padding: 7px 4px;
cursor: pointer;
height: 32px;
width: 32px;
margin: 5px auto;
background-color: #2874f0;
border-radius: 50%;
color: #fff;
text-align: center;
}<div class = "arrow">
<a class = "slide"><</a>
<a class = "slide">></a>
</div>Я советую вам использовать Flexbox, это очень хороший инструмент для выравнивания элементов и создания адаптивных веб-страниц. Вы можете найти руководства здесь или здесь, которые очень ясны и дадут вам передовой опыт.
.container{
display:flex;
justify-content:center;
}
.slide{
display: block;
font-size: 16px;
line-height: 20px;
padding: 7px 4px;
cursor: pointer;
height: 32px;
width: 32px;
margin-left: 5px;
margin-right: 5px;
background-color: #2874f0;
border-radius: 50%;
color: #fff;
text-align: center;
}<div class = "container">
<a class = "slide"><</a>
<a class = "slide">></a>
</div>Изменения в классе Slide:
display: inline-block;
line-height: 30px;
padding: 0px 0px;
Элементы расположены не в ряд, поскольку они блочные. По вашему требованию их нужно будет преобразовать во встроенные блочные типы.
Вам следует использовать флексбоксы:
section#slider_buttons {
display: flex;
display: -webkit-flex;
justify-content: center;
}
section.button {
display: inline-flex;
display: -webkit-inline-flex;
height: 32px;
width: 32px;
cursor: pointer;
border-radius: 50%;
background-color: #2874f0;
color: white;
}
section.button a {
display: block;
text-align: center;
margin: auto; /* Important */
}<section id = "slider_buttons">
<section class = "button">
<a><</a>
</section>
<section class = "button">
<a>></a>
</section>
<section>У вас есть два варианта.
1) Добавьте BootStrap или аналогичный фреймворк и оберните две ссылки в div с классом строки.
2) Измените настройку отображения CSS на встроенный блок
.slide{
display: inline-block;
font-size: 16px;
line-height: 20px;
padding: 7px 4px;
cursor: pointer;
height: 32px;
width: 32px;
margin: 5px auto;
background-color: #2874f0;
border-radius: 50%;
color: #fff;
text-align: center;
}
Flex - лучший инструмент для этого. Несмотря на это, есть решения с блоком дисплея. Flex просто позволяет более подробно управлять им:
.slide-buttons {
display: flex;
margin: 0;
padding: 0;
justify-content: center;
/* Clarity marker, removed when you understand the example */
background-color: rgba(0,0,0,.1);
}
.slide-buttons > a {
display: inherit;
align-items: center;
align-content: center;
justify-content: space-around;
height: 32px;
width: 32px;
margin-right: 5px;
cursor: pointer;
font-size: 16px;
line-height: 1;
background-color: #2874f0;
border-radius: 50%;
color: #fff;
}
.slide-buttons > a:last-child {
margin-right: 0;
}
#bt-slide-left:after {
content: '\276E'; /* \003C */
}
#bt-slide-right:after {
content: '\276F'; /* \003E */
}<div class = "slide-buttons">
<a id = "bt-slide-left"></a>
<a id = "bt-slide-right"></a>
</div>
<br>
<!-- or -->
<div class = "slide-buttons">
<a><</a>
<a>></a>
</div>
используйте
display:inline-blockи установитеtext-align:centerв родительском классе