I have uploaded my code for one page. My goal is to create margins from the left and right sides. The idea is to make the content centered with margins. I have a css code but please keep in mind there is extra code that leads to other pages as well.
For an idea of what needs to be achieved, I have uploaded a link of a site mimicking my goal. https://aliabdaal.com
.navbar1 {
padding: 0;
margin: 0;
}
.nav {
text-align: center;
}
#backroundcolourthing {
background-color: rgb(247, 251, 255);
padding: 10px;
border: 0px solid green;
width: auto;
height: 550px;
}
nav {
display: flex;
/* 1 */
justify-content: space-between;
/* 2 */
padding: 1rem 2rem;
/* 3 */
background: rgb(245, 250, 255);
/* 4 */
}
.barsection {
margin: right;
}
nav ul {
display: flex;
/* 5 */
list-style: none;
/* 6 */
margin: auto;
}
nav li {
padding-left: 3rem;
/* 7! */
margin: 3%;
margin-left: 20px;
}
nav a {
text-decoration: none;
color: black;
font-size: 20px;
font-family: sans-serif light;
}
.aboutmeh2 {
font-size: 40px;
font-family: Optima;
text-align: center;
}
.shortsryh2 {
font-size: 20px;
font-family: Optima;
text-align: center;
}
.para2 {
max-width: 900px;
min-width: 100px;
max-height: 1000px;
min-height: 900px;
background-color: rgb(255, 255, 255);
}
.a {
font-size: 20px;
font-family: sans-serif light;
color: rgb(24, 24, 24);
text-align: left;
margin-top: 4rem;
}
.headingforsmth {
font-size: 25px;
text-align: center;
}
.centerimgonline {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.introname {
font-size: 40px;
font-family: Tahoma;
text-align: center;
}
.introphrase1 {
font-size: 28px;
font-family: Optima;
text-align: center;
}
.introphrase3 {
font-size: 20px;
font-family: Optima;
text-align: center;
}
.post-header {
margin: 0 -1rem;
width: calc(100% 2rem);
padding: 3rem 1rem;
background-color: rgb(255, 255, 255);
}
.home__video,
.home__intro {
margin: 0;
width: 46%;
}
.container {
max-width: 1040px;
margin-left: auto;
margin-right: auto;
}
.para1 {
max-width: 900px;
min-width: 100px;
max-height: 1000px;
min-height: 900px;
background-color: rgb(228, 228, 228);
}
.table-of-contents {
padding: 2rem;
background-color: green;
}
.post-content {
line-height: 1.7;
}
.para3 {
max-width: 900px;
min-width: 100px;
max-height: 1000px;
min-height: 900px;
background-color: rgb(118, 122, 179);
}
.myphoto {
display: flex;
flex-direction: column;
margin: -14em auto;
margin-left: 90em;
max-width: 1140px;
width: 39%;
z-index: -1;
transform: rotate(-20deg);
}
.myclass {
color: rgb(61, 88, 124);
}
<div id="backroundcolourthing">
<div >
<nav>
<div >
<div>
<h2>VovaSite</h2>
</div>
</div>
<div >
<div >
<ul >
<li>
<a href="Homepage.html">Home</a>
</li>
<li>
<a href="aboutme.html">About</a>
</li>
<li>
<a href="articles.html">articles</a>
</li>
<li>
<a href="articles.html">articles</a>
</li>
<li>
<a href="articles.html">articles</a>
</li>
<li>
<a href="articles.html">articles</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<div>
<div>
<div >
<h2 > Hi guys - </h2>
<p > I'm name. I am a soon-to-be-
<a href="http://www.google.com">Youtuber.</a>
</p>
<p >
something text boring intresting information lol
</p>
</div>
<div>
<div >
<img alt="Pacific" src="img4.jpg" style="
border-radius: 10px; transform:rotate(0deg);">
</div>
</div>
</div>
</div>
</div>
CodePudding user response:
if I can understand you, for this case. You would define a width in percentage and then add a new rule in css with a margin auto, this it will do your content be center. (I'm so sorry for my english, I'll hope that you can understand me)
Ej:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Example</title>
<style>
.main{
width: 85%;
margin: 0 auto;
}
</style>
</head>
<body>
<main >
<!--Content here-->
</main>
</body>
</html>
CodePudding user response:
In your <ul >
, you can put the css below:
ul.nav {
display:flex;
justify-content:center;
}
This is the best way in my opinion, but you can put with margin like a margin: 0 auto
.