简体   繁体   English

具有纯CSS和HTML的自定义样式

[英]A custom style with pure CSS and HTML

I am trying to create a style using CSS and HTML. 我正在尝试使用CSS和HTML创建样式。 My desire style is something similar to this. 我的欲望风格与此类似。

在此处输入图片说明

Most of things of that style have been done with pure CSS and HTML. 这种样式的大多数事情都是使用纯CSS和HTML完成的。

This is my CSS - 这是我的CSS-

.filter-box {
    float: left;
    margin: 0 3% 0 2%;
    width :29%;

    > .main-cat {      
        background-color: #FFFFFF;
        display: block;
        margin-top: 25px;
        padding: 10px;
        position: relative;

        > h3 {
            margin: 0;
        }
    }

    > .main-cat:after {
        border-bottom: 15px solid rgba(0, 0, 0, 0);
        border-left: 15px solid #FFFFFF;
        border-top: 15px solid rgba(0, 0, 0, 0);
        content: "";
        height: 0;
        margin-top: -15px;
        position: absolute;
        right: -14px;
        top: 50%;
        width: 0;
    }

    > .main-cat:first-child {
        margin-top: 0;
    }

    > .sub-cat {
            background: #FF9000;
            margin-left: 25px;
            margin-top: 5px;
            padding: 8px 10px;
            text-align: right;

        > h4 {
            margin: 0;
        }
    }
}

My problem is when I am trying to display a let border with a bold circle bullet on the left side of the sub category DIV. 我的问题是,当我尝试在子类别DIV的左侧显示带有粗体圆形项目符号的let边框时。

Can any body tell me is this possible with pure CSS and HTML without using any image? 谁能告诉我使用纯CSS和HTML而不使用任何图像是否可以做到这一点?

This is my code so far: JS BIN 到目前为止,这是我的代码: JS BIN

Any comments would be greatly welcome. 任何意见都将受到欢迎。

Thank You. 谢谢。

Another possibilities would be to use background-image (gradients) and bullets of list-item , resized via font-size : DEMO 另一种可能是使用背景图像(渐变)和列表项的项目符号,并通过font-size调整其大小: DEMO

The CSS update could be : (see comment for explanation ) CSS更新可能是:( 请参阅注释以获取说明)

.filter-box {
    background:linear-gradient(to right,
  transparent 15px,
  white 15px,
  white 17px,
  transparent 17px); /* draws the vertical bar aside list-items */
}
  background:linear-gradient( /* draw orange background */
    to right,
 transparent 40px , 
    #FF9000 40px),
    linear-gradient(/* draw middle white bar */
      to bottom,
      transparent 49%,
      white 48%,
      white 52%,
      transparent 51%
      ) right no-repeat;
  background-size:
      auto auto/* no need to resize first gradient */, 
      95% 100% /*reduce width of second gradient */;
  display:list-item;/* lests get a round bullet if this is not a li */
  color:white; /* give color to bullet */
  font-size:2.2em;/* resize bullet */
  list-style-position:inside;/* keep bullet inside element */
}
.filter-box > .sub-cat > h4 {
  margin: 0;
  font-size:0.6em;/* resize to a normal font-size from  em value inherited */
  display:inline-block;/* stands aside bullet */
  text-align: right;/* align to right */
  width:85%;/* keep min/max-width under control*/
}

Notice: no pseudo elements involved, gradient can be image for better compatibilitie and dispatch within main container , sub container and title for the background-color to increase compatibiliti with old browser. 注意:不涉及伪元素,渐变可以是图像,以便更好地兼容并在主容器,子容器和背景颜色的标题中分配,以增加与旧浏览器的兼容性。

As mentionned earlier , this menu/list deserve to be build from an HTML list . 如前所述, 该菜单/列表应从HTML列表构建

Demo: http://jsfiddle.net/abhitalks/4LB5t/ 演示: http : //jsfiddle.net/abhitalks/4LB5t/

CSS : CSS

.sub-cat:before {
    content: ' ';
    border-left: 1px solid white; 
    display: inline-block;
    width: 16px; height: 42px;
    position: absolute;
    left: 40px; margin: 0px; margin-top: -8px;
    z-index: 10;
}
.sub-cat:after {
    content: '';
    display: inline-block;
    width: 8px; height: 8px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    left: 36px; margin-top: -8px;
}

Update : 更新

Demo 2: http://jsfiddle.net/abhitalks/4LB5t/1/ 演示2: http//jsfiddle.net/abhitalks/4LB5t/1/

Just increase the height on .sub-cat:before . 只需增加.sub-cat:before的高度。

Update 2 : 更新2

Demo 3: http://jsfiddle.net/abhitalks/4LB5t/2/ 演示3: http//jsfiddle.net/abhitalks/4LB5t/2/

Added your horizontal border as well. 也添加了水平边框。 The only changes in the css are: CSS的唯一变化是:

.sub-cat:before {
    ...
    border-bottom: 1px solid white; 
    margin-top: -26px;
    z-index: -1;
}

You have to tweak and tune the styles to achieve what you want. 您必须调整和调整样式以实现所需的功能。 Hope that helps. 希望能有所帮助。

You can use the :before and :after elements in the sub-category to design the circle and left border. 您可以使用子类别中的:before:after元素来设计圆形和左边框。

Use the :before to make the circle as @megha outlined, and position it with the vertical center of the sub-cat. 使用:before以@megha勾勒出轮廓的圆,并将其放置在子猫的垂直中心。

Put the position of the .subcat as position: relative , so that you can define the positions of the absolutely positioned :before and :after in relation to the left edge of .subcat .subcat的位置.subcatposition: relative ,以便您可以定义相对于.subcat左边缘的绝对位置:before:after.subcat

Then use the :after and style it as 然后使用:after并将其样式设置为

width: 2px; height: 100%; top: 0; left: -10px

Hope this helps 希望这可以帮助


Look at this pen. 看这支笔。 I have modified some of the styles in the answer to make it work. 我修改了答案中的某些样式以使其起作用。 (SCSS syntax) http://codepen.io/anon/pen/dJepq (SCSS语法) http://codepen.io/anon/pen/dJepq

  .sub-cat {
    background: #FF9000;
    margin-left: 25px;
    margin-top: 5px;
    padding: 8px 10px;
    text-align: right;
    position: relative;
    &:before {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background-color: #ff9000;
      content: "";
      position: absolute;
      top: 12px;
      left: -20px;
    }
    &:after {
      width: 2px;
      top: -5px;
      bottom: 0;
      left: -16px;
      content: "";
      position: absolute;
      background-color: #ff9000;
    }
  }  
}

Using :after and :before pseudo element you can achieve the result. 使用:after:before伪元素可以达到结果。

Check the DEMO . 检查演示

Here is the CSS would be required. 这是需要的CSS。

.sub-cat:before{
content: "";
position:absolute;
left:25px;
height: 10px;
width: 10px;
border-radius: 50%;
background:white;
margin-top: 5px;
}

.sub-cat:after{
content: "";
position:absolute;
top:55px;
left:29px;
height:21%;
border-right: 1px solid white;
}
.sub-cat h4:before{
content: "  ";
position:absolute;
left:32px;
width: 10px;
height: 10px;
transform:rotate(90deg);
-webkit-transform:rotate(90deg);
border-right: 1px solid white;}

.sub-cat h4:after{
content: "  ";
margin-left:10px;
margin-top:4px;
position:absolute;
border-bottom: 8px solid rgba(0, 0, 0, 0);
border-left: 8px solid #000000;
border-top: 8px solid rgba(0, 0, 0, 0);
}

A circular bullet can be created using the html : 可以使用html创建圆形项目符号:

<div id="circle"></div>

and its corresponding css 及其对应的CSS

#circle
{
width:10px;
height:10px;
border-radius:5px;
background-color:white;
}

I am unable to understand what "let border" means.Hope this helps! 我无法理解“让边界”的含义。希望这会有所帮助!

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

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