保持无序列表对齐

时间:2017-08-16 04:17:43

标签: javascript html css

我正在研究JavaScript的Udacity课程。主要项目是一个简历,由教师提供的基本骨架构建为GitHub回购。这是我最新版本的屏幕截图:

enter image description here

如您所见,我的技能列表在到达图片底部后向左移动。我想保持整个项目符号列表与前两个列表项对齐。我该怎么做呢?可以使用正确的<div> s,还是需要<table>

以下是相关代码:

的index.html

<html>
<head>
  <meta charset="utf-8">
  <title>Resume</title>

  <link href="css/style.css" rel="stylesheet">
  <meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
  <div id="main">
    <div id="header" class="center-content clear-fix">
      <ul id="topContacts" class="flex-box"></ul>
    </div>
    <div style="clear: both;"></div>
    <div id="workExperience" class="gray">
      <h2>Work Experience</h2>
    </div>
    <div id="projects">
      <h2>Projects</h2>
    </div>
    <div id="education" class="gray">
      <h2>Education</h2>
    </div>
    <div id="mapDiv">
      <h2>Where I've Lived and Worked</h2>
    </div>
    <div id="lets-connect" class="dark-gray">
      <h2 class="orange center-text">Let's Connect</h2>
        <ul id="footerContacts" class="flex-box">
      </ul>
    </div>
  </div>

  <script src="js/jQuery.js"></script>

  <script src="js/helper.js"></script>

  <script src="js/resumeBuilder.js"></script>

  <script>
    if(document.getElementsByClassName('flex-item').length === 0) {
      document.getElementById('topContacts').style.display = 'none';
    }
    if(document.getElementsByTagName('h1').length === 0) {
      document.getElementById('header').style.display = 'none';
    }
    if(document.getElementsByClassName('work-entry').length === 0) {
      document.getElementById('workExperience').style.display = 'none';
    }
    if(document.getElementsByClassName('project-entry').length === 0) {
      document.getElementById('projects').style.display = 'none';
    }
    if(document.getElementsByClassName('education-entry').length === 0) {
      document.getElementById('education').style.display = 'none';
    }
    if(document.getElementsByClassName('flex-item').length === 0) {
      document.getElementById('lets-connect').style.display = 'none';
    }
    if(document.getElementById('map') === null) {
      document.getElementById('mapDiv').style.display = 'none';
    }
  </script>
</body>
</html>

JS / resumeBuilder.js

var dataPlaceHolder = "%data%";
var bio = {
    "name" : "Code Apprentice",
    "role" : "Software Engineer",
    "contact" : {
        "phone" : "555-555-5555",
        "email" : "codeguru42@gmail.com",
        "twitter" : "@codeguru42",
        "github" : "codeguru42",
        "location" : "Code Heaven"
    },
    "pictureURL" : "images/minion-me.png",
    "welcomeMessage" : "Android Developer | Stack Overflow Contributor | Full Stack Web Developer",
    "skills" : ["Java", "C++", "Android Development", "HTML", "JavaScript", "CSS", "Python"]
};

var formattedName = HTMLheaderName.replace(dataPlaceHolder, bio.name);
var formattedRole = HTMLheaderRole.replace(dataPlaceHolder, bio.role);
var formattedPhone = HTMLmobile.replace(dataPlaceHolder, bio.contact.phone);
var formattedEmail = HTMLemail.replace(dataPlaceHolder, bio.contact.email);
var formattedTwitter = HTMLtwitter.replace(dataPlaceHolder, bio.contact.twitter);
var formattedGithub = HTMLgithub.replace(dataPlaceHolder, bio.contact.github);var formattedPicture = HTMLbioPic.replace(dataPlaceHolder, bio.pictureURL);
var formattedLocation = HTMLlocation.replace(dataPlaceHolder, bio.contact.location);
var formattedBioPic = HTMLbioPic.replace(dataPlaceHolder, bio.pictureURL);
var formattedWelcomeMessage = HTMLwelcomeMsg.replace(dataPlaceHolder, bio.welcomeMessage);
var formattedSkills = bio.skills.map(function (skill) { return HTMLskills.replace(dataPlaceHolder, skill); });

$("#header").prepend(formattedRole);
$("#header").prepend(formattedName);
$("#header").prepend(formattedBioPic);
$("#header").append(formattedWelcomeMessage);

$("#header").append(HTMLskillsStart);
$("#header").append(formattedSkills);

$("#topContacts").append(formattedPhone);
$("#topContacts").append(formattedEmail);
$("#topContacts").append(formattedLocation);

$("#footerContacts").append(formattedTwitter);
$("#footerContacts").append(formattedGithub);

CSS / styles.css的

body,
div,
ul,
li,
p,
h1,
h2,
h3,
h4,
h5,
h6 {
  padding: 0;
  margin: 0;
  font-family: "Roboto", sans-serif;
}

.clear-fix {
  overflow: auto;
}

.education-entry,
.work-entry,
.project-entry {
  padding: 0 5%;
}

h1 {
  font-size: 40px;
  color: #f5a623;
  line-height: 48px;
  display: inline;
}

h2 {
  font-weight: bold;
  font-size: 24px;
  color: #999;
  line-height: 29px;
  padding: 10px;
}

h3 {
  font-style: italic;
  font-size: 20px;
  color: #000;
  line-height: 22px;
}

h4 {
  font-weight: bold;
  font-size: 14px;
  color: #4a4a4a;
  line-height: 17px;
}

h2,
h3,
h4,
h5 {
  padding: 10px 5%;

}


.date-text {
  font-style: italic;
  font-size: 14px;
  color: #999;
  line-height: 16px;
  float: left;
}

.location-text {
  font-style: italic;
  font-size: 14px;
  color: #999;
  line-height: 16px;
  float: right;

}

p {
  font-size: 14px;
  color: #333;
  line-height: 21px;
}

a {
  color: #1199c3;
  text-decoration: none;
  margin-top: 10px;
  display: block;
}

.welcome-message {
  font-style: italic;
  font-size: 18px;
  color: #f3f3f3;
  line-height: 28px;
}

#skills-h3 {
  color: #f5ae23;
  display: none;
}

.orange {
  background-color: #f5ae23;
}

.orange-text {
  color: #f5ae23;
}

.white-text {
  font-weight: bold;
  color: #fff;
}

.gray {
  background-color: #f3f3f3;
  padding-bottom: 10px;
  clear: both;
}

.dark-gray {
  background-color: #4a4a4a;
}

/* TODO: Replace with image later */
#header {
  background-color: #484848;
}

.flex-box {
  display: -webkit-flex;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
  padding: 10px;
}

.flex-column {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  padding: 10px;
}

.center-content {
  padding: 2.5% 5%;
}

ul {
  list-style-type: none;
}

.biopic {
  float: left;
  padding: 10px;
  width: 200px;
  display: none;
}

img {
  padding: 10px;
}

span {
  padding: 5px;
}

#lets-connect {
  text-align: center;
}

/* Media queries to handle various device widths */

@media only screen and (max-width: 1024px) {
  #lets-connect {
    margin-top: 5%;
  }
}

@media only screen and (max-width:900px) {
  .biopic {
    width: 175px;
  }
}

@media only screen and (max-width: 750px) {
  #lets-connect {
    margin-top: 10%;
  }
  .biopic {
    width: 150px;
  }
  .welcome-message {
    display: none;
  }
}

#map {
  display: block;
  height: 100%;
  margin: 0 5%;
}

#mapDiv {
  height: 400px;
  width: 100%;
  padding-bottom: 5%;
}

@media only screen and (min-width: 750px) {
  #skills-h3,
  .biopic {
    display: block;
  }
}

JS / helper.js

var HTMLheaderName = '<h1 id="name">%data%</h1>';
var HTMLheaderRole = '<span>%data%</span><hr>';

var HTMLcontactGeneric = '<li class="flex-item"><span class="orange-text">%contact%</span><span class="white-text">%data%</span></li>';
var HTMLmobile = '<li class="flex-item"><span class="orange-text">mobile</span><span class="white-text">%data%</span></li>';
var HTMLemail = '<li class="flex-item"><span class="orange-text">email</span><span class="white-text">%data%</span></li>';
var HTMLtwitter = '<li class="flex-item"><span class="orange-text">twitter</span><span class="white-text">%data%</span></li>';
var HTMLgithub = '<li class="flex-item"><span class="orange-text">github</span><span class="white-text">%data%</span></li>';
var HTMLblog = '<li class="flex-item"><span class="orange-text">blog</span><span class="white-text">%data%</span></li>';
var HTMLlocation = '<li class="flex-item"><span class="orange-text">location</span><span class="white-text">%data%</span></li>';

var HTMLbioPic = '<img src="%data%" class="biopic">';
var HTMLwelcomeMsg = '<span class="welcome-message">%data%</span>';

var HTMLskillsStart = '<h3 id="skills-h3">Skills at a Glance:</h3><ul id="skills" class="flex-column"></ul>';
var HTMLskills = '<li class="flex-item"><span class="white-text">%data%</span></li>';

2 个答案:

答案 0 :(得分:1)

尝试将clear:both提供给图片代码,以便列表不会在图片底部移动。

答案 1 :(得分:1)

在检查生成的网页中的HTML元素后,我发现我没有正确地将每个技能的<li>标记插入到<ul>中定义的HTMLskillsStart标记中。我只需要改变

$("#header").append(formattedSkills);

$("#skills").append(formattedSkills);