Как связать все дочерние окна с родительским полем в CSS? [Дубликат]

Возможно, это проблема с вашим типом возвращаемого значения *[]Person, где на самом деле должно быть []*Person, чтобы ссылаться на то, что каждый индекс среза является ссылкой на Person, и где срез [] равен сама по себе ссылка на массив.

Обратите внимание на следующий пример:

package main

import (
    "fmt"
)

type Model interface {
    Name() string
}

type Person struct {}

func (p *Person) Name() string {
    return "Me"
}

func NewPersons() (models []*Person) {
    return models
}

func main() {
    var p Model
    p = new(Person)
    fmt.Println(p.Name())

    arr := NewPersons()
    arr = append(arr, new(Person))
    fmt.Println(arr[0].Name())
}
15
задан Gurjeet Singh 17 February 2013 в 16:43
поделиться

4 ответа

Я считаю, что исправил его: https://github.com/gurjeet/CSSTree/pull/1

Я изменил CSS, чтобы удалить фон и изменить margin to padding.

ul.tree, ul.tree ul {
    list-style-type: none;
    margin:0;
    padding:0;
}

ul.tree ul {
    padding-left: 1em;
    background:  url(vline.png) repeat-y;
}

ul.tree li {
    margin:0;
    padding: 0 1.2em;
    line-height: 20px;
    background: url(node.png) no-repeat;
    color: #369;
    font-weight: bold;
}

/* The #fff color background is to hide the previous background image*/
ul.tree li.last {
    background: #fff url(lastnode.png) no-repeat;
}

ul.tree ul:last-child {
    background: none;
}
3
ответ дан Aram Kocharyan 22 August 2018 в 15:42
поделиться

Спасибо, ребята, полезные ответы, которые заставили меня прочитать еще кое-что, и, наконец, я прочитал эту статью и удалил всю зависимость от JavaScript и использовал псевдоселектор nth-last-of-type для применения специального фона к последним элементам li в списке (игнорируя ul, который приходит после последнего li).

Конечный код здесь здесь . Я собираюсь принять свой собственный ответ, если кто-то не указывает на некоторые проблемы с ним. (Я не думаю, что совместимость со старыми браузерами важна для меня на этом этапе.)

Спасибо @Aram за ответ. @OneTrickPony, ваш ответ прошел по голове этого noob :) Я уверен, что все в порядке, но для меня это слишком сложно.

<style type="text/css">
/* ul[class=tree] and every ul under it loses all alignment, and bullet
 * style.
 */
ul.tree, ul.tree ul {
    list-style-type: none;
    margin:0;
    padding:0;
}

/* Every ul under ul[class=tree] gets an indent of 1em, and a background
 * image (vertical line) applied to all nodes under it (repeat-y)
 */
ul.tree ul {
    padding-left: 1em;
    background:  url(vline.png) repeat-y;
}

/* ... except the last ul child in every ul; so no vertical lines for
 * the children of the last ul
  */
ul.tree ul:last-child {
    background: none;
}

/* Every li under ul[class=tree]
 *  - gets styling to make it bold and blue, and indented.
 *  - gets a background image (tilted T), to denote that its a node
 *  - sets height to match the height of background image
 */
ul.tree li {
    margin:0;
    padding: 0 1.2em;
    background: url(node.png) no-repeat;
    line-height: 20px;
    color: #369;
    font-weight: bold;
}

/*  The last li gets a different background image to denote it as the
 *  end of branch
 */
ul.tree li:nth-last-of-type(1) {
    background: url(lastnode.png) no-repeat;
}

2
ответ дан luchaninov 22 August 2018 в 15:42
поделиться

Попробуйте использовать только псевдоэлементы и границы:

ul, li{     
    position: relative;    
}

/* chop off overflowing lines */
ul{
    overflow: hidden;
}

li::before, li::after{
    content: '';
    position: absolute;
    left: 0;
}

/* horizontal line on inner list items */
li::before{
    border-top: 1px solid #333;
    top: 10px;
    width: 10px;
    height: 0;
}

/* vertical line on list items */    
li::after{
    border-left: 1px solid #333;
    height: 100%;
    width: 0px;
    top: -10px;
}

/* lower line on list items from the first level 
   because they don't have parents */
.tree > li::after{
    top: 10px;
}

/* hide line from the last of the first level list items */
.tree > li:last-child::after{
    display:none;
}

demo (отредактировано)

19
ответ дан nice ass 22 August 2018 в 15:42
поделиться
  • 1
    Это действительно хорошая работа! +1 =) – David Thomas 17 February 2013 в 17:38
  • 2
    Сделал небольшое изменение для вашей демонстрации. Если вы заметили, что когда последний элемент не находится на первом или втором уровне отступа, как показано в настоящее время, есть посторонняя строка , см. Здесь . Если вы посмотрите здесь новый CSS внизу, вы можете увидеть, как он отражается в результате без этой дополнительной строки: dabblet.com/gist/6878696 – Joseph 8 October 2013 в 03:54
  • 3
    @Joseph margin-left: 0 0 0 10px = & gt; margin: 0 0 0 10px? – yckart 27 December 2016 в 04:00

К сожалению, псевдокласс определен в предстоящей спецификации CSS3, и на данный момент несколько веб-браузеров поддерживают его.

Это написано в конце учебника. Возможно, именно по этой причине он не работает.

3
ответ дан Siddharth Gupta 22 August 2018 в 15:42
поделиться
Другие вопросы по тегам:

Похожие вопросы: