css 在标题中水平对齐多个图像,文本居中

lsmd5eda  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(123)

大家晚上好!
把我的头发扯下来,这是我想多了的...
因此,我的标题右侧需要有2个图像与文本中心下方水平运行。我似乎不能得到它正确显示,所以显然做了一个嘘嘘的地方。
正在尝试获取此信息:x1c 0d1x
超文本标记语言:

<div class="container">
    <div class="header">
            <img src="siteImages/siteLogo.png">
        <div class="header-center">
            <div class="headerLinks">
                <a class="active" href="#home">HOME</a>
                <a href="#contact">GAS &amp; CENTRAL HEATING</a>
                <a href="#about">SWIMMING POOLS</a>
                <a href="#about">AIR CONDITIONING</a>
                <a href="#about">SWIMMING POOLS</a>
            </div>
            <div class="socials">
                  <a href="https://www.facebook.com/#LINK"><img src="siteImages/faceBook.png"></a>
                  <a href="https://www.instagram.com/#LINK/"><img src="siteImages/instagram.jpg"></a>
                  <a href="https://www.tiktok.com/@#LINK"><img src="siteImages/tiktok.png"></a>
              </div>
        </div>
        <div class="header-right">
            <div class="contactIcons">
                <img src="siteImages/whatsApp.jpg">
                <span class="contactText">WhatsApp - Changed</span>
            </div>
            <div class="contactIcons">
                <img src="siteImages/telePhone.jpg">
                <span class="contactText">#TELE - Changed</span>
            </div>
        </div>
    </div>
</div>

字符串
CSS:

body{
    background: white;
    font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, "sans-serif";
    margin: 0px;
    width: 100%;
    height: 100%;
}
.container .headerMain{
    
}
.headerMain .HeaderLogo{
    
}
.headerMain .HeaderLinks{
    
}
.headerMain .HeaderContact{
    
}
/*HEADER SECTION */
.header {
    overflow: hidden;
    background-color: black;
    padding: 10px 10px;
}

/* Style the header links */
.headerLinks a {
    float: left;
    color: white;
    text-align: center;
    padding: 15px;
    text-decoration: none;
    font-size: 22px;
    line-height: 25px;
    border-radius: 4px;
    margin-top: 35px;
}

.header a.logo {
    font-size: 25px;
    font-weight: bold;
    max-width:150px;
    max-height:150px;
}
.header img{
    float: left;
    max-width:150px;
    max-height:150px;
}

.header-center {
    float: left;
    margin:0px;
    padding:0px;
}
.headerLinks{
    margin-left:20px;
    margin-bottom:0px;
    padding: 0px;
}
.headerLinks a:hover {
    background-color: #13628d;
    color: white;
}

.headerLinks a.active {
    background-color: #13628d;
    color: white;
}
.socials{
    float: right;
    margin:0px;
    padding: 0px 0px 0px 15px;
}

.socials img{
    float:right;
    max-width:40px;
    max-height:40px;
    padding: 0px 0px 0px 15px;
}
.socials a:hover{
    padding: 0px;
}

.header-right {
    float: right;
    display: flex;
    justify-content: center;
    width: 400px;
}
.contactHeader{
    font-size: 22px;
    color: #13628d;
    width: 300px;
}
.contactIcons {
    display: inline-block;
    text-align: center;
    width: 50%;
    vertical-align: top; 
}
.contactIcons img {
    max-width: 75px;
    max-height: 75px;
    margin: 0 auto;
}
.contactIcons .contactText {
   font-size: 20px;
   color: #13628d;
}


如有任何帮助,将不胜感激!

x8goxv8g

x8goxv8g1#

是的,那是一团糟。你不想要浮动,你需要flexbox es。

body {
  font-family: sans-serif;
  margin: 0;
}

header {
  overflow: hidden;
  background-color: black;
  padding: 10px;
  display: flex;
  gap: 1em;
  justify-content: space-between;
  align-items: center;
}

nav a {
  display: inline-block;
  color: white;
  text-align: center;
  text-decoration: none;
  font-size: 22px;
  border-radius: 4px;
  padding: 5px 10px;
}

nav a:hover, nav a:active {
  background-color: #13628d;
}

.socials {
  margin-top: 1em;
  text-align: center;
}

.header-right {
  display: flex;
  gap: 1em;
}

.contactIcons {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}

.contactIcons .contactText {
   font-size: 20px;
   color: #13628d;
   text-align: center;
}

个字符
运行此代码片段后,请确保使用整页链接查看完整效果。

相关问题