在我的响应式网站的同一行上创建左对齐和右对齐时遇到问题
Having trouble creating left align and right align on the same line in my responsive website
我尝试将我的社交媒体图标放在左下角,同时将版权文本放在所有屏幕尺寸(PC 和移动设备)的右下角。
我已经尝试在文本的 CSS 上使用 'float: right',但似乎无法正常工作。
我试过将父元素更改为 display:flex 或 display:flexbox,但我不确定我做错了什么。
这是我看到的,我已经标记了要放置文本的位置:
我可以使用 padding-right: 'x'em 或 px 移动文本,但我希望文本位于页面的右下角,就像我的社交媒体徽标目前的样子。
这是代码的一个简短片段:
HTML
<div class ="bottom">
<div class = "logos">
<a href="https://github.com/j-ahn94" target="_blank" class="fa fa-github"></a>
<a href="https://whosebug.com/users/14266888/jason-a" target="_blank" class="fa fa-stack-overflow"></a>
<a href="https://www.linkedin.com/in/jasonja-ahn/" target="_blank" class="fa fa-linkedin"></a>
<p> COPYRIGHT </p>
</div>
</div>
</div>
CSS
.bottom {
margin-top: auto;
}
.logos {
display: flex !important;
flex-direction: row;
background-color: black;
bottom: 0;
position: fixed;
}
.logos a {
color: white;
text-align: center;
padding: 14px;
text-decoration: none;
font-size: 17px;
}
.logos p {
float: right;
color: white;
}
整个HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="J.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>J[a]son</title>
</head>
<body>
<div class = "overall">
<nav>
<div class = "logo">
<h4><a href="home.html">J[a]son</a></h4>
</div>
<ul class = "nav-links">
<li>
<a href="home.html">HOME</a>
</li>
<li>
<a href="#">PHOTOGRAPHY</a>
<ul class="sub-menu">
<li><a href="photography_colour.html">Colour</a></li>
<li><a href="photography_black.html">Black</a></li>
</ul>
</li>
<li>
<a href="coding.html">CODING</a>
</li>
<li>
<a href="about.html">ABOUT</a>
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<div class="main_car_wrapper">
<img class="main_car" src="Photos/main_car1.jpg" alt="car" width="100%" height="100%"/>
</div>
<!--<p>June, 2020. Sunshine Coast, BC, Canada </p>-->
<div class ="bottom">
<div class = "logos">
<a href="https://github.com/j-ahn94" target="_blank" class="fa fa-github"></a>
<a href="https://whosebug.com/users/14266888/jason-a" target="_blank" class="fa fa-stack-overflow"></a>
<a href="https://www.linkedin.com/in/jasonja-ahn/" target="_blank" class="fa fa-linkedin"></a>
<p> COPYRIGHT </p>
</div>
</div>
</div>
</body>
</html>
整个CSS:
html {
min-height: 100vh;
}
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
background-color: black !important; /*rgb(241, 233, 233);*/
display: flex;
flex-direction: column;
min-height: 100vh;
}
nav {
display: flex !important;
justify-content: space-between;
padding-right: 2em;
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
background-color: black;
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.logo a {
text-decoration: none;
color: white;
}
.logo_colour {
background-color: black !important;
color: rgb(240, 235, 235) !important;
text-transform: uppercase !important;
letter-spacing: 5px !important;
}
.logo_colour a {
text-decoration: none !important;
color: white !important;
font-weight: bold !important;
font-size: 20px !important;
}
.logo_black {
background-color: black !important;
color: rgb(240, 235, 235) !important;
text-transform: uppercase !important;
letter-spacing: 5px !important;
}
.logo_black a {
text-decoration: none !important;
color: white !important;
font-weight: bold !important;
font-size: 20px !important;
}
.logo_about {
background-color: black !important;
color: rgb(240, 235, 235) !important;
text-transform: uppercase !important;
letter-spacing: 5px !important;
}
.logo_about a {
text-decoration: none !important;
color: white !important;
font-weight: bold !important;
font-size: 20px !important;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
padding: 5px 5px;
}
.nav-links a:hover {
text-decoration: none;
color: white;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
@media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
@media screen and (max-width:950px) {
* {
margin: 0;
padding: 0;
}*/
body, html {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 50vh;
top: 11vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%);
padding-right: 0em;
transition: transform 0.5s ease-in;
z-index: 99999 !important;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
.carousel-control-prev {
padding-top: 5em;
}
.carousel-control-next {
padding-top: 5em;
}
.carousel-item {
padding-top: 6em;
}
.logos {
padding-bottom: 0em;
}
}
.nav-active {
transform: translate(0%);https://ahweb.org.uk/car.png
}
.main_car_wrapper {
background-image: url(https://ahweb.org.uk/car.png);
background-repeat: no-repeat no-repeat;
background-position: center center;
background-size: contain;
max-width: 100%;
height: auto;
padding-top: 6em;
}
@keyframes navLinkFade {
from {
opacity: 0;
transform: translateX(50px);
}
to {
opacity :1;
transform: translateX(0px);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px, 6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px, -6px);
}
.sub-menu {
display: none;
}
.sub-menu li a {
/*display: block;*/
text-decoration: none;
color: white;
border-top: 1px solid white;
background: rgb(221, 215, 215);
white-space: nowrap;
top: 40px;
left: 25px;
padding: 5px;
padding-top: 1px;
}
.sub-menu li a:hover{
background: rgb(10, 10, 10);
opacity: 1;
transition: all 0.5s ease;
}
li:hover ul {
display: flex;
position: absolute;
}
li:hover li {
float: none;
font-size: 8px;
}
li:hover a {
background: rgb(5, 5, 5);
}
li:hover li a:hover {
background: rgb(19, 18, 18);
}
.bottom {
margin-top: auto;
}
.logos {
display: flex !important;
flex-direction: row;
background-color: black;
bottom: 0;
position: fixed;
}
.logos a {
color: white;
text-align: center;
padding: 14px;
text-decoration: none;
font-size: 17px;
}
.logos a:hover {
text-decoration: none;
color: white;
}
.logos p {
float: right;
color: white;
}
.carousel-inner p {
text-align: center;
color: black;
font-size: 14px;
}
.carousel-inner {
background-color: black;
}
.carousel-inner img {
display: flex;
margin: 0 auto;
width: 50vw;
max-height: auto;
align-items: center;
}
/*.carousel-item {
height: 300px
}*/
.carousel-control-prev-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23fff' viewBox='0 0 8 8'%3E%3Cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E");
}
.carousel-control-next-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23fff' viewBox='0 0 8 8'%3E%3Cpath d='M2.75 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3E%3C/svg%3E");
}
.overall {
overflow: hidden;
position: relative;
}
/* About section */
.about_title {
color: rgba(255, 255, 255, 0.671);
text-decoration: underline;
}
.about_body {
padding-left: 1.5em;
padding-right: 1.5em;
padding-top: 2em;
display: block;
}
.about_body p {
color: rgba(255, 255, 255, 0.671);
}
.about_body img {
padding: 10px;
max-height: 320px;
width: 220px;
float: right;
}
指定徽标的宽度 div
.logos {
width: 100%;
display: flex !important;
flex-direction: row;
background-color: black;
bottom: 0;
position: fixed;
}
// 并将 margin-left auto 添加到徽标 p
.logos p {
margin-left: auto;
color: white;
}
我尝试将我的社交媒体图标放在左下角,同时将版权文本放在所有屏幕尺寸(PC 和移动设备)的右下角。
我已经尝试在文本的 CSS 上使用 'float: right',但似乎无法正常工作。
我试过将父元素更改为 display:flex 或 display:flexbox,但我不确定我做错了什么。
这是我看到的,我已经标记了要放置文本的位置:
我可以使用 padding-right: 'x'em 或 px 移动文本,但我希望文本位于页面的右下角,就像我的社交媒体徽标目前的样子。
这是代码的一个简短片段:
HTML
<div class ="bottom">
<div class = "logos">
<a href="https://github.com/j-ahn94" target="_blank" class="fa fa-github"></a>
<a href="https://whosebug.com/users/14266888/jason-a" target="_blank" class="fa fa-stack-overflow"></a>
<a href="https://www.linkedin.com/in/jasonja-ahn/" target="_blank" class="fa fa-linkedin"></a>
<p> COPYRIGHT </p>
</div>
</div>
</div>
CSS
.bottom {
margin-top: auto;
}
.logos {
display: flex !important;
flex-direction: row;
background-color: black;
bottom: 0;
position: fixed;
}
.logos a {
color: white;
text-align: center;
padding: 14px;
text-decoration: none;
font-size: 17px;
}
.logos p {
float: right;
color: white;
}
整个HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="J.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>J[a]son</title>
</head>
<body>
<div class = "overall">
<nav>
<div class = "logo">
<h4><a href="home.html">J[a]son</a></h4>
</div>
<ul class = "nav-links">
<li>
<a href="home.html">HOME</a>
</li>
<li>
<a href="#">PHOTOGRAPHY</a>
<ul class="sub-menu">
<li><a href="photography_colour.html">Colour</a></li>
<li><a href="photography_black.html">Black</a></li>
</ul>
</li>
<li>
<a href="coding.html">CODING</a>
</li>
<li>
<a href="about.html">ABOUT</a>
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<div class="main_car_wrapper">
<img class="main_car" src="Photos/main_car1.jpg" alt="car" width="100%" height="100%"/>
</div>
<!--<p>June, 2020. Sunshine Coast, BC, Canada </p>-->
<div class ="bottom">
<div class = "logos">
<a href="https://github.com/j-ahn94" target="_blank" class="fa fa-github"></a>
<a href="https://whosebug.com/users/14266888/jason-a" target="_blank" class="fa fa-stack-overflow"></a>
<a href="https://www.linkedin.com/in/jasonja-ahn/" target="_blank" class="fa fa-linkedin"></a>
<p> COPYRIGHT </p>
</div>
</div>
</div>
</body>
</html>
整个CSS:
html {
min-height: 100vh;
}
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
background-color: black !important; /*rgb(241, 233, 233);*/
display: flex;
flex-direction: column;
min-height: 100vh;
}
nav {
display: flex !important;
justify-content: space-between;
padding-right: 2em;
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
background-color: black;
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.logo a {
text-decoration: none;
color: white;
}
.logo_colour {
background-color: black !important;
color: rgb(240, 235, 235) !important;
text-transform: uppercase !important;
letter-spacing: 5px !important;
}
.logo_colour a {
text-decoration: none !important;
color: white !important;
font-weight: bold !important;
font-size: 20px !important;
}
.logo_black {
background-color: black !important;
color: rgb(240, 235, 235) !important;
text-transform: uppercase !important;
letter-spacing: 5px !important;
}
.logo_black a {
text-decoration: none !important;
color: white !important;
font-weight: bold !important;
font-size: 20px !important;
}
.logo_about {
background-color: black !important;
color: rgb(240, 235, 235) !important;
text-transform: uppercase !important;
letter-spacing: 5px !important;
}
.logo_about a {
text-decoration: none !important;
color: white !important;
font-weight: bold !important;
font-size: 20px !important;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
padding: 5px 5px;
}
.nav-links a:hover {
text-decoration: none;
color: white;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
@media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
@media screen and (max-width:950px) {
* {
margin: 0;
padding: 0;
}*/
body, html {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 50vh;
top: 11vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%);
padding-right: 0em;
transition: transform 0.5s ease-in;
z-index: 99999 !important;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
.carousel-control-prev {
padding-top: 5em;
}
.carousel-control-next {
padding-top: 5em;
}
.carousel-item {
padding-top: 6em;
}
.logos {
padding-bottom: 0em;
}
}
.nav-active {
transform: translate(0%);https://ahweb.org.uk/car.png
}
.main_car_wrapper {
background-image: url(https://ahweb.org.uk/car.png);
background-repeat: no-repeat no-repeat;
background-position: center center;
background-size: contain;
max-width: 100%;
height: auto;
padding-top: 6em;
}
@keyframes navLinkFade {
from {
opacity: 0;
transform: translateX(50px);
}
to {
opacity :1;
transform: translateX(0px);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px, 6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px, -6px);
}
.sub-menu {
display: none;
}
.sub-menu li a {
/*display: block;*/
text-decoration: none;
color: white;
border-top: 1px solid white;
background: rgb(221, 215, 215);
white-space: nowrap;
top: 40px;
left: 25px;
padding: 5px;
padding-top: 1px;
}
.sub-menu li a:hover{
background: rgb(10, 10, 10);
opacity: 1;
transition: all 0.5s ease;
}
li:hover ul {
display: flex;
position: absolute;
}
li:hover li {
float: none;
font-size: 8px;
}
li:hover a {
background: rgb(5, 5, 5);
}
li:hover li a:hover {
background: rgb(19, 18, 18);
}
.bottom {
margin-top: auto;
}
.logos {
display: flex !important;
flex-direction: row;
background-color: black;
bottom: 0;
position: fixed;
}
.logos a {
color: white;
text-align: center;
padding: 14px;
text-decoration: none;
font-size: 17px;
}
.logos a:hover {
text-decoration: none;
color: white;
}
.logos p {
float: right;
color: white;
}
.carousel-inner p {
text-align: center;
color: black;
font-size: 14px;
}
.carousel-inner {
background-color: black;
}
.carousel-inner img {
display: flex;
margin: 0 auto;
width: 50vw;
max-height: auto;
align-items: center;
}
/*.carousel-item {
height: 300px
}*/
.carousel-control-prev-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23fff' viewBox='0 0 8 8'%3E%3Cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E");
}
.carousel-control-next-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23fff' viewBox='0 0 8 8'%3E%3Cpath d='M2.75 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3E%3C/svg%3E");
}
.overall {
overflow: hidden;
position: relative;
}
/* About section */
.about_title {
color: rgba(255, 255, 255, 0.671);
text-decoration: underline;
}
.about_body {
padding-left: 1.5em;
padding-right: 1.5em;
padding-top: 2em;
display: block;
}
.about_body p {
color: rgba(255, 255, 255, 0.671);
}
.about_body img {
padding: 10px;
max-height: 320px;
width: 220px;
float: right;
}
指定徽标的宽度 div
.logos {
width: 100%;
display: flex !important;
flex-direction: row;
background-color: black;
bottom: 0;
position: fixed;
}
// 并将 margin-left auto 添加到徽标 p
.logos p {
margin-left: auto;
color: white;
}