css - 两种CSS样式在菜单和画廊之间发生冲突

标签 css

我在每个页面中都有一个菜单,我设计了一些风格。 现在我看到this gallery,它看起来不错,但它给我的菜单带来了一些问题, 导致这个问题的风格是这样的:

    *, *:after, *:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

我不太明白它在做什么,所以我不知道如何修复它。 不管怎样,我的代码是:

菜单:

<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<%
    request.setCharacterEncoding("windows-1255");
    response.setCharacterEncoding("windows-1255");
%>
<style>
@import url(http://fonts.googleapis.com/css?family=Montserrat:400,700);

body {
  font-family: 'Roboto', sans-serif;
  margin: 0;
  padding: 0;
}

.headline {

  text-align: center;
  position: absolute;
  margin: auto;
  height: 50%;
  width: 50%;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}

h1 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  letter-spacing: -5px;
  color: #fff;
}

.headline h1 {
  border: 3px solid #FFF;
  padding: 20px;
  font-size: 8vw;
}


#gradient {
  width: 100%;
  height: 100%;
  position: absolute;
  background: linear-gradient(270deg, #003366, #b27000, #06617d, #067370);
  background-size: 800% 800%;
  -webkit-animation: colors 30s ease infinite;
  -moz-animation: colors 30s ease infinite;
  animation: colors 30s ease infinite;
}

@-webkit-keyframes colors {
  0%{background-position:0% 50%}
  50%{background-position:100% 50%}
  100%{background-position:0% 50%}
}
@-moz-keyframes colors {
  0%{background-position:0% 50%}
  50%{background-position:100% 50%}
  100%{background-position:0% 50%}
}
@keyframes colors { 
  0%{background-position:0% 50%}
  50%{background-position:100% 50%}
  100%{background-position:0% 50%}
}


* {
    margin: 0px;
    padding: 0px;
}

.wrapper {
    margin: 70px auto;
    width: 840px;
    height: 49px;
    border-radius: 5px;
    -webkit-box-shadow: 0 0 5px #B9B9B9;
    box-shadow: 0 0 5px #B9B9B9;
}

.menu ul {
    margin: 0px;
    padding: 0px;
    list-style-type: none;
}

.menu ul>li {
    float: right;
}

.menu ul>li a {
    position: relative;
    display: inline-block;
    min-width: 100px;
    padding: 15px 20px;
    text-align: center;
    text-decoration: none;
    background-color: #fff;
    color: #6D6565;
    font-size: 16px;
    -moz-transition: background-color 0.3s, color 0.2s;
    -o-transition: background-color 0.3s, color 0.2s;
    -webkit-transition: background-color 0.3s, color 0.2s;
    transition: background-color 0.3s, color 0.2s;
}

.menu ul>li a:hover {
    background-color: #28d;
    color: #fff;
}

.menu .parent-item {
    position: relative;
}

.menu .parent-item:after {
    content: '>';
    position: absolute;
    top: 13px;
    left: -3px;
    transform: rotate(90deg) translateY(-50%);
    font-size: 19px;
    color: #D8D8D8;
}

.menu .parent-item:hover:after {
    color: #ff897c;
}

.menu .parent-item:hover .sub-menu {
    transform: scale(1, 1) translateX(-50%);
    opacity: 1;
}

.menu .parent-item .sub-menu {
    position: absolute;
    left: 50%;
    z-index: 9999;
    transform: scale(1, 0) translateX(-50%);
    transform-origin: 0 0;
    opacity: 0;
    width: 190px;
    -webkit-box-shadow: 0 0 5px #B9B9B9;
    box-shadow: 0 0 5px #B9B9B9;
    -moz-transition: all 0.3s;
    -o-transition: all 0.3s;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
}

.menu .parent-item .sub-menu a {
    display: block;
    width: 150px;
    background-color: #000;
    color: #fff;
}

.menu .parent-item .sub-menu a:hover {
    display: block;
    width: 150px;
    background-color: #F44336;
    color: #fff;
}

.menu .parent-item .sub-menu:before {
    content: "";
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #000;
    width: 0px;
    height: 0px;
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
}
</style>
<div id="gradient">
  <div class="headline">
<div class="wrapper">
    <nav class="menu">
        <ul>
            <%
                if (session.getAttribute("status") == null || session.getAttribute("status").equals("guest")) {
            %>
            <li><a href="../guest/insertUser.jsp">הרשמה לאתר </a><span></span></li>
            <li><a href="../guest/Login.jsp">התחברות</a><span></span></li>
            <%
                } else {
            %>
            <li><a href="../guest/logout.jsp">התנתקות</a><span></span></li>
            <%
                }
            %>
            <li><a href="../guest/news.jsp">חדשות</a><span></span></li>
            <li><a href="../guest/contact.jsp">צור קשר</a><span></span></li>
            <li><a href="../guest/Home.jsp">דף ראשי</a><span></span></li>
            <li><a href="../guest/odot.jsp">אודות</a><span></span></li>
            <%
                if (session.getAttribute("status") != null && session.getAttribute("status").equals("manager")) {
            %>

            <li class="parent-item"><a href="#"> <%=session.getAttribute("currentuser")%>
            </a>
                <ul class="sub-menu">
                    <li><a href="../admin/selectManyForms.jsp">רשימת לקוחות</a></li>
                    <li><a href="../admin/selectWithPictureAndLink.jsp">רשימת
                            בקשות לשמלות</a></li>
                    <li><a href="../admin/startheleteWithCheckBoxes.jsp">מחיקת
                            פעילות מבית ספר</a></li>
                    <li><a href="../admin/updateSchool.jsp">עדכונים בפעילות של
                            בית ספר </a></li>
                    <li><a href="../admin/insertInfotSchool.jsp">הוספה לטבלה
                            פעילות בית ספר </a></li>
                    <li><a href="../guest/insertUser.jsp">הוספה לקוח</a></li>
                    <li><a href="../admin/deleteWithCheckBoxes.jsp">מחיקת
                            לקוחות</a></li>
                    <li><a href="../admin/ipus2.jsp">איפוס סקר</a></li>
                    <li><a href="../admin/SekerResults.jsp">תוצאות סקר</a></li>
                </ul></li>
            <%
                }
            %>
            <%
                if (session.getAttribute("status") != null && session.getAttribute("status").equals("member")) {
            %>
            <li class="parent-item"><a href="#"> <%=session.getAttribute("currentuser")%>
            </a>
                <ul class="sub-menu">
                    <li><a href="../member/insert.jsp">בקש שמלה אישית</a></li>
                    <li><a href="../member/selectManyForms.jsp">רשימת לקוחות</a></li>
                    <li><a href="../member/UpdatePassword.jsp">שינוי סיסמה</a></li>
                    <li><a href="../member/UpdateMembersMail.jsp">שינוי EMAIL</a></li>
                    <li><a href="../member/deleteMember.jsp">מחיקת משתמש</a></li>
                    <li><a href="../member/seker2WithSessions.jsp">סקר</a></li>
                </ul></li>

            <%
                }
            %>
        </ul>
    </nav>
</div>
</div>
</div>

画廊:

   <%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>שמרו על הכנרת!</title>
<style>
@import
    url(http://fonts.googleapis.com/css?family=Titillium+Web:400,600,700,300,200)
    ;

@import url(http://fonts.googleapis.com/css?family=Croissant+One);

@import url(http://fonts.googleapis.com/css?family=Poiret+One);

*, *:after, *:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

html {
    background: #E4E4E4;
}

body {
    padding: 1px;
    font-family: 'Titillium Web', sans-serif;
    font-size: 16px;
    font-weight: 300;
    line-height: 22px;
    color: #666;
}

h1, h2, h3 {
    font-weight: 600;
}

a {
    text-decoration: none;
}

/* TITLES
===================================================== */
.pageTitle {
    display: block;
    margin: 0 0 0.2em 0;
    font-size: 2.2em;
    line-height: 1em;
    color: #3CA0D0;
}

.pageSubtitle {
    display: block;
    margin: 0 0 0.4em 0;
    font-size: 1.4em;
    line-height: 1em;
    color: #333;
}

/* EFFECTS
===================================================== */
.roundedCorners {
    -webkit-border-radius: 5px;
    border-radius: 5px;
}

.roundedCornersTop {
    -webkit-border-radius: 5px 5px 0 0;
    border-radius: 5px 5px 0 0;
}

.roundedCornersBottom {
    -webkit-border-radius: 0 0 5px 5px;
    border-radius: 0 0 5px 5px;
}

.boxShadow {
    -webkit-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.25);
    box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.25);
}

/* LAYOUT
===================================================== */
.wrapperr {
    width: 600px;
    margin: 20px 0;
}

.top {
    width: 100%;
    min-height: 300px;
    padding: 20px 0;
    text-align: center;
}

.main {
    width: 96%;
    padding: 2% 2% 5% 2%;
    margin: 5% 0;
    background: none;
    border-bottom: solid 1px #ccc;
}

.footer {
    width: 96%;
    padding: 2%;
    background: #222;
    border-top: solid 3px #086FA1;
}

/* GALLERY
===================================================== */
.galleryItem {
    display: inline-block;;
    position: relative;
    width: 250px;
    height: 250px;
    padding: 0;
    margin: 0 20px;
}

.galleryItem img {
    width: 100%;
    height: 100%;
    border: solid 10px #fff;
}

.caption {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 250px;
    height: 250px;
    z-index: 10;
}

.caption::before {
    content: attr(data-title);
    position: absolute;
    top: -50%;
    left: 0;
    width: 100%;
    height: 50%;
    padding: 10px;
    font-family: 'Croissant One', cursive;
    font-size: 1.8em;
    font-weight: 600;
    line-height: 1.4em;
    color: #086FA1;
    background: #fff;
    overflow: hidden;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -ms-transition: all 0.3s ease;
    -o-transition: all 0.3s ease;
    transition: all 0.3s ease;
}

.caption::after {
    content: attr(data-description);
    position: absolute;
    bottom: -50%;
    left: 0;
    width: 100%;
    height: 50%;
    padding: 10px;
    font-family: 'Poiret One', cursive;
    font-size: .9em;
    font-weight: 400;
    line-height: 1.4em;
    color: #fff;
    background: #222;
    overflow: hidden;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -ms-transition: all 0.3s ease;
    -o-transition: all 0.3s ease;
    transition: all 0.3s ease;
}

.caption:hover::before {
    top: 0;
}

.caption:hover::after {
    bottom: 0;
}
</style>
</head>
<body>
    <%
        if (application.getAttribute("mone") == null)
            application.setAttribute("mone", 0);
        if (session.isNew()) {
            int m = (Integer) application.getAttribute("mone");
            m++;
            application.setAttribute("mone", m);
        }
    %>

    <%
        request.setCharacterEncoding("windows-1255");
        response.setCharacterEncoding("windows-1255");
    %>
    <jsp:include page="../menu.jsp"></jsp:include>

    <div class="wrapperr roundedCorners" align="center">

        <div class="main">
            <h1 class="pageTitle">Image gallery</h1>
            <h2 class="pageSubtitle">With caption fom data tags</h2>
            <p>A nice image gallery with animated caption drawn from the
                image data tags. Made with CSS3 for modern browsers. Less modern
                browsers or non-browser (like Internet Explorer) may encounter
                problems with showing the layout correctly.</p>
        </div>

    </div>
    <ul class="top">
        <li class="galleryItem"><a class="caption" href="#"
            data-title="Colored landscape"
            data-description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce id sapien condimentum, sagittis erat rhoncus, bibendum nisi.">

                <img
                src="http://media.digitalcameraworld.com/files/2012/10/Vertorama_landscape_photography_tips_PHO17.insight02and03.vertorama.jpg"
                alt="Landscape image">

        </a></li>

        <li class="galleryItem"><a class="caption" href="#"
            data-title="Black &amp; white photo"
            data-description="Vivamus ut sem id magna consequat porta vitae ut sem. Proin eget commodo risus, vitae blandit velit. ">

                <img
                src="http://media.digitalcameraworld.com/files/2012/11/Black_and_white_landscape_photography_DCM131.shoot_creative.main_image_RGB.jpg"
                alt="Landscape image">

        </a></li>

    </ul>
    <div align="center">
        מונה כניסות:
        <%=application.getAttribute("mone")%>
    </div>
</body>
</html>

如何修复碰撞?它会导致我的菜单变小, wrapper 变大。

最佳答案

box-sizing: border-box; 将使宽度为 content_width + padding

您所要做的就是固定宽度以在宽度中包含填充:

div {
  background: url("http://www.justinas.tk/resource/ruler") no-repeat left center;
  height: 90px;
}
.a {
  width: 200px;
  padding: 0 20px;
}
.b {
  width: 200px;
  padding: 0 20px;
  box-sizing: border-box;
}
<div class="a"></div>

<div class="b"></div>

关于css - 两种CSS样式在菜单和画廊之间发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37433773/

相关文章:

单击时的 Javascript 未显示应有的元素

javascript - HTML:Base64 图像显示/复制高度错误

html - 滚动时的静态标题

javascript - 如何从 ul li 获取单独的值

CSS - 填充可用的剩余空间

html - margin 0 auto 到 div 内的跨度不起作用

javascript - 在 rails 上初始化应用程序 css 和 javascript 标签时,不显示完整日历标题工具栏按钮

c# - 表内表的CSS

html - 对齐盒子和调整 child 的大小

html - 居中居中文本的增长效果