html - 如何在居中的图像旁边放置文本?
问题描述
抱歉,我知道这是一个非常基本的问题,但我不知道如何将文本放在垂直居中的图像旁边。我已经搜索了如何做到这一点,并尝试了几种不同的方法,但我似乎无法找到一种有效的方法。我在想也许我犯了一个错误,我一直在我的代码中忽略。我很新,只是想看看我能应用我学到的东西。谢谢,这是我的代码。
html, body {
margin: 0px;
padding:0px;
width: 100%;
height: 100%;
overflow-x: hidden;
}
body {
background-image: url("https://cdn.pixabay.com/photo/2015/12/03/08/50/paper-1074131_1280.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100%;
opacity: 75%;
}
.header {
display: flex;
align-items: center;
justify-content: center;
}
.image {
flex-basis: 40%;
height: 20px;
width:35px;
vertical-align: middle;
}
.webtitle {
font-size: 30px;
padding-left: 5px;
vertical-align: middle;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<title>Home - Historically Speaking</title>
<link href="D:\Programming\HTML\First Website\syle1.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="Header">
<div class="Logo">
<img src="https://i.imgur.com/Cm5P5vP.jpeg" width="250" height="200" align="left"/>
</div>
<div class="webtitle">
<p> Historically Speaking </p>
</div>
</div>
</body>
</html>
解决方案
您根本不需要vertical-align: middle;
,容器的 flex 设置足以满足您的需求,您只需要注意类名:header
与Header
- 区分大小写...:
html,
body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow-x: hidden;
}
body {
background-image: url("https://cdn.pixabay.com/photo/2015/12/03/08/50/paper-1074131_1280.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100%;
opacity: 75%;
}
.Header {
display: flex;
align-items: center;
justify-content: center;
}
.image {
flex-basis: 40%;
height: 20px;
width: 35px;
}
.webtitle {
font-size: 30px;
padding-left: 5px;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<title>Home - Historically Speaking</title>
<link href="D:\Programming\HTML\First Website\syle1.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="Header">
<div class="Logo">
<img src="https://i.imgur.com/Cm5P5vP.jpeg" width="250" height="200" align="left" />
</div>
<div class="webtitle">
<p> Historically Speaking </p>
</div>
</div>
</body>
</html>
推荐阅读
- android - Firebase 实时查询多个键/值
- vim - Vim - 如何更改在选项卡中打开的文件的名称样式
- xamarin.forms - Prism 从 ViewModelBase 与 BindableBase 继承
- python - 为什么if语句正在执行而语句为假
- mysql - 询问!我怎样才能从每个用户的三张桌子上获得总餐费和费用!这是我的第一个问题,很抱歉给您带来不便
- html - 使标题 (h1, h2, ...) 从正文继承样式
- php - 如何阻止 laravel 用户在设备之间交换
- c# - 尝试使用 LINQ to SQL 创建节点树会产生 NotSupportedException
- c++ - 使用 __single_client_alloc 找到了一些旧代码 - 我该如何恢复它?
- c# - 如何实现具有公共属性但私有设置方法的多个接口?