简体   繁体   English

CSS圆角不起作用-为什么不起作用?

[英]CSS Rounded Corners Not Working - Why Not?

<div id="main-solutions">
   <div id="main-solutions-top-left"></div>
   <div id="main-solutions-top-right"></div>
   <div id="main-solutions-body">
       blah blah blah
   </div>
</div>

css 的CSS

#main-solutions {
}

#main-solutions-top-left {
    position: absolute;
    top: 0px;
    left: 0px;
    background: url('../images/Top-Left-Gray-Corner.gif') no-repeat top left;
    width: 434px;
    height: 15px;
}

#main-solutions-top-right {
    position: absolute;
    top: 0;
    right: 0;
    background: url('../images/Top-Right-Gray-Corner.gif') no-repeat top right;
    width: 434px;
    height: 15px;
}

#main-solutions-body {
    background: url('../images/Gray-Gradient.jpg') repeat-x;
}

I'm expecting to see that main-solutions has two absolutely positioned divs at the top left and right with my rounded corner image, and then followed by the body with the gradient, but when I use HTML element browsers, the top-left and top-right div are not appearing at all, very confused, why are those divs being disregarded? 我期望看到主解决方案的圆角图像在左上和右上有两个绝对定位的div,然后是带有渐变的主体,但是当我使用HTML元素浏览器时,左上和右上角的div根本没有出现,非常混乱,为什么这些div被忽略了?

UPDATE (for others confused by answer): 更新(对于其他答案感到困惑的人):

At the root of my issue is I didn't understand that both absolute and relative define a new coordinate system for their contents, in addition to specifying the posision of the element itself. 问题的根本原因是,我不了解绝对值和相对值都除了为其指定元素本身的位置以外,还为其内容定义了新的坐标系。 Found a good explanation here: 在这里找到了很好的解释:

http://www.w3.org/TR/WD-positioning-970131#Positioned http://www.w3.org/TR/WD-positioning-970131#Positioned

from section 2.2 从2.2节开始

Like 'absolute' positioned elements, 'relative'ly positioned define a new coordinate system for child elements, with the origin located in the position where the first child element is rendered 像“绝对”定位的元素一样,“相对”定位为子元素定义新的坐标系,其原点位于第一个子元素的渲染位置

Far as i'm seeing, the corners should be appearing at the top left and right of the page , since your container div doesn't have a CSS position property. 据我所知,角落应该出现在页面的左上和右上,因为您的容器div没有CSS position属性。 Absolute-positioned elements' positions are relative to the innermost parent that has a position other than static (the default). 绝对定位的元素位置相对于具有最里面的父position比其它static (缺省值)。

Try adding position: relative to the container div's CSS. 尝试添加position: relative对于容器div的CSS。 It works much like the default, but (1) if you want, you can shift the div's position by some amount (which isn't extremely useful here, but still), and (2) since the position's not static anymore, absolute-positioned stuff inside the div should position itself relative to the container, rather than to the body/page. 它的工作原理与默认设置非常相似,但是(1)如果需要,您可以将div的位置移动一定量(这里并不是非常有用,但仍然可以),以及(2)由于该位置不再是static ,因此绝对div内放置的内容应相对于容器而不是正文/页面相对于容器自身定位。

Also, some browsers won't even display a div that has no content -- so the background for said div might not show. 此外,某些浏览器甚至不会显示不包含任何内容的div,因此该div的背景可能不会显示。 You'll probably want to have something in the divs. 您可能需要在div中添加一些东西。 Even a single &nbsp; 甚至只有一个&nbsp; will work. 将工作。

Have you considered using CSS border-radius to achieve this rather than messing around with images? 您是否考虑过使用CSS border-radius实现此目的,而不是搞乱图像?

border-radius is supported by all browsers except IE, but even IE can be made to work with it with the use of a clever little thing called CSS3Pie . 除了IE之外,所有浏览器都支持border-radius,但是即使使用聪明的小东西CSS3Pie,也可以使IE与其一起使用。

(plus as a bonus, CSS3Pie also gives IE CSS gradient backgrounds, so you could kill two birds with one stone) (另外,CSS3Pie还提供了IE CSS渐变背景,因此您可以用一块石头杀死两只鸟)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM